diff --git a/test/qa/lib/firewall.py b/test/qa/lib/firewall.py index 34bdb1f95..830b64a7a 100644 --- a/test/qa/lib/firewall.py +++ b/test/qa/lib/firewall.py @@ -171,15 +171,17 @@ def __rules_allowlist_subnet_chain_forward(interface: str, subnets: list[str]): for subnet in subnets: result += (f"-A FORWARD -d {subnet} -o {interface} -m comment --comment nordvpn -j ACCEPT", ) + result += (f"-A FORWARD -o {interface} -m comment --comment nordvpn -j DROP", ) + current_subnet_rules_forward_chain = [] fw_lines = os.popen("sudo iptables -S").read() for line in fw_lines.splitlines(): - if "FORWARD" in line and "-d" in line: + if "FORWARD" in line and ("-d" in line or "DROP" in line): current_subnet_rules_forward_chain.append(line) - if current_subnet_rules_forward_chain: + if len(current_subnet_rules_forward_chain) > len(result): return sort_list_by_other_list(result, current_subnet_rules_forward_chain) else: return result @@ -191,6 +193,15 @@ def __rules_allowlist_subnet_chain_output(interface: str, subnets: list[str]): for subnet in subnets: result += (f"-A OUTPUT -d {subnet} -o {interface} -m comment --comment nordvpn -j ACCEPT", ) + result += ("-A OUTPUT -d 169.254.0.0/16 -p tcp -m tcp --dport 53 -m comment --comment nordvpn -j DROP", ) + result += ("-A OUTPUT -d 169.254.0.0/16 -p udp -m udp --dport 53 -m comment --comment nordvpn -j DROP", ) + result += ("-A OUTPUT -d 192.168.0.0/16 -p tcp -m tcp --dport 53 -m comment --comment nordvpn -j DROP", ) + result += ("-A OUTPUT -d 192.168.0.0/16 -p udp -m udp --dport 53 -m comment --comment nordvpn -j DROP", ) + result += ("-A OUTPUT -d 172.16.0.0/12 -p tcp -m tcp --dport 53 -m comment --comment nordvpn -j DROP", ) + result += ("-A OUTPUT -d 172.16.0.0/12 -p udp -m udp --dport 53 -m comment --comment nordvpn -j DROP", ) + result += ("-A OUTPUT -d 10.0.0.0/8 -p tcp -m tcp --dport 53 -m comment --comment nordvpn -j DROP", ) + result += ("-A OUTPUT -d 10.0.0.0/8 -p udp -m udp --dport 53 -m comment --comment nordvpn -j DROP", ) + current_subnet_rules_input_chain = [] fw_lines = os.popen("sudo iptables -S").read() @@ -199,7 +210,7 @@ def __rules_allowlist_subnet_chain_output(interface: str, subnets: list[str]): if "OUTPUT" in line and "-d" in line: current_subnet_rules_input_chain.append(line) - if current_subnet_rules_input_chain: + if len(current_subnet_rules_input_chain) > len(result): return sort_list_by_other_list(result, current_subnet_rules_input_chain) else: return result diff --git a/test/qa/test_allowlist_subnet.py b/test/qa/test_allowlist_subnet.py index 879db4d5f..d1c013bb7 100644 --- a/test/qa/test_allowlist_subnet.py +++ b/test/qa/test_allowlist_subnet.py @@ -3,7 +3,6 @@ import pytest import sh -import timeout_decorator import lib from lib import ( @@ -58,8 +57,6 @@ def test_allowlist_does_not_create_new_routes_when_adding_deleting_subnets_disco @pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES) -@pytest.mark.flaky(reruns=2, reruns_delay=90) -@timeout_decorator.timeout(40) def test_connect_allowlist_subnet(tech, proto, obfuscated): lib.set_technology_and_protocol(tech, proto, obfuscated) @@ -81,8 +78,6 @@ def test_connect_allowlist_subnet(tech, proto, obfuscated): @pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES) -@pytest.mark.flaky(reruns=2, reruns_delay=90) -@timeout_decorator.timeout(40) def test_allowlist_subnet_connect(tech, proto, obfuscated): lib.set_technology_and_protocol(tech, proto, obfuscated) @@ -120,8 +115,6 @@ def test_allowlist_subnet_twice_disconnected(tech, proto, obfuscated, subnet): @pytest.mark.parametrize("subnet", lib.SUBNETS) @pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES) -@pytest.mark.flaky(reruns=2, reruns_delay=90) -@timeout_decorator.timeout(40) def test_allowlist_subnet_twice_connected(tech, proto, obfuscated, subnet): lib.set_technology_and_protocol(tech, proto, obfuscated) @@ -156,8 +149,6 @@ def test_allowlist_subnet_and_remove_disconnected(tech, proto, obfuscated): @pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES) -@pytest.mark.flaky(reruns=2, reruns_delay=90) -@timeout_decorator.timeout(40) def test_allowlist_subnet_and_remove_connected(tech, proto, obfuscated): lib.set_technology_and_protocol(tech, proto, obfuscated) @@ -192,8 +183,6 @@ def test_allowlist_subnet_remove_nonexistent_disconnected(tech, proto, obfuscate @pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES) @pytest.mark.parametrize("subnet", lib.SUBNETS) -@pytest.mark.flaky(reruns=2, reruns_delay=90) -@timeout_decorator.timeout(40) def test_allowlist_subnet_remove_nonexistent_connected(tech, proto, obfuscated, subnet): lib.set_technology_and_protocol(tech, proto, obfuscated)