Skip to content

Commit

Permalink
🔧 disable doq:// tests if qh3 is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
Ousret committed Nov 7, 2024
1 parent adb9dd2 commit 7a74b9e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 14 deletions.
48 changes: 41 additions & 7 deletions test/contrib/asynchronous/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@
AsyncResolverDescription,
)
from urllib3.contrib.resolver._async.doh import HTTPSResolver
from urllib3.contrib.resolver._async.doq import QUICResolver
from urllib3.contrib.resolver._async.dot import TLSResolver
from urllib3.contrib.resolver._async.dou import PlainResolver
from urllib3.contrib.resolver._async.in_memory import InMemoryResolver
from urllib3.contrib.resolver._async.null import NullResolver
from urllib3.contrib.resolver._async.system import SystemResolver
from urllib3.exceptions import InsecureRequestWarning

_MISSING_QUIC_SENTINEL = object()

try:
from urllib3.contrib.resolver._async.doq import QUICResolver
except ImportError:
QUICResolver = _MISSING_QUIC_SENTINEL # type: ignore

from urllib3.contrib.resolver._async.dot import TLSResolver # noqa: E402
from urllib3.contrib.resolver._async.dou import PlainResolver # noqa: E402
from urllib3.contrib.resolver._async.in_memory import InMemoryResolver # noqa: E402
from urllib3.contrib.resolver._async.null import NullResolver # noqa: E402
from urllib3.contrib.resolver._async.system import SystemResolver # noqa: E402
from urllib3.exceptions import InsecureRequestWarning # noqa: E402


