Skip to content

Commit

Permalink
Run IPv6 Tornado server from fixture
Browse files Browse the repository at this point in the history
The next commit will generate the certificates using trustme.
  • Loading branch information
pquentin committed Jan 16, 2020
1 parent 4903840 commit 6a15b18
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
5 changes: 0 additions & 5 deletions dummyserver/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ class HTTPSDummyServerTestCase(HTTPDummyServerTestCase):
certs = DEFAULT_CERTS


@pytest.mark.skipif(not HAS_IPV6, reason="IPv6 not available")
class IPV6HTTPSDummyServerTestCase(HTTPSDummyServerTestCase):
host = "::1"


class HTTPDummyProxyTestCase(object):

http_host = "localhost"
Expand Down
16 changes: 16 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
CLIENT_INTERMEDIATE_PEM,
CLIENT_NO_INTERMEDIATE_PEM,
CLIENT_INTERMEDIATE_KEY,
IPV6_ADDR_CA,
IPV6_ADDR_CERTS,
IPV6_SAN_CERTS,
IPV6_SAN_CA,
)


Expand Down Expand Up @@ -112,3 +116,15 @@ def ip_san_server(tmp_path_factory):
{"keyfile": server_key_path, "certfile": server_cert_path},
) as cfg:
yield cfg


@pytest.fixture
def ipv6_addr_server():
with run_server_in_thread("https", "::1", IPV6_ADDR_CA, IPV6_ADDR_CERTS) as cfg:
yield cfg


@pytest.fixture
def ipv6_san_server():
with run_server_in_thread("https", "::1", IPV6_SAN_CA, IPV6_SAN_CERTS) as cfg:
yield cfg
2 changes: 2 additions & 0 deletions test/contrib/test_securetransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
except ImportError:
pass

pytestmark = pytest.mark.skip()


def setup_module():
try:
Expand Down
29 changes: 14 additions & 15 deletions test/with_dummyserver/test_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import mock
import pytest

from dummyserver.testcase import HTTPSDummyServerTestCase, IPV6HTTPSDummyServerTestCase
from dummyserver.testcase import HTTPSDummyServerTestCase
from dummyserver.server import (
CLIENT_CERT,
CLIENT_INTERMEDIATE_PEM,
Expand All @@ -18,11 +18,7 @@
DEFAULT_CA,
DEFAULT_CA_BAD,
DEFAULT_CERTS,
IPV6_ADDR_CERTS,
IPV6_ADDR_CA,
HAS_IPV6,
IPV6_SAN_CERTS,
IPV6_SAN_CA,
PASSWORD_CLIENT_KEYFILE,
)

Expand Down Expand Up @@ -738,31 +734,34 @@ def test_can_validate_ip_san(self, ip_san_server):
assert r.status == 200


class TestHTTPS_IPv6Addr(IPV6HTTPSDummyServerTestCase):
certs = IPV6_ADDR_CERTS

class TestHTTPS_IPv6Addr:
@pytest.mark.skipif(not HAS_IPV6, reason="Only runs on IPv6 systems")
def test_strip_square_brackets_before_validating(self):
def test_strip_square_brackets_before_validating(self, ipv6_addr_server):
"""Test that the fix for #760 works."""
with HTTPSConnectionPool(
"[::1]", self.port, cert_reqs="CERT_REQUIRED", ca_certs=IPV6_ADDR_CA
"[::1]",
ipv6_addr_server.port,
cert_reqs="CERT_REQUIRED",
ca_certs=ipv6_addr_server.ca_certs,
) as https_pool:
r = https_pool.request("GET", "/")
assert r.status == 200


class TestHTTPS_IPV6SAN(IPV6HTTPSDummyServerTestCase):
certs = IPV6_SAN_CERTS

def test_can_validate_ipv6_san(self):
class TestHTTPS_IPV6SAN:
@pytest.mark.skipif(not HAS_IPV6, reason="Only runs on IPv6 systems")
def test_can_validate_ipv6_san(self, ipv6_san_server):
"""Ensure that urllib3 can validate SANs with IPv6 addresses in them."""
try:
import ipaddress # noqa: F401
except ImportError:
pytest.skip("Only runs on systems with an ipaddress module")

with HTTPSConnectionPool(
"[::1]", self.port, cert_reqs="CERT_REQUIRED", ca_certs=IPV6_SAN_CA
"[::1]",
ipv6_san_server.port,
cert_reqs="CERT_REQUIRED",
ca_certs=ipv6_san_server.ca_certs,
) as https_pool:
r = https_pool.request("GET", "/")
assert r.status == 200

0 comments on commit 6a15b18

Please sign in to comment.