Files
thePlug/backend/tests/services/test_mitmproxy_options.py
T
2026-05-07 09:21:45 +02:00

53 lines
1.4 KiB
Python

import pytest
from app.services.mitmproxy.options import (
MitmOption,
parse_options,
public_options,
validate_value,
)
def test_parse_options_extracts_types_and_choices():
text = """
# Enable feature. Type bool.
enabled: false
# Valid values are 'eager', 'lazy'.
strategy: eager
# Hosts. Type sequence of str.
hosts: []
"""
options = parse_options(
text,
{"enabled": False, "strategy": "eager", "hosts": []},
)
assert options["enabled"].value_type == "bool"
assert options["strategy"].choices == ["eager", "lazy"]
assert options["hosts"].value_type == "sequence of str"
@pytest.mark.parametrize(
("option", "value", "message"),
[
(MitmOption("anticache", "bool", False, "", []), "true", "expected bool"),
(MitmOption("flow_detail", "int", 1, "", []), "1", "expected int"),
(MitmOption("allow_hosts", "sequence of str", [], "", []), "x", "list[str]"),
(MitmOption("strategy", "unknown", "eager", "", ["eager"]), "lazy", "one of"),
],
)
def test_validate_value_rejects_wrong_types(option, value, message):
assert message in validate_value(option, value)
def test_public_options_include_docs_links():
options = {
"flow_detail": MitmOption("flow_detail", "int", 1, "Flow detail.", []),
}
public = public_options(options)
assert public[0]["docs_url"].endswith("#flow_detail")