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
021e6f57
Commit
021e6f57
authored
Nov 17, 2015
by
Brian May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests.
parent
9cc6d636
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
165 additions
and
0 deletions
+165
-0
test_helpers.py
sshuttle/tests/test_helpers.py
+165
-0
No files found.
sshuttle/tests/test_helpers.py
0 → 100644
View file @
021e6f57
from
mock
import
patch
,
call
import
io
import
socket
import
sshuttle.helpers
@
patch
(
'sshuttle.helpers.logprefix'
,
new
=
'prefix: '
)
@
patch
(
'sshuttle.helpers.sys.stdout'
)
@
patch
(
'sshuttle.helpers.sys.stderr'
)
def
test_log
(
mock_stderr
,
mock_stdout
):
sshuttle
.
helpers
.
log
(
"message"
)
assert
mock_stdout
.
mock_calls
==
[
call
.
flush
(),
]
assert
mock_stderr
.
mock_calls
==
[
call
.
write
(
'prefix: message'
),
call
.
flush
(),
]
@
patch
(
'sshuttle.helpers.logprefix'
,
new
=
'prefix: '
)
@
patch
(
'sshuttle.helpers.verbose'
,
new
=
1
)
@
patch
(
'sshuttle.helpers.sys.stdout'
)
@
patch
(
'sshuttle.helpers.sys.stderr'
)
def
test_debug1
(
mock_stderr
,
mock_stdout
):
sshuttle
.
helpers
.
debug1
(
"message"
)
assert
mock_stdout
.
mock_calls
==
[
call
.
flush
(),
]
assert
mock_stderr
.
mock_calls
==
[
call
.
write
(
'prefix: message'
),
call
.
flush
(),
]
@
patch
(
'sshuttle.helpers.logprefix'
,
new
=
'prefix: '
)
@
patch
(
'sshuttle.helpers.verbose'
,
new
=
0
)
@
patch
(
'sshuttle.helpers.sys.stdout'
)
@
patch
(
'sshuttle.helpers.sys.stderr'
)
def
test_debug1_nop
(
mock_stderr
,
mock_stdout
):
sshuttle
.
helpers
.
debug1
(
"message"
)
assert
mock_stdout
.
mock_calls
==
[]
assert
mock_stderr
.
mock_calls
==
[]
@
patch
(
'sshuttle.helpers.logprefix'
,
new
=
'prefix: '
)
@
patch
(
'sshuttle.helpers.verbose'
,
new
=
2
)
@
patch
(
'sshuttle.helpers.sys.stdout'
)
@
patch
(
'sshuttle.helpers.sys.stderr'
)
def
test_debug2
(
mock_stderr
,
mock_stdout
):
sshuttle
.
helpers
.
debug2
(
"message"
)
assert
mock_stdout
.
mock_calls
==
[
call
.
flush
(),
]
assert
mock_stderr
.
mock_calls
==
[
call
.
write
(
'prefix: message'
),
call
.
flush
(),
]
@
patch
(
'sshuttle.helpers.logprefix'
,
new
=
'prefix: '
)
@
patch
(
'sshuttle.helpers.verbose'
,
new
=
1
)
@
patch
(
'sshuttle.helpers.sys.stdout'
)
@
patch
(
'sshuttle.helpers.sys.stderr'
)
def
test_debug2_nop
(
mock_stderr
,
mock_stdout
):
sshuttle
.
helpers
.
debug2
(
"message"
)
assert
mock_stdout
.
mock_calls
==
[]
assert
mock_stderr
.
mock_calls
==
[]
@
patch
(
'sshuttle.helpers.logprefix'
,
new
=
'prefix: '
)
@
patch
(
'sshuttle.helpers.verbose'
,
new
=
3
)
@
patch
(
'sshuttle.helpers.sys.stdout'
)
@
patch
(
'sshuttle.helpers.sys.stderr'
)
def
test_debug3
(
mock_stderr
,
mock_stdout
):
sshuttle
.
helpers
.
debug3
(
"message"
)
assert
mock_stdout
.
mock_calls
==
[
call
.
flush
(),
]
assert
mock_stderr
.
mock_calls
==
[
call
.
write
(
'prefix: message'
),
call
.
flush
(),
]
@
patch
(
'sshuttle.helpers.logprefix'
,
new
=
'prefix: '
)
@
patch
(
'sshuttle.helpers.verbose'
,
new
=
2
)
@
patch
(
'sshuttle.helpers.sys.stdout'
)
@
patch
(
'sshuttle.helpers.sys.stderr'
)
def
test_debug3_nop
(
mock_stderr
,
mock_stdout
):
sshuttle
.
helpers
.
debug3
(
"message"
)
assert
mock_stdout
.
mock_calls
==
[]
assert
mock_stderr
.
mock_calls
==
[]
@
patch
(
'sshuttle.helpers.open'
,
create
=
True
)
def
test_resolvconf_nameservers
(
mock_open
):
mock_open
.
return_value
=
io
.
StringIO
(
u"""
# Generated by NetworkManager
search pri
nameserver 192.168.1.1
nameserver 192.168.2.1
nameserver 192.168.3.1
nameserver 192.168.4.1
nameserver 2404:6800:4004:80c::1
nameserver 2404:6800:4004:80c::2
nameserver 2404:6800:4004:80c::3
nameserver 2404:6800:4004:80c::4
"""
)
ns
=
sshuttle
.
helpers
.
resolvconf_nameservers
()
assert
ns
==
[
(
2
,
u'192.168.1.1'
),
(
2
,
u'192.168.2.1'
),
(
2
,
u'192.168.3.1'
),
(
2
,
u'192.168.4.1'
),
(
10
,
u'2404:6800:4004:80c::1'
),
(
10
,
u'2404:6800:4004:80c::2'
),
(
10
,
u'2404:6800:4004:80c::3'
),
(
10
,
u'2404:6800:4004:80c::4'
)
]
@
patch
(
'sshuttle.helpers.open'
,
create
=
True
)
def
test_resolvconf_random_nameserver
(
mock_open
):
mock_open
.
return_value
=
io
.
StringIO
(
u"""
# Generated by NetworkManager
search pri
nameserver 192.168.1.1
nameserver 192.168.2.1
nameserver 192.168.3.1
nameserver 192.168.4.1
nameserver 2404:6800:4004:80c::1
nameserver 2404:6800:4004:80c::2
nameserver 2404:6800:4004:80c::3
nameserver 2404:6800:4004:80c::4
"""
)
ns
=
sshuttle
.
helpers
.
resolvconf_random_nameserver
()
assert
ns
in
[
(
2
,
u'192.168.1.1'
),
(
2
,
u'192.168.2.1'
),
(
2
,
u'192.168.3.1'
),
(
2
,
u'192.168.4.1'
),
(
10
,
u'2404:6800:4004:80c::1'
),
(
10
,
u'2404:6800:4004:80c::2'
),
(
10
,
u'2404:6800:4004:80c::3'
),
(
10
,
u'2404:6800:4004:80c::4'
)
]
def
test_islocal
():
assert
sshuttle
.
helpers
.
islocal
(
"127.0.0.1"
,
socket
.
AF_INET
)
assert
not
sshuttle
.
helpers
.
islocal
(
"192.0.2.1"
,
socket
.
AF_INET
)
assert
sshuttle
.
helpers
.
islocal
(
"::1"
,
socket
.
AF_INET6
)
assert
not
sshuttle
.
helpers
.
islocal
(
"2001:db8::1"
,
socket
.
AF_INET6
)
def
test_family_ip_tuple
():
assert
sshuttle
.
helpers
.
family_ip_tuple
(
"127.0.0.1"
)
\
==
(
socket
.
AF_INET
,
"127.0.0.1"
)
assert
sshuttle
.
helpers
.
family_ip_tuple
(
"192.168.2.6"
)
\
==
(
socket
.
AF_INET
,
"192.168.2.6"
)
assert
sshuttle
.
helpers
.
family_ip_tuple
(
"::1"
)
\
==
(
socket
.
AF_INET6
,
"::1"
)
assert
sshuttle
.
helpers
.
family_ip_tuple
(
"2404:6800:4004:80c::1"
)
\
==
(
socket
.
AF_INET6
,
"2404:6800:4004:80c::1"
)
def
test_family_to_string
():
assert
sshuttle
.
helpers
.
family_to_string
(
socket
.
AF_INET
)
==
"AF_INET"
assert
sshuttle
.
helpers
.
family_to_string
(
socket
.
AF_INET6
)
==
"AF_INET6"
assert
sshuttle
.
helpers
.
family_to_string
(
socket
.
AF_UNIX
)
==
"1"
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