-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathtest_killswitch.py
176 lines (125 loc) · 5.41 KB
/
test_killswitch.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
import pytest
import sh
import lib
from lib import (
daemon,
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()
MSG_KILLSWITCH_ON = "Kill Switch is set to 'enabled' successfully."
MSG_KILLSWITCH_OFF = "Kill Switch is set to 'disabled' successfully."
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES)
def test_killswitch_on_disconnected(tech, proto, obfuscated):
lib.set_technology_and_protocol(tech, proto, obfuscated)
assert network.is_available()
assert MSG_KILLSWITCH_ON in sh.nordvpn.set.killswitch("on")
assert daemon.is_killswitch_on()
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
assert network.is_not_available(2)
assert MSG_KILLSWITCH_OFF in sh.nordvpn.set.killswitch("off")
assert not daemon.is_killswitch_on()
assert network.is_available()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES)
def test_killswitch_on_connect(tech, proto, obfuscated):
lib.set_technology_and_protocol(tech, proto, obfuscated)
assert network.is_available()
assert MSG_KILLSWITCH_ON in sh.nordvpn.set.killswitch("on")
assert daemon.is_killswitch_on()
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
assert network.is_not_available(2)
with lib.ErrorDefer(sh.nordvpn.disconnect):
output = sh.nordvpn.connect()
print(output)
assert network.is_connected()
output = sh.nordvpn.disconnect()
print(output)
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
assert network.is_not_available(2)
assert MSG_KILLSWITCH_OFF in sh.nordvpn.set.killswitch("off")
assert not daemon.is_killswitch_on()
assert network.is_available()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES)
def test_killswitch_on_connected(tech, proto, obfuscated):
lib.set_technology_and_protocol(tech, proto, obfuscated)
assert network.is_available()
with lib.Defer(sh.nordvpn.disconnect):
output = sh.nordvpn.connect()
print(output)
assert network.is_connected()
assert MSG_KILLSWITCH_ON in sh.nordvpn.set.killswitch("on")
assert daemon.is_killswitch_on()
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
assert network.is_not_available(2)
assert MSG_KILLSWITCH_OFF in sh.nordvpn.set.killswitch("off")
assert not daemon.is_killswitch_on()
assert network.is_available()
@pytest.mark.parametrize(("tech", "proto", "obfuscated"), lib.TECHNOLOGIES)
def test_killswitch_off_connected(tech, proto, obfuscated):
lib.set_technology_and_protocol(tech, proto, obfuscated)
assert network.is_available()
assert MSG_KILLSWITCH_ON in sh.nordvpn.set.killswitch("on")
assert daemon.is_killswitch_on()
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
assert network.is_not_available(2)
with lib.Defer(sh.nordvpn.disconnect):
output = sh.nordvpn.connect()
print(output)
assert network.is_connected()
assert MSG_KILLSWITCH_OFF in sh.nordvpn.set.killswitch("off")
assert not daemon.is_killswitch_on()
assert network.is_available()
assert network.is_available()
@pytest.mark.parametrize(("tech_from", "proto_from", "obfuscated_from"), lib.TECHNOLOGIES)
@pytest.mark.parametrize(("tech_to", "proto_to", "obfuscated_to"), lib.TECHNOLOGIES)
def test_killswitch_reconnect(tech_from, proto_from, obfuscated_from, tech_to, proto_to, obfuscated_to):
lib.set_technology_and_protocol(tech_from, proto_from, obfuscated_from)
assert network.is_available()
assert MSG_KILLSWITCH_ON in sh.nordvpn.set.killswitch("on")
assert daemon.is_killswitch_on()
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
assert network.is_not_available(2)
with lib.ErrorDefer(sh.nordvpn.disconnect):
output = sh.nordvpn.connect()
print(output)
assert network.is_connected()
lib.set_technology_and_protocol(tech_to, proto_to, obfuscated_to)
assert network.is_connected()
output = sh.nordvpn.connect()
print(output)
assert network.is_connected()
output = sh.nordvpn.disconnect()
print(output)
assert daemon.is_disconnected()
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
assert network.is_not_available(2)
assert MSG_KILLSWITCH_OFF in sh.nordvpn.set.killswitch("off")
assert not daemon.is_killswitch_on()
assert network.is_available()
# Test for 3.8.7 hotfix. Account and login commands would not work when killswitch is on
# Issue 441
def test_fancy_transport():
sh.nordvpn.logout("--persist-token")
output = sh.nordvpn.set.killswitch("on")
assert MSG_KILLSWITCH_ON in output
output = login.login_as("default")
print(output)
assert "Welcome to NordVPN!" in output
with lib.ErrorDefer(sh.nordvpn.set.killswitch.off):
output = sh.nordvpn.account()
print(output)
assert "Account Information:" in output
sh.nordvpn.set.killswitch("off")
assert network.is_available()