Skip to content

Commit da4ce19

Browse files
committed
Fix MacOSX tests.
1 parent 12d4b30 commit da4ce19

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

sshuttle/tests/test_methods_pf.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,21 @@ def test_firewall_command(mock_pf_get_dev, mock_ioctl, mock_stdout):
9595
]
9696

9797

98-
# FIXME - test fails with platform=='darwin' due re.search not liking Mock
99-
# objects.
100-
@patch('sshuttle.methods.pf.sys.platform', 'not_darwin')
98+
def pfctl(args, stdin=None):
99+
if args == '-s all':
100+
return (b'another mary had a little lamb\n', b'little lamb\n')
101+
if args == '-E':
102+
return (b'\n', b'Token : abcdefg\n')
103+
return None
104+
105+
106+
@patch('sshuttle.methods.pf.sys.platform', 'darwin')
101107
@patch('sshuttle.methods.pf.pfctl')
102108
@patch('sshuttle.methods.pf.ioctl')
103109
@patch('sshuttle.methods.pf.pf_get_dev')
104110
def test_setup_firewall(mock_pf_get_dev, mock_ioctl, mock_pfctl):
111+
mock_pfctl.side_effect = pfctl
112+
105113
method = get_method('pf')
106114
assert method.name == 'pf'
107115

@@ -145,16 +153,31 @@ def test_setup_firewall(mock_pf_get_dev, mock_ioctl, mock_pfctl):
145153
call(mock_pf_get_dev(), 3424666650, ANY),
146154
call(mock_pf_get_dev(), 3424666650, ANY),
147155
]
148-
# FIXME - needs more work
149-
# print(mock_pfctl.mock_calls)
150-
# assert mock_pfctl.mock_calls == []
156+
assert mock_pfctl.mock_calls == [
157+
call('-s all'),
158+
call('-a sshuttle -f /dev/stdin',
159+
b'table <forward_subnets> {!1.2.3.66/32,1.2.3.0/24}\n'
160+
b'table <dns_servers> {1.2.3.33}\n'
161+
b'rdr pass on lo0 proto tcp '
162+
b'to <forward_subnets> -> 127.0.0.1 port 1025\n'
163+
b'rdr pass on lo0 proto udp '
164+
b'to <dns_servers> port 53 -> 127.0.0.1 port 1027\n'
165+
b'pass out route-to lo0 inet proto tcp '
166+
b'to <forward_subnets> keep state\n'
167+
b'pass out route-to lo0 inet proto udp '
168+
b'to <dns_servers> port 53 keep state\n'),
169+
call('-E'),
170+
]
151171
mock_pf_get_dev.reset_mock()
152172
mock_ioctl.reset_mock()
153173
mock_pfctl.reset_mock()
154174

155175
method.setup_firewall(1025, 0, [], 2, [], False)
156176
assert mock_ioctl.mock_calls == []
157-
assert mock_pfctl.mock_calls == [call('-a sshuttle -F all')]
177+
assert mock_pfctl.mock_calls == [
178+
call('-a sshuttle -F all'),
179+
call("-X b'abcdefg'"),
180+
]
158181
mock_pf_get_dev.reset_mock()
159182
mock_pfctl.reset_mock()
160183
mock_ioctl.reset_mock()

0 commit comments

Comments
 (0)