2019-11-08 03:20:38 -05:00
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
import tempfile
|
2019-11-08 06:11:30 -05:00
|
|
|
import zipfile
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2022-10-23 08:09:56 -04:00
|
|
|
from PySide6 import QtCore, QtTest
|
2019-11-08 03:20:38 -05:00
|
|
|
|
|
|
|
from .gui_base_test import GuiBaseTest
|
|
|
|
|
|
|
|
|
|
|
|
class TestShare(GuiBaseTest):
|
|
|
|
# Shared test methods
|
|
|
|
|
2020-06-28 16:01:23 -04:00
|
|
|
def removing_all_files_hides_remove_button(self, tab):
|
|
|
|
"""Test that clicking on the file item shows the remove button. Test that removing the only item in the list hides the remove button"""
|
2019-11-08 06:11:30 -05:00
|
|
|
rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.item(0)
|
2019-11-08 03:20:38 -05:00
|
|
|
)
|
|
|
|
QtTest.QTest.mouseClick(
|
2019-11-08 06:11:30 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.viewport(),
|
2019-11-08 03:20:38 -05:00
|
|
|
QtCore.Qt.LeftButton,
|
|
|
|
pos=rect.center(),
|
|
|
|
)
|
2020-06-28 16:01:23 -04:00
|
|
|
# Remove button should be visible
|
2019-11-08 03:20:38 -05:00
|
|
|
self.assertTrue(
|
2020-06-28 16:01:23 -04:00
|
|
|
tab.get_mode().server_status.file_selection.remove_button.isVisible()
|
2019-11-08 03:20:38 -05:00
|
|
|
)
|
2020-06-28 16:01:23 -04:00
|
|
|
# Click remove, remove button should still be visible since we have one more file
|
|
|
|
tab.get_mode().server_status.file_selection.remove_button.click()
|
2019-11-08 06:11:30 -05:00
|
|
|
rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.item(0)
|
2019-11-08 03:20:38 -05:00
|
|
|
)
|
|
|
|
QtTest.QTest.mouseClick(
|
2019-11-08 06:11:30 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.viewport(),
|
2019-11-08 03:20:38 -05:00
|
|
|
QtCore.Qt.LeftButton,
|
|
|
|
pos=rect.center(),
|
|
|
|
)
|
|
|
|
self.assertTrue(
|
2020-06-28 16:01:23 -04:00
|
|
|
tab.get_mode().server_status.file_selection.remove_button.isVisible()
|
2019-11-08 03:20:38 -05:00
|
|
|
)
|
2020-06-28 16:01:23 -04:00
|
|
|
tab.get_mode().server_status.file_selection.remove_button.click()
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2020-06-28 16:01:23 -04:00
|
|
|
# No more files, the remove button should be hidden
|
2019-11-08 03:20:38 -05:00
|
|
|
self.assertFalse(
|
2020-06-28 16:01:23 -04:00
|
|
|
tab.get_mode().server_status.file_selection.remove_button.isVisible()
|
2019-11-08 03:20:38 -05:00
|
|
|
)
|
|
|
|
|
2020-06-28 16:01:23 -04:00
|
|
|
def add_a_file_and_remove_using_its_remove_widget(self, tab):
|
|
|
|
"""Test that we can also remove a file by clicking on its [X] widget"""
|
2019-11-08 09:08:08 -05:00
|
|
|
num_files = tab.get_mode().server_status.file_selection.get_num_files()
|
2019-11-08 06:11:30 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])
|
2019-11-08 07:44:52 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.item(
|
|
|
|
0
|
|
|
|
).item_button.click()
|
2019-11-08 09:08:08 -05:00
|
|
|
self.file_selection_widget_has_files(tab, num_files)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2020-06-28 16:01:23 -04:00
|
|
|
def add_a_file_and_remove_using_remove_all_widget(self, tab):
|
|
|
|
"""Test that we can also remove all files by clicking on the Remove All widget"""
|
2020-05-26 22:56:33 -04:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])
|
2020-06-28 16:01:23 -04:00
|
|
|
tab.get_mode().remove_all_button.click()
|
2020-05-26 22:56:33 -04:00
|
|
|
# Should be no files after clearing all
|
|
|
|
self.file_selection_widget_has_files(tab, 0)
|
|
|
|
|
2019-11-08 06:11:30 -05:00
|
|
|
def file_selection_widget_read_files(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Re-add some files to the list so we can share"""
|
2019-11-08 09:08:08 -05:00
|
|
|
num_files = tab.get_mode().server_status.file_selection.get_num_files()
|
2019-11-08 06:11:30 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])
|
2019-11-08 09:08:08 -05:00
|
|
|
self.file_selection_widget_has_files(tab, num_files + 2)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2019-11-08 06:11:30 -05:00
|
|
|
def download_share(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Test that we can download the share"""
|
2019-11-08 06:11:30 -05:00
|
|
|
url = f"http://127.0.0.1:{tab.app.port}/download"
|
2021-08-27 01:52:29 -04:00
|
|
|
r = requests.get(url)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2020-08-21 18:33:45 -04:00
|
|
|
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
|
|
|
|
tmp_file.write(r.content)
|
|
|
|
tmp_file.close()
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2020-08-21 18:33:45 -04:00
|
|
|
z = zipfile.ZipFile(tmp_file.name)
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(5, self.gui.qtapp)
|
2020-08-21 18:33:45 -04:00
|
|
|
self.assertEqual("onionshare", z.read("test.txt").decode("utf-8"))
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(500, self.gui.qtapp)
|
2019-11-08 11:42:49 -05:00
|
|
|
|
2019-11-08 06:11:30 -05:00
|
|
|
def individual_file_is_viewable_or_not(self, tab):
|
2019-11-08 09:08:08 -05:00
|
|
|
"""
|
|
|
|
Test that an individual file is viewable (when in autostop_sharing is false) or that it
|
|
|
|
isn't (when not in autostop_sharing is true)
|
|
|
|
"""
|
2019-11-08 06:11:30 -05:00
|
|
|
url = f"http://127.0.0.1:{tab.app.port}"
|
|
|
|
download_file_url = f"http://127.0.0.1:{tab.app.port}/test.txt"
|
2021-08-27 01:52:29 -04:00
|
|
|
r = requests.get(url)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2019-11-08 09:08:08 -05:00
|
|
|
if tab.settings.get("share", "autostop_sharing"):
|
|
|
|
self.assertFalse('a href="/test.txt"' in r.text)
|
2021-08-27 01:52:29 -04:00
|
|
|
r = requests.get(download_file_url)
|
2019-11-08 09:08:08 -05:00
|
|
|
self.assertEqual(r.status_code, 404)
|
|
|
|
self.download_share(tab)
|
2019-11-08 03:20:38 -05:00
|
|
|
else:
|
2021-08-28 08:03:16 -04:00
|
|
|
self.assertTrue('a href="/test.txt"' in r.text)
|
2021-08-27 01:52:29 -04:00
|
|
|
r = requests.get(download_file_url)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2020-08-21 19:21:06 -04:00
|
|
|
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
|
2020-08-21 18:33:45 -04:00
|
|
|
tmp_file.write(r.content)
|
2020-08-21 19:21:06 -04:00
|
|
|
tmp_file.close()
|
2019-11-08 09:08:08 -05:00
|
|
|
|
|
|
|
with open(tmp_file.name, "r") as f:
|
|
|
|
self.assertEqual("onionshare", f.read())
|
2020-08-21 19:21:06 -04:00
|
|
|
os.remove(tmp_file.name)
|
2019-11-08 09:08:08 -05:00
|
|
|
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(500, self.gui.qtapp)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2019-11-08 06:59:20 -05:00
|
|
|
def set_autostart_timer(self, tab, timer):
|
2019-11-08 06:11:30 -05:00
|
|
|
"""Test that the timer can be set"""
|
|
|
|
schedule = QtCore.QDateTime.currentDateTime().addSecs(timer)
|
2019-11-08 06:59:20 -05:00
|
|
|
tab.get_mode().mode_settings_widget.autostart_timer_widget.setDateTime(schedule)
|
|
|
|
self.assertTrue(
|
|
|
|
tab.get_mode().mode_settings_widget.autostart_timer_widget.dateTime(),
|
|
|
|
schedule,
|
|
|
|
)
|
2019-11-08 06:11:30 -05:00
|
|
|
|
2019-11-08 07:06:24 -05:00
|
|
|
def autostart_timer_widget_hidden(self, tab):
|
2019-11-08 06:11:30 -05:00
|
|
|
"""Test that the auto-start timer widget is hidden when share has started"""
|
2019-11-08 06:59:20 -05:00
|
|
|
self.assertFalse(
|
|
|
|
tab.get_mode().mode_settings_widget.autostart_timer_widget.isVisible()
|
|
|
|
)
|
2019-11-08 06:11:30 -05:00
|
|
|
|
2019-11-08 07:44:52 -05:00
|
|
|
def scheduled_service_started(self, tab, wait):
|
2019-11-08 06:11:30 -05:00
|
|
|
"""Test that the server has timed out after the timer ran out"""
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(wait, self.gui.qtapp)
|
2019-11-08 06:11:30 -05:00
|
|
|
# We should have started now
|
2019-11-08 06:59:20 -05:00
|
|
|
self.assertEqual(tab.get_mode().server_status.status, 2)
|
2019-11-08 06:11:30 -05:00
|
|
|
|
2019-11-08 07:44:52 -05:00
|
|
|
def cancel_the_share(self, tab):
|
2019-11-08 06:11:30 -05:00
|
|
|
"""Test that we can cancel a share before it's started up """
|
|
|
|
self.server_working_on_start_button_pressed(tab)
|
|
|
|
self.server_status_indicator_says_scheduled(tab)
|
2020-06-28 16:01:23 -04:00
|
|
|
self.add_remove_buttons_hidden(tab)
|
2019-11-08 06:11:30 -05:00
|
|
|
self.mode_settings_widget_is_hidden(tab)
|
|
|
|
self.set_autostart_timer(tab, 10)
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(500, self.gui.qtapp)
|
2019-11-08 06:59:20 -05:00
|
|
|
QtTest.QTest.mousePress(
|
|
|
|
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
|
|
|
)
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(100, self.gui.qtapp)
|
2019-11-08 06:11:30 -05:00
|
|
|
QtTest.QTest.mouseRelease(
|
2019-11-08 06:59:20 -05:00
|
|
|
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
2019-11-08 06:11:30 -05:00
|
|
|
)
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(500, self.gui.qtapp)
|
2020-08-21 18:33:45 -04:00
|
|
|
self.assertEqual(
|
|
|
|
tab.get_mode().server_status.status,
|
|
|
|
tab.get_mode().server_status.STATUS_STOPPED,
|
|
|
|
)
|
2019-11-08 06:11:30 -05:00
|
|
|
self.server_is_stopped(tab)
|
|
|
|
self.web_server_is_stopped(tab)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
|
|
|
# Grouped tests follow from here
|
|
|
|
|
2019-11-08 06:11:30 -05:00
|
|
|
def run_all_share_mode_setup_tests(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Tests in share mode prior to starting a share"""
|
2019-11-08 09:08:08 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(
|
|
|
|
self.tmpfile_test
|
|
|
|
)
|
2019-11-08 06:11:30 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])
|
2019-11-08 09:08:08 -05:00
|
|
|
self.file_selection_widget_has_files(tab, 3)
|
2019-11-08 06:11:30 -05:00
|
|
|
self.history_is_not_visible(tab)
|
|
|
|
self.click_toggle_history(tab)
|
|
|
|
self.history_is_visible(tab)
|
2020-06-28 16:01:23 -04:00
|
|
|
self.removing_all_files_hides_remove_button(tab)
|
|
|
|
self.add_a_file_and_remove_using_its_remove_widget(tab)
|
2019-11-08 06:11:30 -05:00
|
|
|
self.file_selection_widget_read_files(tab)
|
|
|
|
|
|
|
|
def run_all_share_mode_started_tests(self, tab, startup_time=2000):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Tests in share mode after starting a share"""
|
2019-11-08 06:11:30 -05:00
|
|
|
self.server_working_on_start_button_pressed(tab)
|
|
|
|
self.server_status_indicator_says_starting(tab)
|
2020-06-28 16:01:23 -04:00
|
|
|
self.add_remove_buttons_hidden(tab)
|
2019-11-08 06:11:30 -05:00
|
|
|
self.mode_settings_widget_is_hidden(tab)
|
|
|
|
self.server_is_started(tab, startup_time)
|
|
|
|
self.web_server_is_running(tab)
|
|
|
|
self.url_description_shown(tab)
|
2021-08-31 00:17:23 -04:00
|
|
|
self.url_instructions_shown(tab)
|
|
|
|
self.url_shown(tab)
|
2019-11-08 06:11:30 -05:00
|
|
|
self.have_copy_url_button(tab)
|
2021-08-31 00:17:23 -04:00
|
|
|
self.have_show_url_qr_code_button(tab)
|
2021-09-03 17:24:45 -04:00
|
|
|
self.private_key_shown(tab)
|
2021-08-31 00:17:23 -04:00
|
|
|
self.client_auth_instructions_shown(tab)
|
|
|
|
self.have_show_client_auth_qr_code_button(tab)
|
2019-11-08 06:11:30 -05:00
|
|
|
self.server_status_indicator_says_started(tab)
|
|
|
|
|
|
|
|
def run_all_share_mode_download_tests(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Tests in share mode after downloading a share"""
|
2019-11-08 06:11:30 -05:00
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(
|
|
|
|
self.tmpfile_test
|
|
|
|
)
|
|
|
|
self.web_page(tab, "Total size")
|
2021-12-17 01:59:34 -05:00
|
|
|
self.javascript_is_correct_mime_type(tab, "send.js")
|
2019-11-08 06:11:30 -05:00
|
|
|
self.download_share(tab)
|
|
|
|
self.history_widgets_present(tab)
|
|
|
|
self.server_is_stopped(tab)
|
|
|
|
self.web_server_is_stopped(tab)
|
|
|
|
self.server_status_indicator_says_closed(tab)
|
|
|
|
self.add_button_visible(tab)
|
|
|
|
self.server_working_on_start_button_pressed(tab)
|
|
|
|
self.toggle_indicator_is_reset(tab)
|
|
|
|
self.server_is_started(tab)
|
|
|
|
self.history_indicator(tab)
|
|
|
|
|
|
|
|
def run_all_share_mode_individual_file_download_tests(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Tests in share mode after downloading a share"""
|
2019-11-08 06:11:30 -05:00
|
|
|
self.web_page(tab, "Total size")
|
|
|
|
self.individual_file_is_viewable_or_not(tab)
|
|
|
|
self.history_widgets_present(tab)
|
|
|
|
self.server_is_stopped(tab)
|
|
|
|
self.web_server_is_stopped(tab)
|
|
|
|
self.server_status_indicator_says_closed(tab)
|
|
|
|
self.add_button_visible(tab)
|
|
|
|
self.server_working_on_start_button_pressed(tab)
|
|
|
|
self.server_is_started(tab)
|
|
|
|
self.history_indicator(tab)
|
|
|
|
|
|
|
|
def run_all_share_mode_tests(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""End-to-end share tests"""
|
2019-11-08 06:11:30 -05:00
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
|
|
|
self.run_all_share_mode_download_tests(tab)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
2020-05-26 22:56:33 -04:00
|
|
|
def run_all_clear_all_history_button_tests(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Test the Clear All history button"""
|
2019-11-08 06:11:30 -05:00
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
|
|
|
self.individual_file_is_viewable_or_not(tab)
|
|
|
|
self.history_widgets_present(tab)
|
|
|
|
self.clear_all_history_items(tab, 0)
|
|
|
|
self.individual_file_is_viewable_or_not(tab)
|
|
|
|
self.clear_all_history_items(tab, 2)
|
|
|
|
|
2020-06-28 16:01:23 -04:00
|
|
|
def run_all_remove_all_file_selection_button_tests(self, tab):
|
|
|
|
"""Test the Remove All File Selection button"""
|
2020-05-26 22:56:33 -04:00
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
2020-06-28 16:01:23 -04:00
|
|
|
self.add_a_file_and_remove_using_remove_all_widget(tab)
|
2020-05-26 22:56:33 -04:00
|
|
|
|
2019-11-08 06:11:30 -05:00
|
|
|
def run_all_share_mode_individual_file_tests(self, tab):
|
2019-11-08 03:20:38 -05:00
|
|
|
"""Tests in share mode when viewing an individual file"""
|
2019-11-08 06:11:30 -05:00
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
|
|
|
self.run_all_share_mode_individual_file_download_tests(tab)
|
2019-11-08 03:20:38 -05:00
|
|
|
|
|
|
|
# Tests
|
|
|
|
|
2019-11-08 06:59:20 -05:00
|
|
|
def test_autostart_and_autostop_timer_mismatch(self):
|
2019-11-08 07:06:24 -05:00
|
|
|
"""
|
|
|
|
If autostart timer is after autostop timer, a warning should be thrown
|
|
|
|
"""
|
2019-11-08 06:11:30 -05:00
|
|
|
tab = self.new_share_tab()
|
2019-11-08 07:44:52 -05:00
|
|
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
|
|
tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()
|
|
|
|
tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()
|
2019-11-08 06:11:30 -05:00
|
|
|
|
2019-11-08 06:59:20 -05:00
|
|
|
def accept_dialog():
|
|
|
|
window = tab.common.gui.qtapp.activeWindow()
|
|
|
|
if window:
|
|
|
|
window.close()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.set_autostart_timer(tab, 15)
|
|
|
|
self.set_timeout(tab, 5)
|
|
|
|
QtCore.QTimer.singleShot(200, accept_dialog)
|
|
|
|
tab.get_mode().server_status.server_button.click()
|
|
|
|
self.server_is_stopped(tab)
|
2019-11-08 07:06:24 -05:00
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
def test_autostart_timer(self):
|
|
|
|
"""
|
|
|
|
Autostart timer should automatically start
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
2019-11-08 07:44:52 -05:00
|
|
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
|
|
tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()
|
|
|
|
|
2019-11-08 07:06:24 -05:00
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
2019-11-08 07:44:52 -05:00
|
|
|
self.set_autostart_timer(tab, 2)
|
2019-11-08 07:06:24 -05:00
|
|
|
self.server_working_on_start_button_pressed(tab)
|
|
|
|
self.autostart_timer_widget_hidden(tab)
|
|
|
|
self.server_status_indicator_says_scheduled(tab)
|
|
|
|
self.web_server_is_stopped(tab)
|
2019-11-08 07:44:52 -05:00
|
|
|
self.scheduled_service_started(tab, 2200)
|
2019-11-08 07:06:24 -05:00
|
|
|
self.web_server_is_running(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2019-11-08 07:48:38 -05:00
|
|
|
|
|
|
|
def test_autostart_timer_too_short(self):
|
|
|
|
"""
|
|
|
|
Autostart timer should throw a warning if the scheduled time is too soon
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
|
|
tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()
|
|
|
|
|
|
|
|
def accept_dialog():
|
|
|
|
window = tab.common.gui.qtapp.activeWindow()
|
|
|
|
if window:
|
|
|
|
window.close()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
# Set a low timeout
|
|
|
|
self.set_autostart_timer(tab, 2)
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(2200, self.gui.qtapp)
|
2019-11-08 07:48:38 -05:00
|
|
|
QtCore.QTimer.singleShot(200, accept_dialog)
|
|
|
|
tab.get_mode().server_status.server_button.click()
|
|
|
|
self.assertEqual(tab.get_mode().server_status.status, 0)
|
2019-11-08 07:55:05 -05:00
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
def test_autostart_timer_cancel(self):
|
|
|
|
"""
|
|
|
|
Test canceling a scheduled share
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
|
|
tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.cancel_the_share(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2019-11-08 09:08:08 -05:00
|
|
|
|
2020-05-26 22:56:33 -04:00
|
|
|
def test_clear_all_history_button(self):
|
2019-11-08 09:08:08 -05:00
|
|
|
"""
|
2020-05-26 22:56:33 -04:00
|
|
|
Test clearing all history items
|
2019-11-08 09:08:08 -05:00
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().autostop_sharing_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
2020-05-26 22:56:33 -04:00
|
|
|
self.run_all_clear_all_history_button_tests(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
2020-06-28 16:01:23 -04:00
|
|
|
def test_remove_all_file_selection_button(self):
|
2020-05-26 22:56:33 -04:00
|
|
|
"""
|
2020-06-28 16:01:23 -04:00
|
|
|
Test remove all file items at once
|
2020-05-26 22:56:33 -04:00
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
2020-06-28 16:01:23 -04:00
|
|
|
self.run_all_remove_all_file_selection_button_tests(tab)
|
2019-11-08 11:42:49 -05:00
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
def test_public_mode(self):
|
|
|
|
"""
|
|
|
|
Public mode shouldn't have a password
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().mode_settings_widget.public_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_tests(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2019-11-08 11:53:03 -05:00
|
|
|
|
2019-11-08 11:57:25 -05:00
|
|
|
def test_without_autostop_sharing(self):
|
2019-11-08 11:53:03 -05:00
|
|
|
"""
|
2019-11-08 11:57:25 -05:00
|
|
|
Disable autostop sharing after first download
|
2019-11-08 11:53:03 -05:00
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().autostop_sharing_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_tests(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
def test_download(self):
|
|
|
|
"""
|
|
|
|
Test downloading in share mode
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_tests(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2019-11-08 11:57:25 -05:00
|
|
|
|
|
|
|
def test_individual_files_without_autostop_sharing(self):
|
|
|
|
"""
|
|
|
|
Test downloading individual files with autostop sharing disabled
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().autostop_sharing_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_individual_file_tests(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
def test_individual_files(self):
|
|
|
|
"""
|
|
|
|
Test downloading individual files
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_individual_file_tests(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2019-11-08 12:31:22 -05:00
|
|
|
|
|
|
|
def test_large_download(self):
|
|
|
|
"""
|
|
|
|
Test a large download
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(
|
|
|
|
self.tmpfile_large
|
|
|
|
)
|
|
|
|
self.run_all_share_mode_started_tests(tab, startup_time=15000)
|
|
|
|
self.assertTrue(tab.get_mode().filesize_warning.isVisible())
|
|
|
|
self.download_share(tab)
|
|
|
|
self.server_is_stopped(tab)
|
|
|
|
self.web_server_is_stopped(tab)
|
|
|
|
self.server_status_indicator_says_closed(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2019-11-10 13:25:24 -05:00
|
|
|
|
2019-11-10 13:40:23 -05:00
|
|
|
def test_autostop_timer(self):
|
|
|
|
"""
|
|
|
|
Test the autostop timer
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
|
|
tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.set_timeout(tab, 5)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
|
|
|
self.autostop_timer_widget_hidden(tab)
|
|
|
|
self.server_timed_out(tab, 10000)
|
|
|
|
self.web_server_is_stopped(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
def test_autostop_timer_too_short(self):
|
|
|
|
"""
|
|
|
|
Test the autostop timer when the timeout is too short
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
|
|
tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()
|
|
|
|
|
|
|
|
def accept_dialog():
|
|
|
|
window = tab.common.gui.qtapp.activeWindow()
|
|
|
|
if window:
|
|
|
|
window.close()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
# Set a low timeout
|
|
|
|
self.set_timeout(tab, 2)
|
2020-10-14 23:17:08 -04:00
|
|
|
QtTest.QTest.qWait(2100, self.gui.qtapp)
|
2019-11-10 13:40:23 -05:00
|
|
|
QtCore.QTimer.singleShot(2200, accept_dialog)
|
|
|
|
tab.get_mode().server_status.server_button.click()
|
|
|
|
self.assertEqual(tab.get_mode().server_status.status, 0)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
def test_unreadable_file(self):
|
|
|
|
"""
|
|
|
|
Sharing an unreadable file should throw a warning
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
|
|
|
|
def accept_dialog():
|
|
|
|
window = tab.common.gui.qtapp.activeWindow()
|
|
|
|
if window:
|
|
|
|
window.close()
|
|
|
|
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
QtCore.QTimer.singleShot(200, accept_dialog)
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(
|
|
|
|
"/tmp/nonexistent.txt"
|
|
|
|
)
|
|
|
|
self.file_selection_widget_has_files(tab, 3)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2019-11-10 13:56:45 -05:00
|
|
|
|
2021-05-06 01:24:19 -04:00
|
|
|
def test_client_auth(self):
|
|
|
|
"""
|
2021-05-06 04:02:40 -04:00
|
|
|
Test the ClientAuth is received from the backend,
|
|
|
|
that the widget is visible in the UI and that the
|
|
|
|
clipboard contains the ClientAuth string
|
2021-05-06 01:24:19 -04:00
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
|
|
|
self.clientauth_is_visible(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
2021-08-26 19:44:43 -04:00
|
|
|
|
2021-08-27 19:41:31 -04:00
|
|
|
# Now try in public mode
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().mode_settings_widget.public_checkbox.click()
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
|
|
|
self.clientauth_is_not_visible(tab)
|
|
|
|
|
|
|
|
self.close_all_tabs()
|
|
|
|
|
|
|
|
|
2021-05-09 21:23:44 -04:00
|
|
|
def test_405_page_returned_for_invalid_methods(self):
|
|
|
|
"""
|
|
|
|
Our custom 405 page should return for invalid methods
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
|
|
|
|
tab.get_mode().autostop_sharing_checkbox.click()
|
|
|
|
tab.get_mode().mode_settings_widget.public_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
2021-08-26 19:44:43 -04:00
|
|
|
|
2021-05-09 21:23:44 -04:00
|
|
|
url = f"http://127.0.0.1:{tab.app.port}/"
|
|
|
|
self.hit_405(url, expected_resp="OnionShare: 405 Method Not Allowed", data = {'foo':'bar'}, methods = ["put", "post", "delete", "options"])
|
|
|
|
self.history_widgets_present(tab)
|
|
|
|
self.close_all_tabs()
|
2023-05-30 02:23:31 -04:00
|
|
|
|
|
|
|
|
2023-05-30 02:36:58 -04:00
|
|
|
def test_compression(self):
|
2023-05-30 02:23:31 -04:00
|
|
|
"""
|
|
|
|
A file with a compressable mimetype should return a Content-Encoding header
|
|
|
|
with gzip compression enabled.
|
|
|
|
"""
|
|
|
|
tab = self.new_share_tab()
|
|
|
|
tab.get_mode().autostop_sharing_checkbox.click()
|
|
|
|
|
|
|
|
self.run_all_common_setup_tests()
|
|
|
|
self.run_all_share_mode_setup_tests(tab)
|
|
|
|
tab.get_mode().mode_settings_widget.public_checkbox.click()
|
|
|
|
tab.get_mode().remove_all_button.click()
|
|
|
|
tab.get_mode().server_status.file_selection.file_list.add_file(
|
|
|
|
self.tmpfile_test_html
|
|
|
|
)
|
|
|
|
self.run_all_share_mode_started_tests(tab)
|
|
|
|
url = f"http://127.0.0.1:{tab.app.port}/test.html"
|
|
|
|
r = requests.get(url)
|
|
|
|
self.assertTrue("Content-Encoding" in r.headers)
|
|
|
|
self.assertEqual("gzip", r.headers["Content-Encoding"])
|
|
|
|
|
|
|
|
self.server_is_stopped(tab)
|
|
|
|
self.web_server_is_stopped(tab)
|
|
|
|
self.server_status_indicator_says_closed(tab)
|
|
|
|
self.close_all_tabs()
|