Skip to content

Commit

Permalink
Fix forwarding rules and tests
Browse files Browse the repository at this point in the history
Signed-off-by: keliramu <[email protected]>
  • Loading branch information
keliramu committed Aug 6, 2024
1 parent a7e0c89 commit e98e22d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
17 changes: 14 additions & 3 deletions test/qa/lib/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions test/qa/test_allowlist_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
import sh
import timeout_decorator

import lib
from lib import (
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e98e22d

Please sign in to comment.