From 5dbbac67ac0d0cc43f63e23a12a0f6508b8e1bad Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Fri, 31 Jul 2026 17:34:28 +0200 Subject: [PATCH 1/2] Create test test_create_and_read_firewall_protocol_all to verify new output type --- tests/integration/firewalls/fixtures.py | 26 +++++++++++++++++++ tests/integration/firewalls/test_firewalls.py | 16 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/integration/firewalls/fixtures.py b/tests/integration/firewalls/fixtures.py index 72559555f..64a6a71d6 100644 --- a/tests/integration/firewalls/fixtures.py +++ b/tests/integration/firewalls/fixtures.py @@ -32,3 +32,29 @@ def firewall_id(): yield firewall_id delete_target_id(target="firewalls", id=firewall_id) + + +@pytest.fixture(scope="session") +def firewall_protocol_all(): + firewall_id = exec_test_command( + BASE_CMDS["firewalls"] + + [ + "create", + "--label", + "fw-test-" + get_random_text(5), + "--rules.outbound_policy", + "ACCEPT", + "--rules.outbound", + '[{"protocol": "ALL", "addresses": {"ipv4": ["198.51.100.0/24"]}, "action": "ACCEPT", "label": "protocol_ALL_test"}]', + "--rules.inbound_policy", + "DROP", + "--text", + "--no-headers", + "--format", + "id", + ] + ) + + yield firewall_id + + delete_target_id(target="firewalls", id=firewall_id) diff --git a/tests/integration/firewalls/test_firewalls.py b/tests/integration/firewalls/test_firewalls.py index 27baf3e2e..bc5063ea1 100644 --- a/tests/integration/firewalls/test_firewalls.py +++ b/tests/integration/firewalls/test_firewalls.py @@ -8,6 +8,7 @@ from tests.integration.firewalls.fixtures import ( # noqa: F401 FIREWALL_LABEL, firewall_id, + firewall_protocol_all, ) from tests.integration.helpers import ( BASE_CMDS, @@ -275,3 +276,18 @@ def test_firewall_template_view(monkeypatch: MonkeyPatch): assert template["rules"]["outbound_policy"] == "ACCEPT" assert isinstance(template["rules"]["inbound"], list) assert isinstance(template["rules"]["outbound"], list) + + +def test_create_and_read_firewall_protocol_all(firewall_protocol_all): + output = json.loads( + exec_test_command( + BASE_CMDS["firewalls"] + + [ + "rules-list", + firewall_protocol_all, + "--json", + ] + ) + ) + assert output[0]["outbound"][0]["protocol"] == "ALL" + assert output[0]["outbound"][0]["addresses"]["ipv4"] == ["198.51.100.0/24"] From ae7e4b5400f35831f846ba0cc61c480cd361cf62 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Mon, 3 Aug 2026 15:30:48 +0200 Subject: [PATCH 2/2] Refactor axisting one and add new tests for protocol ALL and numeric types --- tests/integration/firewalls/fixtures.py | 30 +++++++++ tests/integration/firewalls/test_firewalls.py | 16 ----- .../firewalls/test_firewalls_rules.py | 64 +++++++++++++++++++ 3 files changed, 94 insertions(+), 16 deletions(-) diff --git a/tests/integration/firewalls/fixtures.py b/tests/integration/firewalls/fixtures.py index 64a6a71d6..88812afe9 100644 --- a/tests/integration/firewalls/fixtures.py +++ b/tests/integration/firewalls/fixtures.py @@ -1,3 +1,5 @@ +import json + import pytest from tests.integration.helpers import ( @@ -58,3 +60,31 @@ def firewall_protocol_all(): yield firewall_id delete_target_id(target="firewalls", id=firewall_id) + + +@pytest.fixture(scope="session") +def firewall_protocol_numeric_and_all(): + response = json.loads( + exec_test_command( + BASE_CMDS["firewalls"] + + [ + "create", + "--label", + "fw-test-" + get_random_text(5), + "--rules.inbound_policy", + "DROP", + "--rules.inbound", + '[{"protocol": "ALL", "addresses": {"ipv4": ["0.0.0.0/0"]}, "action": "ACCEPT", "label": "protocol_ALL_test"}]', + "--rules.outbound_policy", + "ACCEPT", + "--rules.outbound", + '[{"protocol": "40", "addresses": {"ipv4": ["198.51.100.0/24"]}, "action": "ACCEPT", "label": "protocol_numeric_test"}, ' + '{"protocol": "ALL", "addresses": {"ipv4": ["0.0.0.0/0"]}, "action": "ACCEPT", "label": "protocol_ALL_test"}]', + "--json", + ] + ) + ) + + yield response + + delete_target_id(target="firewalls", id=str(response[0]["id"])) diff --git a/tests/integration/firewalls/test_firewalls.py b/tests/integration/firewalls/test_firewalls.py index bc5063ea1..27baf3e2e 100644 --- a/tests/integration/firewalls/test_firewalls.py +++ b/tests/integration/firewalls/test_firewalls.py @@ -8,7 +8,6 @@ from tests.integration.firewalls.fixtures import ( # noqa: F401 FIREWALL_LABEL, firewall_id, - firewall_protocol_all, ) from tests.integration.helpers import ( BASE_CMDS, @@ -276,18 +275,3 @@ def test_firewall_template_view(monkeypatch: MonkeyPatch): assert template["rules"]["outbound_policy"] == "ACCEPT" assert isinstance(template["rules"]["inbound"], list) assert isinstance(template["rules"]["outbound"], list) - - -def test_create_and_read_firewall_protocol_all(firewall_protocol_all): - output = json.loads( - exec_test_command( - BASE_CMDS["firewalls"] - + [ - "rules-list", - firewall_protocol_all, - "--json", - ] - ) - ) - assert output[0]["outbound"][0]["protocol"] == "ALL" - assert output[0]["outbound"][0]["addresses"]["ipv4"] == ["198.51.100.0/24"] diff --git a/tests/integration/firewalls/test_firewalls_rules.py b/tests/integration/firewalls/test_firewalls_rules.py index 781ca7725..dab6ac19e 100644 --- a/tests/integration/firewalls/test_firewalls_rules.py +++ b/tests/integration/firewalls/test_firewalls_rules.py @@ -3,6 +3,8 @@ from tests.integration.firewalls.fixtures import ( # noqa: F401 firewall_id, + firewall_protocol_all, + firewall_protocol_numeric_and_all, ) from tests.integration.helpers import ( BASE_CMDS, @@ -280,3 +282,65 @@ def test_list_rules_json_format(firewall_id): ) ) assert result[0]["inbound"][0]["label"] == "rules-list-test" + + +def test_create_firewall_protocol_numeric_and_all( + firewall_protocol_numeric_and_all, +): + output = firewall_protocol_numeric_and_all[0] + assert output["status"] == "enabled" + assert output["rules"]["inbound_policy"] == "DROP" + assert output["rules"]["inbound"][0]["action"] == "ACCEPT" + assert output["rules"]["inbound"][0]["protocol"] == "ALL" + assert output["rules"]["inbound"][0]["addresses"]["ipv4"] == ["0.0.0.0/0"] + assert output["rules"]["outbound_policy"] == "ACCEPT" + assert output["rules"]["outbound"][0]["action"] == "ACCEPT" + assert output["rules"]["outbound"][0]["protocol"] == "40" + assert output["rules"]["outbound"][0]["addresses"]["ipv4"] == [ + "198.51.100.0/24" + ] + assert output["rules"]["outbound"][1]["action"] == "ACCEPT" + assert output["rules"]["outbound"][1]["protocol"] == "ALL" + assert output["rules"]["outbound"][1]["addresses"]["ipv4"] == ["0.0.0.0/0"] + assert output["rules"]["version"] == 1 + + +def test_firewall_protocol_all_get_rules_list(firewall_protocol_all): + output = json.loads( + exec_test_command( + BASE_CMDS["firewalls"] + + [ + "rules-list", + firewall_protocol_all, + "--json", + ] + ) + ) + assert len(output[0]["inbound"]) == 0 + assert output[0]["inbound_policy"] == "DROP" + assert output[0]["outbound_policy"] == "ACCEPT" + assert output[0]["outbound"][0]["action"] == "ACCEPT" + assert output[0]["outbound"][0]["protocol"] == "ALL" + assert output[0]["outbound"][0]["addresses"]["ipv4"] == ["198.51.100.0/24"] + assert output[0]["version"] == 1 + + +def test_firewall_protocol_all_get_version_view(firewall_protocol_all): + output = json.loads( + exec_test_command( + BASE_CMDS["firewalls"] + + [ + "version-view", + firewall_protocol_all, + "1", + "--json", + ] + ) + ) + assert len(output[0]["inbound"]) == 0 + assert output[0]["inbound_policy"] == "DROP" + assert output[0]["outbound_policy"] == "ACCEPT" + assert output[0]["outbound"][0]["action"] == "ACCEPT" + assert output[0]["outbound"][0]["protocol"] == "ALL" + assert output[0]["outbound"][0]["addresses"]["ipv4"] == ["198.51.100.0/24"] + assert output[0]["version"] == 1