Auto-detect scheme for AUTHGUARD_URL instead of always assuming https
A bare host:port (e.g. a LAN AuthGuard reachable only over plain HTTP) was always defaulting to https, so a TLS handshake against a plain-HTTP AuthGuard failed at the transport level. Now a loopback, RFC1918/RFC4193 private, or link-local host (or a .local name) defaults to http instead; an explicit http:// or https:// is still always honored as-is. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
730bf0463f
commit
449bb6fd6a
8 files changed
+241
-27
No files matched your search
@@ -50,14 +50,29 @@ def _fake_http_error(status: int, payload: dict) -> urllib.error.HTTPError:
|
||||
|
||||
|
||||
class AuthClientBaseUrlTests(unittest.TestCase):
|
||||
def test_bare_host_assumes_https(self) -> None:
|
||||
def test_bare_public_host_assumes_https(self) -> None:
|
||||
self.assertEqual(AuthClient("auth.example.com").base_url, "https://auth.example.com")
|
||||
self.assertEqual(AuthClient("192.168.1.50:8080").base_url, "https://192.168.1.50:8080")
|
||||
self.assertEqual(AuthClient("auth.example.com:8080").base_url, "https://auth.example.com:8080")
|
||||
|
||||
def test_bare_private_host_assumes_http(self) -> None:
|
||||
self.assertEqual(AuthClient("192.168.1.50:8080").base_url, "http://192.168.1.50:8080")
|
||||
self.assertEqual(AuthClient("10.1.2.3:8080").base_url, "http://10.1.2.3:8080")
|
||||
self.assertEqual(AuthClient("172.20.0.5:8080").base_url, "http://172.20.0.5:8080")
|
||||
self.assertEqual(AuthClient("127.0.0.1:8080").base_url, "http://127.0.0.1:8080")
|
||||
self.assertEqual(AuthClient("169.254.1.1:8080").base_url, "http://169.254.1.1:8080")
|
||||
self.assertEqual(AuthClient("localhost:8080").base_url, "http://localhost:8080")
|
||||
self.assertEqual(AuthClient("authguard.local:8080").base_url, "http://authguard.local:8080")
|
||||
self.assertEqual(AuthClient("[::1]:8080").base_url, "http://[::1]:8080")
|
||||
self.assertEqual(AuthClient("[fd00::1]:8080").base_url, "http://[fd00::1]:8080")
|
||||
|
||||
def test_172_range_outside_private_block_assumes_https(self) -> None:
|
||||
self.assertEqual(AuthClient("172.32.0.5:8080").base_url, "https://172.32.0.5:8080")
|
||||
|
||||
def test_explicit_scheme_left_alone(self) -> None:
|
||||
self.assertEqual(AuthClient("http://auth.example.com").base_url, "http://auth.example.com")
|
||||
self.assertEqual(AuthClient("https://auth.example.com").base_url, "https://auth.example.com")
|
||||
self.assertEqual(AuthClient("HTTP://auth.example.com").base_url, "HTTP://auth.example.com")
|
||||
self.assertEqual(AuthClient("https://192.168.1.50:8080").base_url, "https://192.168.1.50:8080")
|
||||
|
||||
def test_trailing_slash_stripped_before_scheme_check(self) -> None:
|
||||
self.assertEqual(AuthClient("auth.example.com/").base_url, "https://auth.example.com")
|
||||
|
||||
Reference in new issue
Block a user