mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-29 01:06:16 -05:00
More test coverage, particularly of Receive Mode
This commit is contained in:
parent
b826528603
commit
a093d41102
@ -29,7 +29,7 @@ class GuiBaseTest(object):
|
||||
# Create a test dir and files
|
||||
if not os.path.exists('/tmp/testdir'):
|
||||
testdir = os.mkdir('/tmp/testdir')
|
||||
testfile = open('/tmp/testdir/test.txt', 'w')
|
||||
testfile = open('/tmp/testdir/test', 'w')
|
||||
testfile.write('onionshare')
|
||||
testfile.close()
|
||||
|
||||
|
@ -4,9 +4,9 @@ from PyQt5 import QtCore, QtTest
|
||||
from .GuiBaseTest import GuiBaseTest
|
||||
|
||||
class GuiReceiveTest(GuiBaseTest):
|
||||
def upload_file(self, public_mode, expected_file):
|
||||
def upload_file(self, public_mode, file_to_upload, expected_file):
|
||||
'''Test that we can upload the file'''
|
||||
files = {'file[]': open('/tmp/test.txt', 'rb')}
|
||||
files = {'file[]': open(file_to_upload, 'rb')}
|
||||
if not public_mode:
|
||||
path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug)
|
||||
else:
|
||||
@ -31,6 +31,12 @@ class GuiReceiveTest(GuiBaseTest):
|
||||
'''Manipulate the permissions on the upload dir in between tests'''
|
||||
os.chmod('/tmp/OnionShare', mode)
|
||||
|
||||
def try_public_paths_in_non_public_mode(self):
|
||||
response = requests.post('http://127.0.0.1:{}/upload'.format(self.gui.app.port))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
response = requests.get('http://127.0.0.1:{}/close'.format(self.gui.app.port))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def run_receive_mode_sender_closed_tests(self, public_mode):
|
||||
'''Test that the share can be stopped by the sender in receive mode'''
|
||||
if not public_mode:
|
||||
@ -65,11 +71,17 @@ class GuiReceiveTest(GuiBaseTest):
|
||||
def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown):
|
||||
'''Upload files in receive mode and stop the share'''
|
||||
self.run_all_receive_mode_setup_tests(public_mode)
|
||||
self.upload_file(public_mode, '/tmp/OnionShare/test.txt')
|
||||
if not public_mode:
|
||||
self.try_public_paths_in_non_public_mode()
|
||||
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt')
|
||||
self.history_widgets_present(self.gui.receive_mode)
|
||||
self.counter_incremented(self.gui.receive_mode, 1)
|
||||
self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt')
|
||||
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt')
|
||||
self.counter_incremented(self.gui.receive_mode, 2)
|
||||
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test')
|
||||
self.counter_incremented(self.gui.receive_mode, 3)
|
||||
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2')
|
||||
self.counter_incremented(self.gui.receive_mode, 4)
|
||||
self.history_indicator(self.gui.receive_mode, public_mode)
|
||||
self.server_is_stopped(self.gui.receive_mode, False)
|
||||
self.web_server_is_stopped()
|
||||
|
@ -5,13 +5,13 @@ from .TorGuiBaseTest import TorGuiBaseTest
|
||||
|
||||
class TorGuiReceiveTest(TorGuiBaseTest):
|
||||
|
||||
def upload_file(self, public_mode, expected_file):
|
||||
def upload_file(self, public_mode, file_to_upload, expected_file):
|
||||
'''Test that we can upload the file'''
|
||||
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
|
||||
session = requests.session()
|
||||
session.proxies = {}
|
||||
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
|
||||
files = {'file[]': open('/tmp/test.txt', 'rb')}
|
||||
files = {'file[]': open(file_to_upload, 'rb')}
|
||||
if not public_mode:
|
||||
path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug)
|
||||
else:
|
||||
@ -40,11 +40,15 @@ class TorGuiReceiveTest(TorGuiBaseTest):
|
||||
self.have_copy_url_button(self.gui.receive_mode, public_mode)
|
||||
self.server_status_indicator_says_started(self.gui.receive_mode)
|
||||
self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode)
|
||||
self.upload_file(public_mode, '/tmp/OnionShare/test.txt')
|
||||
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt')
|
||||
self.history_widgets_present(self.gui.receive_mode)
|
||||
self.counter_incremented(self.gui.receive_mode, 1)
|
||||
self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt')
|
||||
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt')
|
||||
self.counter_incremented(self.gui.receive_mode, 2)
|
||||
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test')
|
||||
self.counter_incremented(self.gui.receive_mode, 3)
|
||||
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2')
|
||||
self.counter_incremented(self.gui.receive_mode, 4)
|
||||
self.history_indicator(self.gui.receive_mode, public_mode)
|
||||
self.server_is_stopped(self.gui.receive_mode, False)
|
||||
self.web_server_is_stopped()
|
||||
|
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
|
||||
from .GuiReceiveTest import GuiReceiveTest
|
||||
|
||||
class LocalReceivePublicModeUnwritableTest(unittest.TestCase, GuiReceiveTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"public_mode": True,
|
||||
"receive_allow_receiver_shutdown": True
|
||||
}
|
||||
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceivePublicModeUnwritableTest')
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
GuiReceiveTest.tear_down()
|
||||
|
||||
def test_gui(self):
|
||||
self.run_all_common_setup_tests()
|
||||
self.run_all_receive_mode_unwritable_dir_tests(True, True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -3,13 +3,13 @@ import unittest
|
||||
|
||||
from .GuiReceiveTest import GuiReceiveTest
|
||||
|
||||
class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest):
|
||||
class LocalReceiveModeSenderClosedTest(unittest.TestCase, GuiReceiveTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"receive_allow_receiver_shutdown": True
|
||||
}
|
||||
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest')
|
||||
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeSenderClosedTest')
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
@ -3,13 +3,13 @@ import unittest
|
||||
|
||||
from .GuiReceiveTest import GuiReceiveTest
|
||||
|
||||
class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest):
|
||||
class LocalReceiveModeUnwritableTest(unittest.TestCase, GuiReceiveTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"receive_allow_receiver_shutdown": True
|
||||
}
|
||||
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest')
|
||||
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeUnwritableTest')
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
@ -11,7 +11,7 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest):
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"no_bridges": False,
|
||||
"tor_bridges_use_obfs4": True,
|
||||
"tor_bridges_use_custom_bridges": "Bridge 1.2.3.4:56 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 5.6.7.8:910 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 11.12.13.14:1516 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n",
|
||||
}
|
||||
cls.gui = SettingsGuiBaseTest.set_up(test_settings, 'settings')
|
||||
|
||||
@ -97,8 +97,12 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest):
|
||||
self.assertTrue(self.gui.connection_type_bundled_radio.isChecked())
|
||||
# bridge options are shown
|
||||
self.assertTrue(self.gui.connection_type_bridges_radio_group.isVisible())
|
||||
# bridges are set to obfs4
|
||||
# bridges are set to custom
|
||||
self.assertFalse(self.gui.tor_bridges_no_bridges_radio.isChecked())
|
||||
self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked())
|
||||
|
||||
# switch to obfs4
|
||||
QtTest.QTest.mouseClick(self.gui.tor_bridges_use_obfs4_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_obfs4_radio.height()/2))
|
||||
self.assertTrue(self.gui.tor_bridges_use_obfs4_radio.isChecked())
|
||||
|
||||
# custom bridges are hidden
|
||||
@ -143,10 +147,11 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest):
|
||||
|
||||
# re-enable bundled mode
|
||||
QtTest.QTest.mouseClick(self.gui.connection_type_bundled_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_bundled_radio.height()/2))
|
||||
# set some custom bridges
|
||||
# go back to custom bridges
|
||||
QtTest.QTest.mouseClick(self.gui.tor_bridges_use_custom_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_custom_radio.height()/2))
|
||||
self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked())
|
||||
self.assertTrue(self.gui.tor_bridges_use_custom_textbox.isVisible())
|
||||
self.assertFalse(self.gui.tor_bridges_use_obfs4_radio.isChecked())
|
||||
self.gui.tor_bridges_use_custom_textbox.setPlainText('94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\n148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\n93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3')
|
||||
|
||||
# Test that the Settings Dialog can save the settings and close itself
|
||||
|
@ -3,12 +3,12 @@ import unittest
|
||||
|
||||
from .GuiShareTest import GuiShareTest
|
||||
|
||||
class LocalShareModeTest(unittest.TestCase, GuiShareTest):
|
||||
class LocalShareModeLargeDownloadTest(unittest.TestCase, GuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
}
|
||||
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest')
|
||||
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeLargeDownloadTest')
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
Loading…
Reference in New Issue
Block a user