Files
devplacepy/tests/unit/services/nodes/spec.py
T

74 lines
2.2 KiB
Python
Raw Normal View History

# retoor <retoor@molodetz.nl>
import pytest
from devplacepy.services.nodes import spec
from devplacepy.services.nodes.spec import SPEC
def test_open_proxy_is_never_enabled():
assert SPEC.open_proxy is False
assert SPEC.describe()["open_proxy"] is False
def test_ports_are_web_only():
assert spec.ALLOWED_PORTS == (80, 443)
for destination in SPEC.destinations:
assert set(destination.ports) <= {80, 443}
def test_frame_types_unique_per_direction():
seen = [(item.type, item.direction) for item in SPEC.frames]
assert len(seen) == len(set(seen))
def test_every_frame_fits_the_wire_cap():
for item in SPEC.frames:
assert 0 < item.max_bytes <= 3 * 1024 * 1024
assert item.direction in (spec.CLIENT_TO_SERVER, spec.SERVER_TO_CLIENT)
def test_frame_lookup():
assert SPEC.frame("hello", spec.CLIENT_TO_SERVER).required()[0] == "protocol"
assert SPEC.frame("hello", spec.SERVER_TO_CLIENT) is None
assert "type" in SPEC.frame("ping", spec.SERVER_TO_CLIENT).allowed()
@pytest.mark.parametrize(
"host,expected",
[
("reddit.com", True),
("www.reddit.com", True),
("old.reddit.com", True),
("REDDIT.COM.", True),
("evilreddit.com", False),
("reddit.com.evil.net", False),
("localhost", False),
("127.0.0.1", False),
],
)
def test_destination_matching_is_suffix_safe(host, expected):
assert (SPEC.destination(host) is not None) is expected
def test_limits_are_positive_and_ordered():
limits = SPEC.limits
for value in limits.describe().values():
assert value >= 0
assert limits.default_wait_seconds <= limits.max_wait_seconds
assert limits.reconnect_min_seconds <= limits.reconnect_max_seconds
assert limits.cache_entry_max_bytes <= limits.cache_max_bytes
assert limits.default_donor_mb_per_day <= limits.max_donor_mb_per_day
assert limits.job_timeout_seconds <= limits.max_wait_seconds
assert limits.default_daily_requests_guest == 0
def test_protocol_versions_consistent():
assert SPEC.min_supported <= SPEC.version
def test_describe_is_json_serialisable():
import json
json.dumps(SPEC.describe())