mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
feat: add --config-url-insecure option to disable TLS certificate verification
Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
+67
-1
@@ -85,10 +85,38 @@ def test_parse_configuration_from_yaml() -> None:
|
||||
"""
|
||||
configuration = parse_configuration(raw)
|
||||
assert configuration.organisation == "InterDiode"
|
||||
assert configuration.description == ""
|
||||
assert configuration.description is None
|
||||
assert configuration.configurations.certificates == []
|
||||
|
||||
|
||||
def test_parse_configuration_without_uuid_or_organisation() -> None:
|
||||
configuration = parse_configuration(json.dumps({}))
|
||||
assert configuration.uuid is None
|
||||
assert configuration.organisation is None
|
||||
assert configuration.version == "1.0"
|
||||
assert configuration.description is None
|
||||
|
||||
|
||||
def test_parse_configuration_defaults_version_to_1_0() -> None:
|
||||
configuration = parse_configuration(json.dumps(FULL_CONFIG))
|
||||
assert configuration.version == "1.0"
|
||||
|
||||
|
||||
def test_parse_configuration_with_explicit_version() -> None:
|
||||
configuration = parse_configuration(json.dumps({**FULL_CONFIG, "version": "1.0"}))
|
||||
assert configuration.version == "1.0"
|
||||
|
||||
|
||||
def test_parse_configuration_coerces_unquoted_yaml_version_to_str() -> None:
|
||||
raw = """
|
||||
version: 1.0
|
||||
uuid: 12345678-1234-5678-1234-567812345678
|
||||
organisation: InterDiode
|
||||
"""
|
||||
configuration = parse_configuration(raw)
|
||||
assert configuration.version == "1.0"
|
||||
|
||||
|
||||
def test_load_configuration_from_file(tmp_path) -> None:
|
||||
config_file = tmp_path / "config.json"
|
||||
config_file.write_text(json.dumps(FULL_CONFIG), encoding="utf-8")
|
||||
@@ -166,6 +194,44 @@ def test_load_configuration_from_url_with_custom_cacert(monkeypatch) -> None:
|
||||
assert stats["x509"] == 1
|
||||
|
||||
|
||||
def test_load_configuration_from_url_insecure_disables_verification(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
mock_urlopen = _mock_urlopen(json.dumps(FULL_CONFIG).encode("utf-8"))
|
||||
monkeypatch.setattr("id_configurator.config.urllib.request.urlopen", mock_urlopen)
|
||||
|
||||
configuration = load_configuration(
|
||||
None,
|
||||
None,
|
||||
"https://example.invalid/config.json",
|
||||
None,
|
||||
True,
|
||||
)
|
||||
|
||||
assert configuration.organisation == "InterDiode"
|
||||
_, kwargs = mock_urlopen.call_args
|
||||
assert kwargs["context"].verify_mode.name == "CERT_NONE"
|
||||
assert kwargs["context"].check_hostname is False
|
||||
|
||||
|
||||
def test_load_configuration_from_url_insecure_ignores_cacert(monkeypatch) -> None:
|
||||
mock_urlopen = _mock_urlopen(json.dumps(FULL_CONFIG).encode("utf-8"))
|
||||
monkeypatch.setattr("id_configurator.config.urllib.request.urlopen", mock_urlopen)
|
||||
cacert_content = _self_signed_ca_pem()
|
||||
|
||||
configuration = load_configuration(
|
||||
None,
|
||||
None,
|
||||
"https://example.invalid/config.json",
|
||||
cacert_content,
|
||||
True,
|
||||
)
|
||||
|
||||
assert configuration.organisation == "InterDiode"
|
||||
_, kwargs = mock_urlopen.call_args
|
||||
assert kwargs["context"].verify_mode.name == "CERT_NONE"
|
||||
|
||||
|
||||
def test_apt_source_to_deb822_minimal() -> None:
|
||||
source = AptSource(
|
||||
name="interdiode", uris=["http://example.invalid/debian"], suites=["stable"]
|
||||
|
||||
Reference in New Issue
Block a user