mirror of
https://github.com/CloakHQ/CloakBrowser.git
synced 2026-06-23 11:41:46 +02:00
fix: support bare proxy format (user:pass@host:port) without scheme
Normalize bare proxy strings by prepending http:// before parsing when @ is present but :// is absent. Tests added for Python and JS.
This commit is contained in:
@@ -98,3 +98,56 @@ class TestMaybeResolveGeoip:
|
||||
tz, locale = _maybe_resolve_geoip(True, "http://proxy:8080", "Europe/Berlin", None)
|
||||
assert tz == "Europe/Berlin"
|
||||
assert locale == "ja-JP"
|
||||
|
||||
@patch("cloakbrowser.geoip.resolve_proxy_geo", return_value=("America/New_York", "en-US"))
|
||||
def test_geoip_normalizes_bare_proxy_with_creds(self, mock_geo):
|
||||
# "user:pass@host:port" must be normalized to http:// before geoip lookup.
|
||||
tz, locale = _maybe_resolve_geoip(True, "user:pass@proxy:8080", None, None)
|
||||
mock_geo.assert_called_once_with("http://user:pass@proxy:8080")
|
||||
assert tz == "America/New_York"
|
||||
assert locale == "en-US"
|
||||
|
||||
@patch("cloakbrowser.geoip.resolve_proxy_geo", return_value=("America/New_York", "en-US"))
|
||||
def test_geoip_normalizes_schemeless_proxy_no_creds(self, mock_geo):
|
||||
# "host:port" (no @ and no scheme) must also be normalized.
|
||||
tz, locale = _maybe_resolve_geoip(True, "proxy:8080", None, None)
|
||||
mock_geo.assert_called_once_with("http://proxy:8080")
|
||||
assert tz == "America/New_York"
|
||||
|
||||
|
||||
class TestBareProxyFormat:
|
||||
"""_parse_proxy_url must handle bare 'user:pass@host:port' strings (no scheme)."""
|
||||
|
||||
def test_bare_with_credentials(self):
|
||||
r = _parse_proxy_url("user:pass@proxy:8080")
|
||||
assert r["username"] == "user"
|
||||
assert r["password"] == "pass"
|
||||
assert r["server"] == "http://proxy:8080"
|
||||
|
||||
def test_bare_credentials_not_in_server(self):
|
||||
r = _parse_proxy_url("user:pass@proxy1.example.com:5610")
|
||||
assert "user" not in r["server"]
|
||||
assert "pass" not in r["server"]
|
||||
|
||||
def test_bare_username_only(self):
|
||||
r = _parse_proxy_url("user@proxy:8080")
|
||||
assert r["username"] == "user"
|
||||
assert "password" not in r
|
||||
assert r["server"] == "http://proxy:8080"
|
||||
|
||||
def test_bare_no_port(self):
|
||||
r = _parse_proxy_url("user:pass@proxy.example.com")
|
||||
assert r["username"] == "user"
|
||||
assert r["password"] == "pass"
|
||||
assert r["server"] == "http://proxy.example.com"
|
||||
|
||||
def test_bare_no_credentials_passthrough(self):
|
||||
# "host:port" without @ — no scheme, no creds — pass through unchanged
|
||||
r = _parse_proxy_url("proxy:8080")
|
||||
assert r == {"server": "proxy:8080"}
|
||||
|
||||
def test_build_proxy_kwargs_bare(self):
|
||||
r = _build_proxy_kwargs("user:pass@proxy:8080")
|
||||
assert r["proxy"]["username"] == "user"
|
||||
assert r["proxy"]["password"] == "pass"
|
||||
assert "user" not in r["proxy"]["server"]
|
||||
|
||||
Reference in New Issue
Block a user