diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index 3b7ec4c4..0e570412 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -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() diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py index 0c0cb770..a659a79f 100644 --- a/tests/GuiReceiveTest.py +++ b/tests/GuiReceiveTest.py @@ -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() diff --git a/tests/TorGuiReceiveTest.py b/tests/TorGuiReceiveTest.py index 3c380b8a..a21dd4fc 100644 --- a/tests/TorGuiReceiveTest.py +++ b/tests/TorGuiReceiveTest.py @@ -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() diff --git a/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py new file mode 100644 index 00000000..2bffb4dd --- /dev/null +++ b/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py @@ -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() diff --git a/tests/local_onionshare_receive_mode_sender_closed_test.py b/tests/local_onionshare_receive_mode_sender_closed_test.py index 1f16b5fb..3a0d8617 100644 --- a/tests/local_onionshare_receive_mode_sender_closed_test.py +++ b/tests/local_onionshare_receive_mode_sender_closed_test.py @@ -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): diff --git a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py index ee3a7215..b6f06b08 100644 --- a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py +++ b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py @@ -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): diff --git a/tests/local_onionshare_settings_dialog_test.py b/tests/local_onionshare_settings_dialog_test.py index 64840d7d..a328f53b 100644 --- a/tests/local_onionshare_settings_dialog_test.py +++ b/tests/local_onionshare_settings_dialog_test.py @@ -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 diff --git a/tests/local_onionshare_share_mode_large_download_test.py b/tests/local_onionshare_share_mode_large_download_test.py index b8017b77..5f5de888 100644 --- a/tests/local_onionshare_share_mode_large_download_test.py +++ b/tests/local_onionshare_share_mode_large_download_test.py @@ -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):