From b2a7b0c929f4f142a4f8b2c4ca541b2a88d2815d Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 16 Oct 2018 13:01:44 +1100 Subject: [PATCH] More coverage such as 404 ratelimit, large file tests. Standardise some method naming conventions and other fixes/cleanup --- tests/GuiBaseTest.py | 80 +++++++++++---- tests/GuiReceiveTest.py | 65 ++++++++++-- tests/GuiShareTest.py | 99 ++++++++++++------- tests/TorGuiBaseTest.py | 31 ++++-- tests/TorGuiReceiveTest.py | 14 ++- tests/TorGuiShareTest.py | 31 +++++- ...re_404_public_mode_skips_ratelimit_test.py | 21 ++++ ..._onionshare_404_triggers_ratelimit_test.py | 20 ++++ ...onshare_receive_mode_sender_closed_test.py | 20 ++++ ...ocal_onionshare_receive_mode_timer_test.py | 20 ++++ ...ceive_mode_upload_non_writable_dir_test.py | 19 ++++ ...re_receive_mode_upload_public_mode_test.py | 1 - ...cal_onionshare_receive_mode_upload_test.py | 1 - ...re_share_mode_download_public_mode_test.py | 1 - ...hare_share_mode_download_stay_open_test.py | 1 - ...cal_onionshare_share_mode_download_test.py | 1 - ...ionshare_share_mode_large_download_test.py | 18 ++++ ...onshare_share_mode_slug_persistent_test.py | 1 - .../local_onionshare_share_mode_timer_test.py | 1 - ...onshare_790_cancel_on_second_share_test.py | 2 +- 20 files changed, 360 insertions(+), 87 deletions(-) create mode 100644 tests/local_onionshare_404_public_mode_skips_ratelimit_test.py create mode 100644 tests/local_onionshare_404_triggers_ratelimit_test.py create mode 100644 tests/local_onionshare_receive_mode_sender_closed_test.py create mode 100644 tests/local_onionshare_receive_mode_timer_test.py create mode 100644 tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py create mode 100644 tests/local_onionshare_share_mode_large_download_test.py diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index 79543468..e2f194db 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -26,6 +26,13 @@ class GuiBaseTest(object): testfile.write('onionshare') testfile.close() + # 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.write('onionshare') + testfile.close() + common = Common() common.settings = Settings(common) common.define_css() @@ -46,14 +53,17 @@ class GuiBaseTest(object): web = Web(common, False, True) open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) - gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], '/tmp/{}.json'.format(settings_filename), True) + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/{}.json'.format(settings_filename), True) return gui @staticmethod def tear_down(): + '''Clean up after tests''' try: os.remove('/tmp/test.txt') + os.remove('/tmp/largefile') shutil.rmtree('/tmp/OnionShare') + shutil.rmtree('/tmp/testdir') except: pass @@ -72,6 +82,11 @@ class GuiBaseTest(object): '''Test that the settings button is visible''' self.assertTrue(self.gui.settings_button.isVisible()) + + def settings_button_is_hidden(self): + '''Test that the settings button is hidden when the server starts''' + self.assertFalse(self.gui.settings_button.isVisible()) + def server_status_bar_is_visible(self): '''Test that the status bar is visible''' @@ -152,22 +167,17 @@ class GuiBaseTest(object): def server_status_indicator_says_starting(self, mode): '''Test that the Server Status indicator shows we are Starting''' - self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) + self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) - def settings_button_is_hidden(self): - '''Test that the settings button is hidden when the server starts''' - self.assertFalse(self.gui.settings_button.isVisible()) - - - def a_server_is_started(self, mode): + def server_is_started(self, mode, startup_time=2000): '''Test that the server has started''' - QtTest.QTest.qWait(2000) + QtTest.QTest.qWait(startup_time) # Should now be in SERVER_STARTED state self.assertEqual(mode.server_status.status, 2) - def a_web_server_is_running(self): + def web_server_is_running(self): '''Test that the web server has started''' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -187,17 +197,24 @@ class GuiBaseTest(object): self.assertTrue(mode.server_status.url_description.isVisible()) - def have_copy_url_button(self, mode): - '''Test that the Copy URL button is shown''' + def have_copy_url_button(self, mode, public_mode): + '''Test that the Copy URL button is shown and that the clipboard is correct''' self.assertTrue(mode.server_status.copy_url_button.isVisible()) + QtTest.QTest.mouseClick(mode.server_status.copy_url_button, QtCore.Qt.LeftButton) + clipboard = self.gui.qtapp.clipboard() + if public_mode: + self.assertEqual(clipboard.text(), 'http://127.0.0.1:{}'.format(self.gui.app.port)) + else: + self.assertEqual(clipboard.text(), 'http://127.0.0.1:{}/{}'.format(self.gui.app.port, mode.server_status.web.slug)) + def server_status_indicator_says_started(self, mode): '''Test that the Server Status indicator shows we are started''' if type(mode) == ReceiveMode: - self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started')) + self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started')) if type(mode) == ShareMode: - self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_started')) + self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_started')) def web_page(self, mode, string, public_mode): @@ -237,17 +254,17 @@ class GuiBaseTest(object): def counter_incremented(self, mode, count): '''Test that the counter has incremented''' - self.assertEquals(mode.history.completed_count, count) + self.assertEqual(mode.history.completed_count, count) def server_is_stopped(self, mode, stay_open): '''Test that the server stops when we click Stop''' if type(mode) == ReceiveMode or (type(mode) == ShareMode and stay_open): QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton) - self.assertEquals(mode.server_status.status, 0) + self.assertEqual(mode.server_status.status, 0) - def web_service_is_stopped(self): + def web_server_is_stopped(self): '''Test that the web server also stopped''' QtTest.QTest.qWait(2000) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -259,12 +276,35 @@ class GuiBaseTest(object): def server_status_indicator_says_closed(self, mode, stay_open): '''Test that the Server Status indicator shows we closed''' if type(mode) == ReceiveMode: - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) + self.assertEqual(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) if type(mode) == ShareMode: if stay_open: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped')) + self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped')) else: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically')) + self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically')) + + + # Auto-stop timer tests + def set_timeout(self, mode, timeout): + '''Test that the timeout can be set''' + timer = QtCore.QDateTime.currentDateTime().addSecs(timeout) + mode.server_status.shutdown_timeout.setDateTime(timer) + self.assertTrue(mode.server_status.shutdown_timeout.dateTime(), timer) + + + def timeout_widget_hidden(self, mode): + '''Test that the timeout widget is hidden when share has started''' + self.assertFalse(mode.server_status.shutdown_timeout_container.isVisible()) + + + def server_timed_out(self, mode, wait): + '''Test that the server has timed out after the timer ran out''' + QtTest.QTest.qWait(wait) + # We should have timed out now + self.assertEqual(mode.server_status.status, 0) + + + # 'Grouped' tests follow from here def run_all_common_setup_tests(self): self.gui_loaded() diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py index 1fa5c4dc..84d6a55a 100644 --- a/tests/GuiReceiveTest.py +++ b/tests/GuiReceiveTest.py @@ -15,7 +15,39 @@ class GuiReceiveTest(GuiBaseTest): QtTest.QTest.qWait(2000) self.assertTrue(os.path.isfile(expected_file)) - def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + def upload_file_should_fail(self, public_mode, expected_file): + '''Test that we can't upload the file when permissions are wrong, and expected content is shown''' + files = {'file[]': open('/tmp/test.txt', 'rb')} + if not public_mode: + path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug) + else: + path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port) + response = requests.post(path, files=files) + + # A nasty hack to avoid the Alert dialog that blocks the rest of the test + self.gui.qtapp.exit() + self.assertTrue('Error uploading, please inform the OnionShare user' in response.text) + + def upload_dir_permissions(self, mode=0o755): + '''Manipulate the permissions on the upload dir in between tests''' + os.chmod('/tmp/OnionShare', mode) + + 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: + path = 'http://127.0.0.1:{}/{}/close'.format(self.gui.app.port, self.gui.receive_mode.web.slug) + else: + path = 'http://127.0.0.1:{}/close'.format(self.gui.app.port) + response = requests.post(path) + self.server_is_stopped(self.gui.receive_mode, False) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.receive_mode, False) + + + # 'Grouped' tests follow from here + + def run_all_receive_mode_setup_tests(self, public_mode): + '''Set up a share in Receive mode and start it''' self.click_mode(self.gui.receive_mode) self.history_is_not_visible(self.gui.receive_mode) self.click_toggle_history(self.gui.receive_mode) @@ -23,13 +55,17 @@ class GuiReceiveTest(GuiBaseTest): self.server_working_on_start_button_pressed(self.gui.receive_mode) self.server_status_indicator_says_starting(self.gui.receive_mode) self.settings_button_is_hidden() - self.a_server_is_started(self.gui.receive_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.receive_mode) + self.web_server_is_running() self.have_a_slug(self.gui.receive_mode, public_mode) self.url_description_shown(self.gui.receive_mode) - self.have_copy_url_button(self.gui.receive_mode) + 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) + + 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') self.history_widgets_present(self.gui.receive_mode) self.counter_incremented(self.gui.receive_mode, 1) @@ -37,9 +73,26 @@ class GuiReceiveTest(GuiBaseTest): self.counter_incremented(self.gui.receive_mode, 2) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() self.server_status_indicator_says_closed(self.gui.receive_mode, False) self.server_working_on_start_button_pressed(self.gui.receive_mode) - self.a_server_is_started(self.gui.receive_mode) + self.server_is_started(self.gui.receive_mode) self.history_indicator(self.gui.receive_mode, public_mode) + def run_all_receive_mode_unwritable_dir_tests(self, public_mode, receive_allow_receiver_shutdown): + '''Attempt to upload (unwritable) files in receive mode and stop the share''' + self.run_all_receive_mode_setup_tests(public_mode) + self.upload_dir_permissions(0o400) + self.upload_file_should_fail(public_mode, '/tmp/OnionShare/test.txt') + self.server_is_stopped(self.gui.receive_mode, True) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.receive_mode, False) + self.upload_dir_permissions(0o755) + + def run_all_receive_mode_timer_tests(self, public_mode): + """Auto-stop timer tests in receive mode""" + self.run_all_receive_mode_setup_tests(public_mode) + self.set_timeout(self.gui.receive_mode, 5) + self.timeout_widget_hidden(self.gui.receive_mode) + self.server_timed_out(self.gui.receive_mode, 15000) + self.web_server_is_stopped() diff --git a/tests/GuiShareTest.py b/tests/GuiShareTest.py index 34149dec..4f2f58e7 100644 --- a/tests/GuiShareTest.py +++ b/tests/GuiShareTest.py @@ -1,29 +1,11 @@ +import os +import requests import socks import zipfile from PyQt5 import QtCore, QtTest from .GuiBaseTest import GuiBaseTest class GuiShareTest(GuiBaseTest): - # Auto-stop timer tests - - def set_timeout(self, mode, timeout): - '''Test that the timeout can be set''' - timer = QtCore.QDateTime.currentDateTime().addSecs(timeout) - mode.server_status.shutdown_timeout.setDateTime(timer) - self.assertTrue(mode.server_status.shutdown_timeout.dateTime(), timer) - - - def timeout_widget_hidden(self, mode): - '''Test that the timeout widget is hidden when share has started''' - self.assertFalse(mode.server_status.shutdown_timeout_container.isVisible()) - - - def server_timed_out(self, mode, wait): - '''Test that the server has timed out after the timer ran out''' - QtTest.QTest.qWait(wait) - # We should have timed out now - self.assertEqual(mode.server_status.status, 0) - # Persistence tests def have_same_slug(self, slug): '''Test that we have the same slug''' @@ -31,19 +13,26 @@ class GuiShareTest(GuiBaseTest): # Share-specific tests - def file_selection_widget_has_a_file(self): - '''Test that the number of files in the list is 1''' - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 1) + def file_selection_widget_has_files(self): + '''Test that the number of items in the list is 2''' + self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) - def deleting_only_file_hides_delete_button(self): + def deleting_all_files_hides_delete_button(self): '''Test that clicking on the file item shows the delete button. Test that deleting the only item in the list hides the delete button''' rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0)) QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center()) # Delete button should be visible self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) - # Click delete, and since there's no more files, the delete button should be hidden + # Click delete, delete button should still be visible since we have one more file QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton) + + rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0)) + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center()) + self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton) + + # No more files, the delete button should be hidden self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) @@ -60,7 +49,15 @@ class GuiShareTest(GuiBaseTest): self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/test.txt') self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) + + def add_large_file(self): + '''Add a large file to the share''' + size = 1024*1024*155 + with open('/tmp/large_file', 'wb') as fout: + fout.write(os.urandom(size)) + self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/large_file') + def add_delete_buttons_hidden(self): '''Test that the add and delete buttons are hidden when the server starts''' self.assertFalse(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) @@ -95,35 +92,56 @@ class GuiShareTest(GuiBaseTest): QtTest.QTest.qWait(2000) self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8')) - + def hit_404(self, public_mode): + '''Test that the server stops after too many 404s, or doesn't when in public_mode''' + bogus_path = '/gimme' + url = "http://127.0.0.1:{}/{}".format(self.gui.app.port, bogus_path) + + for _ in range(20): + r = requests.get(url) + + # A nasty hack to avoid the Alert dialog that blocks the rest of the test + if not public_mode: + self.gui.qtapp.exit() + + # In public mode, we should still be running (no rate-limiting) + if public_mode: + self.web_server_is_running() + # In non-public mode, we should be shut down (rate-limiting) + else: + self.web_server_is_stopped() + + def add_button_visible(self): '''Test that the add button should be visible''' self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) + # 'Grouped' tests follow from here + def run_all_share_mode_setup_tests(self): """Tests in share mode prior to starting a share""" self.click_mode(self.gui.share_mode) - self.file_selection_widget_has_a_file() + self.file_selection_widget_has_files() self.history_is_not_visible(self.gui.share_mode) self.click_toggle_history(self.gui.share_mode) self.history_is_visible(self.gui.share_mode) - self.deleting_only_file_hides_delete_button() + self.deleting_all_files_hides_delete_button() self.add_a_file_and_delete_using_its_delete_widget() self.file_selection_widget_readd_files() - def run_all_share_mode_started_tests(self, public_mode): + def run_all_share_mode_started_tests(self, public_mode, startup_time=2000): """Tests in share mode after starting a share""" self.server_working_on_start_button_pressed(self.gui.share_mode) self.server_status_indicator_says_starting(self.gui.share_mode) self.add_delete_buttons_hidden() self.settings_button_is_hidden() - self.a_server_is_started(self.gui.share_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.share_mode, startup_time) + self.web_server_is_running() self.have_a_slug(self.gui.share_mode, public_mode) self.url_description_shown(self.gui.share_mode) - self.have_copy_url_button(self.gui.share_mode) + self.have_copy_url_button(self.gui.share_mode, public_mode) self.server_status_indicator_says_started(self.gui.share_mode) @@ -133,11 +151,11 @@ class GuiShareTest(GuiBaseTest): self.download_share(public_mode) self.history_widgets_present(self.gui.share_mode) self.server_is_stopped(self.gui.share_mode, stay_open) - self.web_service_is_stopped() + self.web_server_is_stopped() self.server_status_indicator_says_closed(self.gui.share_mode, stay_open) self.add_button_visible() self.server_working_on_start_button_pressed(self.gui.share_mode) - self.a_server_is_started(self.gui.share_mode) + self.server_is_started(self.gui.share_mode) self.history_indicator(self.gui.share_mode, public_mode) @@ -148,6 +166,17 @@ class GuiShareTest(GuiBaseTest): self.run_all_share_mode_download_tests(public_mode, stay_open) + def run_all_large_file_tests(self, public_mode, stay_open): + """Same as above but with a larger file""" + self.run_all_share_mode_setup_tests() + self.add_large_file() + self.run_all_share_mode_started_tests(public_mode, startup_time=15000) + self.assertTrue(self.gui.share_mode.filesize_warning.isVisible()) + self.server_is_stopped(self.gui.share_mode, stay_open) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.share_mode, stay_open) + + def run_all_share_mode_persistent_tests(self, public_mode, stay_open): """Same as end-to-end share tests but also test the slug is the same on multiple shared""" self.run_all_share_mode_setup_tests() @@ -164,5 +193,5 @@ class GuiShareTest(GuiBaseTest): self.run_all_share_mode_started_tests(public_mode) self.timeout_widget_hidden(self.gui.share_mode) self.server_timed_out(self.gui.share_mode, 10000) - self.web_service_is_stopped() + self.web_server_is_stopped() diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index 2fadfab7..aee05096 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -1,4 +1,5 @@ import json +import os import requests import socks @@ -24,6 +25,13 @@ class TorGuiBaseTest(GuiBaseTest): testfile.write('onionshare') testfile.close() + # 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.write('onionshare') + testfile.close() + common = Common() common.settings = Settings(common) common.define_css() @@ -45,7 +53,7 @@ class TorGuiBaseTest(GuiBaseTest): web = Web(common, False, False) open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) - gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], '/tmp/{}.json'.format(settings_filename), False) + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/{}.json'.format(settings_filename), False) return gui def history_indicator(self, mode, public_mode): @@ -91,12 +99,6 @@ class TorGuiBaseTest(GuiBaseTest): QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton) self.assertFalse(mode.toggle_history.indicator_label.isVisible()) - def a_server_is_started(self, mode): - '''Test that the server has started (overriding from local tests to wait for longer)''' - QtTest.QTest.qWait(45000) - # Should now be in SERVER_STARTED state - self.assertEqual(mode.server_status.status, 2) - def have_an_onion_service(self): '''Test that we have a valid Onion URL''' self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion') @@ -127,6 +129,17 @@ class TorGuiBaseTest(GuiBaseTest): self.assertTrue(string in f.read()) f.close() + def have_copy_url_button(self, mode, public_mode): + '''Test that the Copy URL button is shown and that the clipboard is correct''' + self.assertTrue(mode.server_status.copy_url_button.isVisible()) + + QtTest.QTest.mouseClick(mode.server_status.copy_url_button, QtCore.Qt.LeftButton) + clipboard = self.gui.qtapp.clipboard() + if public_mode: + self.assertEqual(clipboard.text(), 'http://{}'.format(self.gui.app.onion_host)) + else: + self.assertEqual(clipboard.text(), 'http://{}/{}'.format(self.gui.app.onion_host, mode.server_status.web.slug)) + def cancel_the_share(self, mode): '''Test that we can cancel this share before it's started up ''' self.server_working_on_start_button_pressed(self.gui.share_mode) @@ -138,13 +151,15 @@ class TorGuiBaseTest(GuiBaseTest): QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton) self.assertEqual(mode.server_status.status, 0) self.server_is_stopped(self.gui.share_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() # Stealth tests def copy_have_hidserv_auth_button(self, mode): '''Test that the Copy HidservAuth button is shown''' self.assertTrue(mode.server_status.copy_hidservauth_button.isVisible()) + clipboard = self.gui.qtapp.clipboard() + self.assertRegex(clipboard.text(), r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host) def hidserv_auth_string(self): '''Test the validity of the HidservAuth string''' diff --git a/tests/TorGuiReceiveTest.py b/tests/TorGuiReceiveTest.py index 67b6a811..3c380b8a 100644 --- a/tests/TorGuiReceiveTest.py +++ b/tests/TorGuiReceiveTest.py @@ -20,7 +20,11 @@ class TorGuiReceiveTest(TorGuiBaseTest): QtTest.QTest.qWait(4000) self.assertTrue(os.path.isfile(expected_file)) + + # 'Grouped' tests follow from here + def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + '''Run a full suite of tests in Receive mode''' self.click_mode(self.gui.receive_mode) self.history_is_not_visible(self.gui.receive_mode) self.click_toggle_history(self.gui.receive_mode) @@ -28,12 +32,12 @@ class TorGuiReceiveTest(TorGuiBaseTest): self.server_working_on_start_button_pressed(self.gui.receive_mode) self.server_status_indicator_says_starting(self.gui.receive_mode) self.settings_button_is_hidden() - self.a_server_is_started(self.gui.receive_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.receive_mode, startup_time=45000) + self.web_server_is_running() self.have_an_onion_service() self.have_a_slug(self.gui.receive_mode, public_mode) self.url_description_shown(self.gui.receive_mode) - self.have_copy_url_button(self.gui.receive_mode) + 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') @@ -43,9 +47,9 @@ class TorGuiReceiveTest(TorGuiBaseTest): self.counter_incremented(self.gui.receive_mode, 2) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() self.server_status_indicator_says_closed(self.gui.receive_mode, False) self.server_working_on_start_button_pressed(self.gui.receive_mode) - self.a_server_is_started(self.gui.receive_mode) + self.server_is_started(self.gui.receive_mode, startup_time=45000) self.history_indicator(self.gui.receive_mode, public_mode) diff --git a/tests/TorGuiShareTest.py b/tests/TorGuiShareTest.py index aa622b4f..ff8d0bb7 100644 --- a/tests/TorGuiShareTest.py +++ b/tests/TorGuiShareTest.py @@ -6,6 +6,7 @@ from .GuiShareTest import GuiShareTest class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): def download_share(self, public_mode): + '''Test downloading a share''' # Set up connecting to the onion (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() session = requests.session() @@ -27,27 +28,46 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): file_to_write.close() zip = zipfile.ZipFile('/tmp/download.zip') QtTest.QTest.qWait(4000) - self.assertEquals('onionshare', zip.read('test.txt').decode('utf-8')) + self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8')) + # Persistence tests def have_same_onion(self, onion): '''Test that we have the same onion''' self.assertEqual(self.gui.app.onion_host, onion) + + # 'Grouped' tests follow from here + def run_all_share_mode_started_tests(self, public_mode): """Tests in share mode after starting a share""" self.server_working_on_start_button_pressed(self.gui.share_mode) self.server_status_indicator_says_starting(self.gui.share_mode) self.add_delete_buttons_hidden() self.settings_button_is_hidden() - self.a_server_is_started(self.gui.share_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.share_mode, startup_time=45000) + self.web_server_is_running() self.have_an_onion_service() self.have_a_slug(self.gui.share_mode, public_mode) self.url_description_shown(self.gui.share_mode) - self.have_copy_url_button(self.gui.share_mode) + self.have_copy_url_button(self.gui.share_mode, public_mode) self.server_status_indicator_says_started(self.gui.share_mode) + + def run_all_share_mode_download_tests(self, public_mode, stay_open): + """Tests in share mode after downloading a share""" + self.web_page(self.gui.share_mode, 'Total size', public_mode) + self.download_share(public_mode) + self.history_widgets_present(self.gui.share_mode) + self.server_is_stopped(self.gui.share_mode, stay_open) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.share_mode, stay_open) + self.add_button_visible() + self.server_working_on_start_button_pressed(self.gui.share_mode) + self.server_is_started(self.gui.share_mode, startup_time=45000) + self.history_indicator(self.gui.share_mode, public_mode) + + def run_all_share_mode_persistent_tests(self, public_mode, stay_open): """Same as end-to-end share tests but also test the slug is the same on multiple shared""" self.run_all_share_mode_setup_tests() @@ -57,6 +77,7 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): self.run_all_share_mode_download_tests(public_mode, stay_open) self.have_same_onion(onion) self.have_same_slug(slug) + def run_all_share_mode_timer_tests(self, public_mode): """Auto-stop timer tests in share mode""" @@ -65,5 +86,5 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): self.run_all_share_mode_started_tests(public_mode) self.timeout_widget_hidden(self.gui.share_mode) self.server_timed_out(self.gui.share_mode, 125000) - self.web_service_is_stopped() + self.web_server_is_stopped() diff --git a/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py new file mode 100644 index 00000000..e4e0a03f --- /dev/null +++ b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiShareTest import GuiShareTest + +class Local404PublicModeRateLimitTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": False, + "public_mode": True + } + cls.gui = GuiShareTest.set_up(test_settings, 'Local404PublicModeRateLimitTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_tests(True, True) + self.hit_404(True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_404_triggers_ratelimit_test.py b/tests/local_onionshare_404_triggers_ratelimit_test.py new file mode 100644 index 00000000..ce26eae1 --- /dev/null +++ b/tests/local_onionshare_404_triggers_ratelimit_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiShareTest import GuiShareTest + +class Local404RateLimitTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": False + } + cls.gui = GuiShareTest.set_up(test_settings, 'Local404RateLimitTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_tests(False, True) + self.hit_404(False) + +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 new file mode 100644 index 00000000..6960301a --- /dev/null +++ b/tests/local_onionshare_receive_mode_sender_closed_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "receive_allow_receiver_shutdown": True + } + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_receive_mode_tests(False, True) + self.run_receive_mode_sender_closed_tests(False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_receive_mode_timer_test.py b/tests/local_onionshare_receive_mode_timer_test.py new file mode 100644 index 00000000..1784ba94 --- /dev/null +++ b/tests/local_onionshare_receive_mode_timer_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class LocalReceiveModeTimerTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": False, + "shutdown_timeout": True, + } + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTimerTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_receive_mode_timer_tests(False) + +if __name__ == "__main__": + unittest.main() 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 new file mode 100644 index 00000000..e33a6461 --- /dev/null +++ b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "receive_allow_receiver_shutdown": True + } + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_receive_mode_unwritable_dir_tests(False, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_receive_mode_upload_public_mode_test.py b/tests/local_onionshare_receive_mode_upload_public_mode_test.py index c99fae52..2c7cbd5e 100644 --- a/tests/local_onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/local_onionshare_receive_mode_upload_public_mode_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiReceiveTest import GuiReceiveTest diff --git a/tests/local_onionshare_receive_mode_upload_test.py b/tests/local_onionshare_receive_mode_upload_test.py index dc6c1f06..fb5d36a7 100644 --- a/tests/local_onionshare_receive_mode_upload_test.py +++ b/tests/local_onionshare_receive_mode_upload_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiReceiveTest import GuiReceiveTest diff --git a/tests/local_onionshare_share_mode_download_public_mode_test.py b/tests/local_onionshare_share_mode_download_public_mode_test.py index bfed9443..3b4ad0e8 100644 --- a/tests/local_onionshare_share_mode_download_public_mode_test.py +++ b/tests/local_onionshare_share_mode_download_public_mode_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_download_stay_open_test.py b/tests/local_onionshare_share_mode_download_stay_open_test.py index b68516a2..dfe7f56c 100644 --- a/tests/local_onionshare_share_mode_download_stay_open_test.py +++ b/tests/local_onionshare_share_mode_download_stay_open_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_download_test.py b/tests/local_onionshare_share_mode_download_test.py index a2a16c96..6b6b0bcc 100644 --- a/tests/local_onionshare_share_mode_download_test.py +++ b/tests/local_onionshare_share_mode_download_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_large_download_test.py b/tests/local_onionshare_share_mode_large_download_test.py new file mode 100644 index 00000000..6fe77752 --- /dev/null +++ b/tests/local_onionshare_share_mode_large_download_test.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiShareTest import GuiShareTest + +class LocalShareModeTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_large_file_tests(False, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_share_mode_slug_persistent_test.py b/tests/local_onionshare_share_mode_slug_persistent_test.py index 03285fa1..a28f5a23 100644 --- a/tests/local_onionshare_share_mode_slug_persistent_test.py +++ b/tests/local_onionshare_share_mode_slug_persistent_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_timer_test.py b/tests/local_onionshare_share_mode_timer_test.py index 3d20efc4..9e3b0b5e 100644 --- a/tests/local_onionshare_share_mode_timer_test.py +++ b/tests/local_onionshare_share_mode_timer_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/onionshare_790_cancel_on_second_share_test.py b/tests/onionshare_790_cancel_on_second_share_test.py index 21747d4c..327a8456 100644 --- a/tests/onionshare_790_cancel_on_second_share_test.py +++ b/tests/onionshare_790_cancel_on_second_share_test.py @@ -19,7 +19,7 @@ class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest): self.run_all_share_mode_tests(False, False) self.cancel_the_share(self.gui.share_mode) self.server_is_stopped(self.gui.share_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() if __name__ == "__main__": unittest.main()