mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-23 07:59:50 -05:00
Add more unit tests.
This commit is contained in:
parent
3a3b8fb21d
commit
47ba6043ce
@ -8,9 +8,12 @@ def get_platform():
|
|||||||
else:
|
else:
|
||||||
return platform.system()
|
return platform.system()
|
||||||
|
|
||||||
if get_platform() == 'Tails':
|
def append_lib_on_tails():
|
||||||
|
if get_platform() == 'Tails':
|
||||||
sys.path.append(os.path.dirname(__file__)+'/../tails/lib')
|
sys.path.append(os.path.dirname(__file__)+'/../tails/lib')
|
||||||
|
|
||||||
|
append_lib_on_tails()
|
||||||
|
|
||||||
from stem.control import Controller
|
from stem.control import Controller
|
||||||
from stem import SocketError
|
from stem import SocketError
|
||||||
|
|
||||||
|
@ -14,12 +14,19 @@ def test_get_platform_returns_platform_system():
|
|||||||
onionshare.platform.system = lambda: 'Sega Saturn'
|
onionshare.platform.system = lambda: 'Sega Saturn'
|
||||||
assert get_platform() == 'Sega Saturn'
|
assert get_platform() == 'Sega Saturn'
|
||||||
|
|
||||||
|
def test_tails_appends_to_path():
|
||||||
|
"adds '/../tails/lib' to the path when running on Tails"
|
||||||
|
original_path = sys.path
|
||||||
|
onionshare.platform.system = lambda: 'Tails'
|
||||||
|
append_lib_on_tails()
|
||||||
|
assert sys.path[-1][-13:] == '/../tails/lib'
|
||||||
|
|
||||||
def test_get_hidden_service_dir_windows_with_temp():
|
def test_get_hidden_service_dir_windows_with_temp():
|
||||||
"""
|
"""
|
||||||
get_hidden_service_dir() uses a temporary directory from the
|
get_hidden_service_dir() uses a temporary directory from the
|
||||||
Windows environment when defined
|
Windows environment when defined
|
||||||
"""
|
"""
|
||||||
onionshare.get_platform = lambda: 'Windows'
|
onionshare.platform.system = lambda: 'Windows'
|
||||||
os.environ['Temp'] = "C:\Internet Explorer\Secrets"
|
os.environ['Temp'] = "C:\Internet Explorer\Secrets"
|
||||||
expected_path = "C:/Internet Explorer/Secrets/onionshare_hidden_service_port"
|
expected_path = "C:/Internet Explorer/Secrets/onionshare_hidden_service_port"
|
||||||
assert get_hidden_service_dir('port') == expected_path
|
assert get_hidden_service_dir('port') == expected_path
|
||||||
@ -37,6 +44,63 @@ def test_get_hidden_service_dir_posix():
|
|||||||
expected_path = "/tmp/onionshare_hidden_service_port"
|
expected_path = "/tmp/onionshare_hidden_service_port"
|
||||||
assert get_hidden_service_dir('port') == expected_path
|
assert get_hidden_service_dir('port') == expected_path
|
||||||
|
|
||||||
|
class MockSubprocess():
|
||||||
|
def __init__(self):
|
||||||
|
self.last_call = None
|
||||||
|
|
||||||
|
def call(self, args):
|
||||||
|
self.last_call = args
|
||||||
|
|
||||||
|
def last_call_args(self):
|
||||||
|
return self.last_call
|
||||||
|
|
||||||
|
def test_tails_open_port():
|
||||||
|
"tails_open_port() calls iptables with ACCEPT arg"
|
||||||
|
onionshare.get_platform = lambda: 'Tails'
|
||||||
|
onionshare.strings = {'punching_a_hole': ''}
|
||||||
|
|
||||||
|
mock_subprocess = MockSubprocess()
|
||||||
|
onionshare.subprocess = mock_subprocess
|
||||||
|
onionshare.tails_open_port('port')
|
||||||
|
|
||||||
|
expected_call = [
|
||||||
|
'/sbin/iptables', '-I', 'OUTPUT',
|
||||||
|
'-o', 'lo', '-p',
|
||||||
|
'tcp', '--dport', 'port', '-j', 'ACCEPT'
|
||||||
|
]
|
||||||
|
actual_call = mock_subprocess.last_call_args()
|
||||||
|
assert actual_call == expected_call
|
||||||
|
|
||||||
|
def test_load_strings_defaults_to_english():
|
||||||
|
"load_strings() loads English by default"
|
||||||
|
locale.getdefaultlocale = lambda: ('en_US', 'UTF-8')
|
||||||
|
load_strings()
|
||||||
|
assert onionshare.strings['calculating_sha1'] == "Calculating SHA1 checksum."
|
||||||
|
|
||||||
|
def test_load_strings_loads_other_languages():
|
||||||
|
"load_strings() loads other languages in different locales"
|
||||||
|
locale.getdefaultlocale = lambda: ('fr_FR', 'UTF-8')
|
||||||
|
load_strings("fr")
|
||||||
|
print onionshare.strings
|
||||||
|
assert onionshare.strings['calculating_sha1'] == "Calculer un hachage SHA-1."
|
||||||
|
|
||||||
|
def test_tails_close_port():
|
||||||
|
"tails_close_port() calls iptables with REJECT arg"
|
||||||
|
onionshare.get_platform = lambda: 'Tails'
|
||||||
|
onionshare.strings = {'closing_hole': ''}
|
||||||
|
|
||||||
|
mock_subprocess = MockSubprocess()
|
||||||
|
onionshare.subprocess = mock_subprocess
|
||||||
|
onionshare.tails_close_port('port')
|
||||||
|
|
||||||
|
expected_call = [
|
||||||
|
'/sbin/iptables', '-I', 'OUTPUT',
|
||||||
|
'-o', 'lo', '-p',
|
||||||
|
'tcp', '--dport', 'port', '-j', 'REJECT'
|
||||||
|
]
|
||||||
|
actual_call = mock_subprocess.last_call_args()
|
||||||
|
assert actual_call == expected_call
|
||||||
|
|
||||||
def test_generate_slug_length():
|
def test_generate_slug_length():
|
||||||
"generates a 32-character slug"
|
"generates a 32-character slug"
|
||||||
assert len(slug) == 32
|
assert len(slug) == 32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user