Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark tests as requiring Internet #120

Merged
merged 3 commits into from
Oct 18, 2023
Merged
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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ filterwarnings = [
# See: aio-libs/aiohttp#7545
"ignore:.*datetime.utcfromtimestamp().*:DeprecationWarning",
]
markers = [
"internet: test requires Internet access"
]

[tool.flit.sdist]
include = ["docs", "tests"]
2 changes: 1 addition & 1 deletion src/truststore/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ssl
import typing

import _ssl # type: ignore[import]
import _ssl # type: ignore[import-not-found]

from ._ssl_constants import (
_original_SSLContext,
Expand Down
13 changes: 12 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
original_SSLContext = ssl.SSLContext


successful_hosts = pytest.mark.parametrize("host", ["example.com", "1.1.1.1"])
def decorator_requires_internet(decorator):
"""Mark a decorator with the "internet" mark"""

def wrapper(f):
return pytest.mark.internet(decorator(f))

return wrapper


successful_hosts = decorator_requires_internet(
pytest.mark.parametrize("host", ["example.com", "1.1.1.1"])
)

logger = logging.getLogger("aiohttp.web")

Expand Down
17 changes: 12 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@

import truststore
from tests import SSLContextAdapter
from tests.conftest import decorator_requires_internet

pytestmark = pytest.mark.flaky

# Make sure the httpserver doesn't hang
# if the client drops the connection due to a cert verification error
socket.setdefaulttimeout(10)

successful_hosts = pytest.mark.parametrize("host", ["example.com", "1.1.1.1"])

successful_hosts = decorator_requires_internet(
pytest.mark.parametrize("host", ["example.com", "1.1.1.1"])
)


@dataclass
Expand Down Expand Up @@ -118,8 +122,10 @@ class FailureHost:
),
]

failure_hosts_no_revocation = pytest.mark.parametrize(
"failure", failure_hosts_list.copy(), ids=attrgetter("host")
failure_hosts_no_revocation = decorator_requires_internet(
pytest.mark.parametrize(
"failure", failure_hosts_list.copy(), ids=attrgetter("host")
)
)

if platform.system() != "Linux":
Expand All @@ -139,8 +145,8 @@ class FailureHost:
)
)

failure_hosts = pytest.mark.parametrize(
"failure", failure_hosts_list, ids=attrgetter("host")
failure_hosts = decorator_requires_internet(
pytest.mark.parametrize("failure", failure_hosts_list, ids=attrgetter("host"))
)


Expand Down Expand Up @@ -318,6 +324,7 @@ def test_trustme_cert_loaded_via_capath(trustme_ca, httpserver):
assert len(resp.data) > 0


@pytest.mark.internet
def test_trustme_cert_still_uses_system_certs(trustme_ca):
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
trustme_ca.configure_trust(ctx)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_sslcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import truststore


@pytest.mark.internet
def test_minimum_maximum_version():
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ctx.maximum_version = ssl.TLSVersion.TLSv1_2
Expand All @@ -24,6 +25,7 @@ def test_minimum_maximum_version():
assert ctx.maximum_version == ssl.TLSVersion.TLSv1_2


@pytest.mark.internet
def test_check_hostname_false():
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
assert ctx.check_hostname is True
Expand All @@ -35,6 +37,7 @@ def test_check_hostname_false():
assert "match" in str(e.value)


@pytest.mark.internet
def test_verify_mode_cert_none():
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
assert ctx.check_hostname is True
Expand Down
Loading