Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tests.fixtures import (elasticapm_client, instrument, not_so_random,
sending_elasticapm_client, validating_httpserver,
waiting_httpserver)
waiting_httpserver, waiting_httpsserver)
from tests.utils.compat import middleware_setting

try:
Expand Down
12 changes: 6 additions & 6 deletions tests/asyncio/test_asyncio_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ async def test_send_timeout(mock_client):


@pytest.mark.asyncio
async def test_ssl_verify_fails(httpsserver):
async def test_ssl_verify_fails(waiting_httpsserver):
from elasticapm.transport.asyncio import AsyncioHTTPTransport
from elasticapm.transport.base import TransportException

httpsserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = AsyncioHTTPTransport(urlparse(httpsserver.url))
waiting_httpsserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = AsyncioHTTPTransport(urlparse(waiting_httpsserver.url))
with pytest.raises(TransportException) as exc_info:
await transport.send(b'x', {})
assert 'CERTIFICATE_VERIFY_FAILED' in str(exc_info)


@pytest.mark.asyncio
async def test_ssl_verify_disable(httpsserver):
async def test_ssl_verify_disable(waiting_httpsserver):
from elasticapm.transport.asyncio import AsyncioHTTPTransport

httpsserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = AsyncioHTTPTransport(urlparse(httpsserver.url), verify_server_cert=False)
waiting_httpsserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = AsyncioHTTPTransport(urlparse(waiting_httpsserver.url), verify_server_cert=False)
url = await transport.send(b'x', {})
assert url == 'http://example.com/foo'
6 changes: 6 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def waiting_httpserver(httpserver):
return httpserver


@pytest.fixture()
def waiting_httpsserver(httpsserver):
wait_for_http_server(httpsserver)
return httpsserver


@pytest.fixture()
def validating_httpserver(request):
server = ValidatingWSGIApp()
Expand Down
24 changes: 12 additions & 12 deletions tests/transports/test_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
responses = Responses('urllib3')


def test_send(httpserver):
httpserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = Transport(urlparse.urlparse(httpserver.url))
def test_send(waiting_httpserver):
waiting_httpserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = Transport(urlparse.urlparse(waiting_httpserver.url))
url = transport.send(compat.b('x'), {})
assert url == 'http://example.com/foo'

Expand All @@ -34,9 +34,9 @@ def test_timeout():
assert 'timeout' in str(exc_info.value)


def test_http_error(httpserver):
httpserver.serve_content(code=418, content="I'm a teapot")
transport = Transport(urlparse.urlparse(httpserver.url))
def test_http_error(waiting_httpserver):
waiting_httpserver.serve_content(code=418, content="I'm a teapot")
transport = Transport(urlparse.urlparse(waiting_httpserver.url))

with pytest.raises(TransportException) as exc_info:
transport.send('x', {})
Expand Down Expand Up @@ -98,17 +98,17 @@ def test_header_encodings():
assert isinstance(v, compat.binary_type)


def test_ssl_verify_fails(httpsserver):
httpsserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = Transport(compat.urlparse.urlparse(httpsserver.url))
def test_ssl_verify_fails(waiting_httpsserver):
waiting_httpsserver.serve_content(code=202, content='', headers={'Location': 'http://example.com/foo'})
transport = Transport(compat.urlparse.urlparse(waiting_httpsserver.url))
with pytest.raises(TransportException) as exc_info:
url = transport.send(compat.b('x'), {})
assert 'CERTIFICATE_VERIFY_FAILED' in str(exc_info)


@pytest.mark.filterwarnings('ignore:Unverified HTTPS')
def test_ssl_verify_disable(httpsserver):
httpsserver.serve_content(code=202, content='', headers={'Location': 'https://example.com/foo'})
transport = Transport(compat.urlparse.urlparse(httpsserver.url), verify_server_cert=False)
def test_ssl_verify_disable(waiting_httpsserver):
waiting_httpsserver.serve_content(code=202, content='', headers={'Location': 'https://example.com/foo'})
transport = Transport(compat.urlparse.urlparse(waiting_httpsserver.url), verify_server_cert=False)
url = transport.send(compat.b('x'), {})
assert url == 'https://example.com/foo'