Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion leakix/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def __init__(self, ip: str, operator: Operator | None = None) -> None:

class PortField(CustomField):
def __init__(self, port: int, operator: Operator | None = None) -> None:
assert 0 <= port < 65536
if not (0 <= port < 65536):
raise ValueError(f"Port must be between 0 and 65535, got {port}")
super().__init__(v=str(port), operator=operator, field_name="port")


Expand Down
4 changes: 2 additions & 2 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ def test_serialize_with_max_port(self) -> None:
assert field.serialize() == "port:65535"

def test_invalid_port_negative(self) -> None:
with pytest.raises(AssertionError):
with pytest.raises(ValueError):
PortField(-1)

def test_invalid_port_too_large(self) -> None:
with pytest.raises(AssertionError):
with pytest.raises(ValueError):
PortField(65536)

def test_serialize_with_greater_operator(self) -> None:
Expand Down