Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
dea3f219
Commit
dea3f219
authored
Mar 16, 2016
by
Brian May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write more server tests
parent
d522d1e1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
3 deletions
+62
-3
server.py
sshuttle/server.py
+3
-0
test_server.py
sshuttle/tests/server/test_server.py
+59
-3
No files found.
sshuttle/server.py
View file @
dea3f219
...
@@ -17,6 +17,7 @@ from sshuttle.helpers import log, debug1, debug2, debug3, Fatal, \
...
@@ -17,6 +17,7 @@ from sshuttle.helpers import log, debug1, debug2, debug3, Fatal, \
def
_ipmatch
(
ipstr
):
def
_ipmatch
(
ipstr
):
# FIXME: IPv4 only
if
ipstr
==
b
'default'
:
if
ipstr
==
b
'default'
:
ipstr
=
b
'0.0.0.0/0'
ipstr
=
b
'0.0.0.0/0'
m
=
re
.
match
(
b
'^(
\
d+(
\
.
\
d+(
\
.
\
d+(
\
.
\
d+)?)?)?)(?:/(
\
d+))?$'
,
ipstr
)
m
=
re
.
match
(
b
'^(
\
d+(
\
.
\
d+(
\
.
\
d+(
\
.
\
d+)?)?)?)(?:/(
\
d+))?$'
,
ipstr
)
...
@@ -38,6 +39,7 @@ def _ipmatch(ipstr):
...
@@ -38,6 +39,7 @@ def _ipmatch(ipstr):
def
_ipstr
(
ip
,
width
):
def
_ipstr
(
ip
,
width
):
# FIXME: IPv4 only
if
width
>=
32
:
if
width
>=
32
:
return
ip
return
ip
else
:
else
:
...
@@ -45,6 +47,7 @@ def _ipstr(ip, width):
...
@@ -45,6 +47,7 @@ def _ipstr(ip, width):
def
_maskbits
(
netmask
):
def
_maskbits
(
netmask
):
# FIXME: IPv4 only
if
not
netmask
:
if
not
netmask
:
return
32
return
32
for
i
in
range
(
32
):
for
i
in
range
(
32
):
...
...
sshuttle/tests/server/test_server.py
View file @
dea3f219
import
io
import
socket
import
sshuttle.server
import
sshuttle.server
from
mock
import
patch
,
Mock
,
call
def
test__ipmatch
():
def
test__ipmatch
():
assert
sshuttle
.
server
.
_ipmatch
(
"1.2.3.4"
)
is
not
None
assert
sshuttle
.
server
.
_ipmatch
(
b
"1.2.3.4"
)
is
not
None
assert
sshuttle
.
server
.
_ipmatch
(
"::1"
)
is
not
None
assert
sshuttle
.
server
.
_ipmatch
(
b
"::1"
)
is
None
# ipv6 not supported
assert
sshuttle
.
server
.
_ipmatch
(
"42 Example Street, Melbourne"
)
is
None
assert
sshuttle
.
server
.
_ipmatch
(
b
"42 Example Street, Melbourne"
)
is
None
def
test__ipstr
():
assert
sshuttle
.
server
.
_ipstr
(
"1.2.3.4"
,
24
)
==
"1.2.3.4/24"
assert
sshuttle
.
server
.
_ipstr
(
"1.2.3.4"
,
32
)
==
"1.2.3.4"
def
test__maskbits
():
netmask
=
sshuttle
.
server
.
_ipmatch
(
b
"255.255.255.0"
)
sshuttle
.
server
.
_maskbits
(
netmask
)
@
patch
(
'sshuttle.server.ssubprocess.Popen'
)
def
test__listroutes
(
mock_popen
):
mock_pobj
=
Mock
()
mock_pobj
.
stdout
=
io
.
BytesIO
(
b
"""
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
"""
)
mock_pobj
.
wait
.
return_value
=
0
mock_popen
.
return_value
=
mock_pobj
routes
=
sshuttle
.
server
.
_list_routes
()
assert
mock_popen
.
mock_calls
==
[
call
([
'netstat'
,
'-rn'
],
stdout
=-
1
),
call
()
.
wait
()
]
assert
routes
==
[
(
socket
.
AF_INET
,
'0.0.0.0'
,
0
),
(
socket
.
AF_INET
,
'192.168.1.0'
,
24
)
]
@
patch
(
'sshuttle.server.ssubprocess.Popen'
)
def
test_listroutes
(
mock_popen
):
mock_pobj
=
Mock
()
mock_pobj
.
stdout
=
io
.
BytesIO
(
b
"""
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
"""
)
mock_pobj
.
wait
.
return_value
=
0
mock_popen
.
return_value
=
mock_pobj
routes
=
sshuttle
.
server
.
list_routes
()
assert
list
(
routes
)
==
[
(
socket
.
AF_INET
,
'192.168.1.0'
,
24
)
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment