From 832d278d572f90e0e3752bb46619d2d54bb29818 Mon Sep 17 00:00:00 2001 From: chelsealong Date: Sat, 21 Nov 2026 08:10:13 +0000 Subject: [PATCH 1/2] fix: allow more time for loopback TLS in integration tests --- .../integrations/test_installed_adapters.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/specify_cli/integrations/test_installed_adapters.py b/tests/specify_cli/integrations/test_installed_adapters.py index 5b0f80e8e1..d48ad5a1f4 100644 --- a/tests/specify_cli/integrations/test_installed_adapters.py +++ b/tests/specify_cli/integrations/test_installed_adapters.py @@ -15,6 +15,7 @@ import sys import tarfile import threading +import urllib.request import zipfile from datetime import datetime, timedelta, timezone from functools import partial @@ -157,6 +158,16 @@ def log_message(self, *args): result = SimpleNamespace( root=downloads, url=f"https://127.0.0.1:{http.server_port}", requests=requests, ) + from specify_cli.authentication import http as authentication_http + + original_open_url = authentication_http.open_url + + def open_loopback_url(url, *args, **kwargs): + if url.startswith(f"{result.url}/"): + kwargs["timeout"] = max(kwargs["timeout"], 60) + return original_open_url(url, *args, **kwargs) + + monkeypatch.setattr(authentication_http, "open_url", open_loopback_url) try: yield result finally: @@ -186,6 +197,24 @@ def set_minimum_version(context, version): assert context.minimum_version > ssl.TLSVersion.TLSv1_1 +def test_loopback_catalog_survives_short_handshake_window(tmp_path, server, monkeypatch): + original_open = urllib.request.OpenerDirector.open + + def require_handshake_window(opener, fullurl, *args, **kwargs): + if fullurl.full_url.startswith(f"{server.url}/") and kwargs["timeout"] < 60: + raise TimeoutError("The handshake operation timed out") + return original_open(opener, fullurl, *args, **kwargs) + + monkeypatch.setattr(urllib.request.OpenerDirector, "open", require_handshake_window) + publish(server) + project = catalog_project(tmp_path, server) + + install(project) + + assert read_records(project)[KEY]["version"] == "1.0.0" + assert "/catalog.json" in server.requests + + def publish(server, *, metadata=None, code=None, version="1.0.0", members=None, archive="zip"): data = descriptor(version) if metadata is None else metadata source = implementation() if code is None else code From 29d781e2e531499149aeb802628f7f8616e7c8e8 Mon Sep 17 00:00:00 2001 From: chelsealong Date: Mon, 23 Nov 2026 16:23:02 +0000 Subject: [PATCH 2/2] Handle loopback fixture timeout review --- .../integrations/test_installed_adapters.py | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/specify_cli/integrations/test_installed_adapters.py b/tests/specify_cli/integrations/test_installed_adapters.py index d48ad5a1f4..5487483cac 100644 --- a/tests/specify_cli/integrations/test_installed_adapters.py +++ b/tests/specify_cli/integrations/test_installed_adapters.py @@ -162,10 +162,13 @@ def log_message(self, *args): original_open_url = authentication_http.open_url - def open_loopback_url(url, *args, **kwargs): + def open_loopback_url(url, timeout=10, extra_headers=None, redirect_validator=None): if url.startswith(f"{result.url}/"): - kwargs["timeout"] = max(kwargs["timeout"], 60) - return original_open_url(url, *args, **kwargs) + timeout = max(timeout, 60) + return original_open_url( + url, timeout=timeout, extra_headers=extra_headers, + redirect_validator=redirect_validator, + ) monkeypatch.setattr(authentication_http, "open_url", open_loopback_url) try: @@ -215,6 +218,35 @@ def require_handshake_window(opener, fullurl, *args, **kwargs): assert "/catalog.json" in server.requests +def test_loopback_timeout_preserves_open_url_call_forms_and_other_hosts(server, monkeypatch): + from specify_cli.authentication import http as authentication_http + + observed = [] + + def record_open(opener, request, *, timeout): + observed.append((request.full_url, timeout)) + return object() + + monkeypatch.setattr(urllib.request.OpenerDirector, "open", record_open) + fixture_url = f"{server.url}/catalog.json" + other_port = "https://127.0.0.1:1/catalog.json" + remote_url = "https://example.com/catalog.json" + + authentication_http.open_url(fixture_url) + authentication_http.open_url(fixture_url, 10) + authentication_http.open_url(fixture_url, timeout=90) + authentication_http.open_url(other_port, 10) + authentication_http.open_url(remote_url, timeout=5) + + assert observed == [ + (fixture_url, 60), + (fixture_url, 60), + (fixture_url, 90), + (other_port, 10), + (remote_url, 5), + ] + + def publish(server, *, metadata=None, code=None, version="1.0.0", members=None, archive="zip"): data = descriptor(version) if metadata is None else metadata source = implementation() if code is None else code