fix issue where you couldn't update ports
Build and Push Container / build-and-push (push) Successful in 26s
Build and Push Container / build-and-push (push) Successful in 26s
This commit is contained in:
@@ -9,7 +9,10 @@ from unifi_firewall import (
|
||||
FirewallPolicyCreatePayload,
|
||||
build_policy_payload,
|
||||
create_policy,
|
||||
get_action_from_policy,
|
||||
get_dest_ports_from_policy,
|
||||
get_policy,
|
||||
get_protocol_from_policy,
|
||||
get_session,
|
||||
get_source_ip_from_policy,
|
||||
list_policies,
|
||||
@@ -297,3 +300,126 @@ class TestGetSourceIpFromPolicy:
|
||||
|
||||
ip = get_source_ip_from_policy(policy) # type: ignore[arg-type]
|
||||
assert ip is None
|
||||
|
||||
|
||||
class TestGetDestPortsFromPolicy:
|
||||
def test_extracts_ports_and_ranges(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"id": "pol-1",
|
||||
"name": "Test",
|
||||
"source": {"zoneId": "wan-zone", "trafficFilter": None},
|
||||
"destination": {
|
||||
"zoneId": "lan-zone",
|
||||
"trafficFilter": {
|
||||
"type": "PORT",
|
||||
"portFilter": {
|
||||
"type": "PORTS",
|
||||
"matchOpposite": False,
|
||||
"items": [
|
||||
{"type": "PORT_NUMBER", "value": 80},
|
||||
{"type": "PORT_NUMBER", "value": 443},
|
||||
{"type": "PORT_NUMBER_RANGE", "start": 8000, "stop": 9000},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
"action": {"type": "ALLOW", "allowReturnTraffic": True},
|
||||
"ipProtocolScope": {"ipVersion": "IPV4"},
|
||||
"enabled": True,
|
||||
"loggingEnabled": False,
|
||||
"index": 0,
|
||||
"metadata": {},
|
||||
}
|
||||
|
||||
result = get_dest_ports_from_policy(policy) # type: ignore[arg-type]
|
||||
assert result is not None
|
||||
dest_ports, dest_port_ranges = result
|
||||
assert sorted(dest_ports) == [80, 443]
|
||||
assert len(dest_port_ranges) == 1
|
||||
assert dest_port_ranges[0] == {"start": 8000, "stop": 9000}
|
||||
|
||||
def test_returns_none_no_port_filter(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"destination": {
|
||||
"zoneId": "lan-zone",
|
||||
"trafficFilter": None,
|
||||
},
|
||||
}
|
||||
|
||||
result = get_dest_ports_from_policy(policy) # type: ignore[arg-type]
|
||||
assert result is None
|
||||
|
||||
def test_returns_none_empty_items(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"destination": {
|
||||
"zoneId": "lan-zone",
|
||||
"trafficFilter": {
|
||||
"type": "PORT",
|
||||
"portFilter": {"type": "PORTS", "items": []},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
result = get_dest_ports_from_policy(policy) # type: ignore[arg-type]
|
||||
assert result is None
|
||||
|
||||
|
||||
class TestGetProtocolFromPolicy:
|
||||
def test_extracts_protocol(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"ipProtocolScope": {
|
||||
"ipVersion": "IPV4",
|
||||
"protocolFilter": {
|
||||
"type": "NAMED_PROTOCOL",
|
||||
"protocol": {"name": "TCP"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
protocol = get_protocol_from_policy(policy) # type: ignore[arg-type]
|
||||
assert protocol == "TCP"
|
||||
|
||||
def test_returns_none_no_protocol_filter(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"ipProtocolScope": {
|
||||
"ipVersion": "IPV4",
|
||||
"protocolFilter": None,
|
||||
},
|
||||
}
|
||||
|
||||
protocol = get_protocol_from_policy(policy) # type: ignore[arg-type]
|
||||
assert protocol is None
|
||||
|
||||
|
||||
class TestGetActionFromPolicy:
|
||||
def test_extracts_allow_action(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"action": {"type": "ALLOW", "allowReturnTraffic": True},
|
||||
}
|
||||
|
||||
result = get_action_from_policy(policy) # type: ignore[arg-type]
|
||||
assert result == ("ALLOW", True)
|
||||
|
||||
def test_extracts_allow_action_no_return_traffic(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"action": {"type": "ALLOW", "allowReturnTraffic": False},
|
||||
}
|
||||
|
||||
result = get_action_from_policy(policy) # type: ignore[arg-type]
|
||||
assert result == ("ALLOW", False)
|
||||
|
||||
def test_extracts_block_action(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"action": {"type": "BLOCK"},
|
||||
}
|
||||
|
||||
result = get_action_from_policy(policy) # type: ignore[arg-type]
|
||||
assert result == ("BLOCK", False)
|
||||
|
||||
def test_extracts_reject_action(self) -> None:
|
||||
policy: dict[str, Any] = {
|
||||
"action": {"type": "REJECT"},
|
||||
}
|
||||
|
||||
result = get_action_from_policy(policy) # type: ignore[arg-type]
|
||||
assert result == ("REJECT", False)
|
||||
|
||||
Reference in New Issue
Block a user