@pytest.mark.parametrize(
Expand Down Expand Up @@ -82,6 +89,9 @@ async def test_null_resolver(hostname: str, expect_error: bool) -> None:
async def test_url_resolver(
url: str, expected_resolver_class: type[AsyncBaseResolver] | None
) -> None:
if expected_resolver_class is _MISSING_QUIC_SENTINEL:
pytest.skip("Test requires qh3 installed")

if expected_resolver_class is None:
with pytest.raises(
(
Expand Down Expand Up @@ -118,6 +128,9 @@ async def test_url_resolver(
)
@pytest.mark.asyncio
async def test_1_1_1_1_ipv4_resolution_across_protocols(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

res = await resolver.getaddrinfo(
Expand Down Expand Up @@ -158,6 +171,9 @@ async def test_1_1_1_1_ipv4_resolution_across_protocols(dns_url: str) -> None:
async def test_dnssec_exception(
dns_url: str, hostname: str, expected_failure: bool
) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

if expected_failure:
Expand Down Expand Up @@ -282,6 +298,9 @@ async def test_many_resolver_host_constraint_distribution() -> None:
)
@pytest.mark.asyncio
async def test_short_endurance_sprint(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

for host in [
Expand Down Expand Up @@ -365,6 +384,9 @@ async def test_doh_rfc8484(dns_url: str) -> None:
)
@pytest.mark.asyncio
async def test_task_safe_resolver(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

tasks = []
Expand Down Expand Up @@ -446,6 +468,9 @@ async def test_many_resolver_task_safe() -> None:
)
@pytest.mark.asyncio
async def test_resolver_recycle(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

await resolver.close()
Expand Down Expand Up @@ -479,6 +504,9 @@ async def test_resolver_recycle(dns_url: str) -> None:
)
@pytest.mark.asyncio
async def test_resolve_cannot_recycle_when_available(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

with pytest.raises(RuntimeError):
Expand All @@ -501,6 +529,9 @@ async def test_resolve_cannot_recycle_when_available(dns_url: str) -> None:
@pytest.mark.asyncio
async def test_ipv6_always_preferred(dns_url: str) -> None:
"""Our resolvers must place IPV6 address in the beginning of returned list."""
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

inet_classes = []
Expand Down Expand Up @@ -536,6 +567,9 @@ async def test_ipv6_always_preferred(dns_url: str) -> None:
@pytest.mark.asyncio
async def test_dgram_upgrade(dns_url: str) -> None:
"""www.cloudflare.com records HTTPS exist, we know it. This verify that we are able to propose a DGRAM upgrade."""
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = AsyncResolverDescription.from_url(dns_url).new()

sock_types = []
Expand Down
48 changes: 41 additions & 7 deletions test/contrib/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
ResolverDescription,
)
from urllib3.contrib.resolver.doh import HTTPSResolver
from urllib3.contrib.resolver.doq import QUICResolver
from urllib3.contrib.resolver.dot import TLSResolver
from urllib3.contrib.resolver.dou import PlainResolver
from urllib3.contrib.resolver.in_memory import InMemoryResolver
from urllib3.contrib.resolver.null import NullResolver
from urllib3.contrib.resolver.system import SystemResolver
from urllib3.exceptions import InsecureRequestWarning

_MISSING_QUIC_SENTINEL = object()

try:
from urllib3.contrib.resolver.doq import QUICResolver
except ImportError:
QUICResolver = _MISSING_QUIC_SENTINEL # type: ignore

from urllib3.contrib.resolver.dot import TLSResolver # noqa: E402
from urllib3.contrib.resolver.dou import PlainResolver # noqa: E402
from urllib3.contrib.resolver.in_memory import InMemoryResolver # noqa: E402
from urllib3.contrib.resolver.null import NullResolver # noqa: E402
from urllib3.contrib.resolver.system import SystemResolver # noqa: E402
from urllib3.exceptions import InsecureRequestWarning # noqa: E402


@pytest.mark.parametrize(
Expand Down Expand Up @@ -81,6 +88,9 @@ def test_null_resolver(hostname: str, expect_error: bool) -> None:
def test_url_resolver(
url: str, expected_resolver_class: type[BaseResolver] | None
) -> None:
if expected_resolver_class is _MISSING_QUIC_SENTINEL:
pytest.skip("Test requires qh3 installed")

if expected_resolver_class is None:
with pytest.raises(
(
Expand Down Expand Up @@ -116,6 +126,9 @@ def test_url_resolver(
],
)
def test_1_1_1_1_ipv4_resolution_across_protocols(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

res = resolver.getaddrinfo(
Expand Down Expand Up @@ -152,6 +165,9 @@ def test_1_1_1_1_ipv4_resolution_across_protocols(dns_url: str) -> None:
],
)
def test_dnssec_exception(dns_url: str, hostname: str, expected_failure: bool) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

if expected_failure:
Expand Down Expand Up @@ -273,6 +289,9 @@ def test_many_resolver_host_constraint_distribution() -> None:
],
)
def test_short_endurance_sprint(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

for host in [
Expand Down Expand Up @@ -354,6 +373,9 @@ def test_doh_rfc8484(dns_url: str) -> None:
],
)
def test_thread_safe_resolver(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

def _run(
Expand Down Expand Up @@ -453,6 +475,9 @@ def _run(
],
)
def test_resolver_recycle(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

resolver.close()
Expand Down Expand Up @@ -485,6 +510,9 @@ def test_resolver_recycle(dns_url: str) -> None:
],
)
def test_resolve_cannot_recycle_when_available(dns_url: str) -> None:
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

with pytest.raises(RuntimeError):
Expand All @@ -506,6 +534,9 @@ def test_resolve_cannot_recycle_when_available(dns_url: str) -> None:
)
def test_ipv6_always_preferred(dns_url: str) -> None:
"""Our resolvers must place IPV6 address in the beginning of returned list."""
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

inet_classes = []
Expand Down Expand Up @@ -540,6 +571,9 @@ def test_ipv6_always_preferred(dns_url: str) -> None:
)
def test_dgram_upgrade(dns_url: str) -> None:
"""www.cloudflare.com records HTTPS exist, we know it. This verify that we are able to propose a DGRAM upgrade."""
if QUICResolver is _MISSING_QUIC_SENTINEL and dns_url.startswith("doq"):
pytest.skip("Test requires qh3 installed")

resolver = ResolverDescription.from_url(dns_url).new()

sock_types = []
Expand Down

0 comments on commit 7a74b9e

Please sign in to comment.