Skip to content

Commit 9cc6d63

Browse files
committed
Fix firewall tests.
1 parent 43566eb commit 9cc6d63

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

sshuttle/tests/test_firewall.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def setup_daemon():
2424
return stdin, stdout
2525

2626

27+
@patch('sshuttle.firewall.HOSTSFILE', new='tmp/hosts')
28+
@patch('sshuttle.firewall.hostmap', new={
29+
'myhost': '1.2.3.4',
30+
'myotherhost': '1.2.3.5',
31+
})
2732
def test_rewrite_etc_hosts():
2833
if not os.path.isdir("tmp"):
2934
os.mkdir("tmp")
@@ -33,11 +38,6 @@ def test_rewrite_etc_hosts():
3338

3439
shutil.copyfile("tmp/hosts.orig", "tmp/hosts")
3540

36-
sshuttle.firewall.HOSTSFILE = "tmp/hosts"
37-
sshuttle.firewall.hostmap = {
38-
'myhost': '1.2.3.4',
39-
'myotherhost': '1.2.3.5',
40-
}
4141
sshuttle.firewall.rewrite_etc_hosts(10)
4242
with open("tmp/hosts") as f:
4343
line = f.readline()
@@ -61,14 +61,26 @@ def test_rewrite_etc_hosts():
6161
assert filecmp.cmp("tmp/hosts.orig", "tmp/hosts", shallow=False) is True
6262

6363

64+
@patch('sshuttle.firewall.HOSTSFILE', new='tmp/hosts')
6465
@patch('sshuttle.firewall.setup_daemon')
6566
@patch('sshuttle.firewall.get_method')
6667
def test_main(mock_get_method, mock_setup_daemon):
6768
stdin, stdout = setup_daemon()
6869
mock_setup_daemon.return_value = stdin, stdout
6970

71+
if not os.path.isdir("tmp"):
72+
os.mkdir("tmp")
73+
7074
sshuttle.firewall.main("test", False)
7175

76+
with open("tmp/hosts") as f:
77+
line = f.readline()
78+
s = line.split()
79+
assert s == ['1.2.3.3', 'existing']
80+
81+
line = f.readline()
82+
assert line == ""
83+
7284
stdout.mock_calls == [
7385
call.write('READY test\n'),
7486
call.flush(),

0 commit comments

Comments
 (0)