-
Notifications
You must be signed in to change notification settings - Fork 45
/
test_firewall6.py
231 lines (174 loc) · 7.94 KB
/
test_firewall6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import random
import pytest
import sh
import lib
from lib import (
allowlist,
daemon,
firewall,
info,
logging,
login,
network,
)
def setup_module(module): # noqa: ARG001
daemon.start()
login.login_as("default")
def teardown_module(module): # noqa: ARG001
sh.nordvpn.logout("--persist-token")
daemon.stop()
def setup_function(function): # noqa: ARG001
logging.log()
def teardown_function(function): # noqa: ARG001
logging.log(data=info.collect())
logging.log()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
def test_connected_firewall_disable(tech, proto, obfuscated):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_ipv6("on")
lib.set_firewall("on")
assert not firewall.is_active()
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert firewall.is_active()
lib.set_firewall("off")
assert not firewall.is_active()
assert network.is_disconnected()
assert not firewall.is_active()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
def test_connected_firewall_enable(tech, proto, obfuscated):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_ipv6("on")
lib.set_firewall("off")
assert not firewall.is_active()
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert not firewall.is_active()
lib.set_firewall("on")
assert firewall.is_active()
assert network.is_disconnected()
assert not firewall.is_active()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
def test_firewall_disable_connect(tech, proto, obfuscated):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_ipv6("on")
lib.set_firewall("off")
assert not firewall.is_active()
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert not firewall.is_active()
assert network.is_disconnected()
assert not firewall.is_active()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
def test_firewall_enable_connect(tech, proto, obfuscated):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_ipv6("on")
lib.set_firewall("on")
assert not firewall.is_active()
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert firewall.is_active()
assert network.is_disconnected()
assert not firewall.is_active()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
@pytest.mark.parametrize("port", lib.PORTS)
def test_firewall_ipv6_02_allowlist_port(tech, proto, obfuscated, port):
with lib.Defer(lib.flush_allowlist):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_firewall("on")
lib.set_ipv6("on")
allowlist.add_ports_to_allowlist([port])
assert not firewall.is_active([port])
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert firewall.is_active([port])
lib.set_firewall("off")
assert not firewall.is_active([port])
assert network.is_ipv4_and_ipv6_connected(20)
assert network.is_disconnected()
assert not firewall.is_active([port])
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
@pytest.mark.parametrize("ports", lib.PORTS_RANGE)
def test_firewall_ipv6_03_allowlist_ports_range(tech, proto, obfuscated, ports):
with lib.Defer(lib.flush_allowlist):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_firewall("on")
lib.set_ipv6("on")
allowlist.add_ports_to_allowlist([ports])
assert not firewall.is_active([ports])
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert firewall.is_active([ports])
lib.set_firewall("off")
assert not firewall.is_active([ports])
assert network.is_ipv4_and_ipv6_connected(20)
assert network.is_disconnected()
assert not firewall.is_active([ports])
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
@pytest.mark.parametrize("port", lib.PORTS)
def test_firewall_ipv6_04_allowlist_port_and_protocol(tech, proto, obfuscated, port):
with lib.Defer(lib.flush_allowlist):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_firewall("on")
lib.set_ipv6("on")
allowlist.add_ports_to_allowlist([port])
assert not firewall.is_active([port])
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert firewall.is_active([port])
lib.set_firewall("off")
assert not firewall.is_active([port])
assert network.is_ipv4_and_ipv6_connected(20)
assert network.is_disconnected()
assert not firewall.is_active([port])
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
@pytest.mark.parametrize("subnet", lib.SUBNETS)
def test_firewall_ipv6_05_allowlist_subnet(tech, proto, obfuscated, subnet):
with lib.Defer(lib.flush_allowlist):
with lib.Defer(sh.nordvpn.disconnect):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_firewall("on")
lib.set_ipv6("on")
allowlist.add_subnet_to_allowlist([subnet])
assert not firewall.is_active(None, [subnet])
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert firewall.is_active(None, [subnet])
lib.set_firewall("off")
assert not firewall.is_active(None, [subnet])
assert network.is_ipv4_and_ipv6_connected(20)
assert network.is_disconnected()
assert not firewall.is_active(None, [subnet])
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
def test_firewall_ipv6_06_with_killswitch(tech, proto, obfuscated):
with lib.Defer(lambda: lib.set_killswitch("off")):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_firewall("on")
lib.set_ipv6("on")
assert not firewall.is_active()
lib.set_killswitch("on")
assert firewall.is_active()
assert not firewall.is_active()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.OVPN_STANDARD_TECHNOLOGIES)
def test_firewall_ipv6_07_with_killswitch_while_connected(tech, proto, obfuscated):
with lib.Defer(sh.nordvpn.disconnect):
with lib.Defer(lambda: lib.set_killswitch("off")):
lib.set_technology_and_protocol(tech, proto, obfuscated)
lib.set_firewall("on")
lib.set_ipv6("on")
assert not firewall.is_active()
lib.set_killswitch("on")
assert firewall.is_active()
sh.nordvpn.connect(random.choice(lib.IPV6_SERVERS))
assert network.is_ipv4_and_ipv6_connected(20)
assert firewall.is_active()
assert firewall.is_active()
assert network.is_disconnected()
assert not firewall.is_active()