@@ -95,13 +95,21 @@ def test_firewall_command(mock_pf_get_dev, mock_ioctl, mock_stdout):
95
95
]
96
96
97
97
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' )
101
107
@patch ('sshuttle.methods.pf.pfctl' )
102
108
@patch ('sshuttle.methods.pf.ioctl' )
103
109
@patch ('sshuttle.methods.pf.pf_get_dev' )
104
110
def test_setup_firewall (mock_pf_get_dev , mock_ioctl , mock_pfctl ):
111
+ mock_pfctl .side_effect = pfctl
112
+
105
113
method = get_method ('pf' )
106
114
assert method .name == 'pf'
107
115
@@ -145,16 +153,31 @@ def test_setup_firewall(mock_pf_get_dev, mock_ioctl, mock_pfctl):
145
153
call (mock_pf_get_dev (), 3424666650 , ANY ),
146
154
call (mock_pf_get_dev (), 3424666650 , ANY ),
147
155
]
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
+ ]
151
171
mock_pf_get_dev .reset_mock ()
152
172
mock_ioctl .reset_mock ()
153
173
mock_pfctl .reset_mock ()
154
174
155
175
method .setup_firewall (1025 , 0 , [], 2 , [], False )
156
176
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
+ ]
158
181
mock_pf_get_dev .reset_mock ()
159
182
mock_pfctl .reset_mock ()
160
183
mock_ioctl .reset_mock ()
0 commit comments