summaryrefslogtreecommitdiff
path: root/desktop/tests/test_gui_receive.py
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/tests/test_gui_receive.py')
-rw-r--r--desktop/tests/test_gui_receive.py73
1 files changed, 67 insertions, 6 deletions
diff --git a/desktop/tests/test_gui_receive.py b/desktop/tests/test_gui_receive.py
index 848b2f11..b523b0fa 100644
--- a/desktop/tests/test_gui_receive.py
+++ b/desktop/tests/test_gui_receive.py
@@ -48,15 +48,15 @@ class TestReceive(GuiBaseTest):
QtTest.QTest.qWait(1000, self.gui.qtapp)
- # Make sure the file is within the last 10 seconds worth of fileames
+ # Make sure the file is within the last 10 seconds worth of filenames
exists = False
now = datetime.now()
for _ in range(10):
date_dir = now.strftime("%Y-%m-%d")
if identical_files_at_once:
- time_dir = now.strftime("%H.%M.%S-1")
+ time_dir = now.strftime("%H%M%S-1")
else:
- time_dir = now.strftime("%H.%M.%S")
+ time_dir = now.strftime("%H%M%S")
receive_mode_dir = os.path.join(
tab.settings.get("receive", "data_dir"), date_dir, time_dir
)
@@ -93,6 +93,47 @@ class TestReceive(GuiBaseTest):
QtCore.QTimer.singleShot(1000, accept_dialog)
self.assertTrue("Error uploading, please inform the OnionShare user" in r.text)
+ def submit_message(self, tab, message):
+ """Test that we can submit a message"""
+
+ # Wait 2 seconds to make sure the filename, based on timestamp, isn't accidentally reused
+ QtTest.QTest.qWait(2000, self.gui.qtapp)
+
+ url = f"http://127.0.0.1:{tab.app.port}/upload"
+ if tab.settings.get("general", "public"):
+ requests.post(url, data={"text": message})
+ else:
+ requests.post(
+ url,
+ data={"text": message},
+ auth=requests.auth.HTTPBasicAuth(
+ "onionshare", tab.get_mode().web.password
+ ),
+ )
+
+ QtTest.QTest.qWait(1000, self.gui.qtapp)
+
+ # Make sure the file is within the last 10 seconds worth of filenames
+ exists = False
+ now = datetime.now()
+ for _ in range(10):
+ date_dir = now.strftime("%Y-%m-%d")
+ time_dir = now.strftime("%H%M%S")
+ expected_filename = os.path.join(
+ tab.settings.get("receive", "data_dir"),
+ date_dir,
+ f"{time_dir}-message.txt",
+ )
+ if os.path.exists(expected_filename):
+ with open(expected_filename) as f:
+ assert f.read() == message
+
+ exists = True
+ break
+ now = now - timedelta(seconds=1)
+
+ self.assertTrue(exists)
+
def try_without_auth_in_non_public_mode(self, tab):
r = requests.post(f"http://127.0.0.1:{tab.app.port}/upload")
self.assertEqual(r.status_code, 401)
@@ -115,10 +156,9 @@ class TestReceive(GuiBaseTest):
self.have_copy_url_button(tab)
self.have_show_qr_code_button(tab)
self.server_status_indicator_says_started(tab)
- self.web_page(tab, "Select the files you want to send, then click")
def run_all_receive_mode_tests(self, tab):
- """Upload files in receive mode and stop the share"""
+ """Submit files and messages in receive mode and stop the share"""
self.run_all_receive_mode_setup_tests(tab)
if not tab.settings.get("general", "public"):
self.try_without_auth_in_non_public_mode(tab)
@@ -131,9 +171,11 @@ class TestReceive(GuiBaseTest):
self.counter_incremented(tab, 3)
self.upload_file(tab, self.tmpfile_test2, "test2.txt")
self.counter_incremented(tab, 4)
+ self.submit_message(tab, "onionshare is an interesting piece of software")
+ self.counter_incremented(tab, 5)
# Test uploading the same file twice at the same time, and make sure no collisions
self.upload_file(tab, self.tmpfile_test, "test.txt", True)
- self.counter_incremented(tab, 6)
+ self.counter_incremented(tab, 7)
self.history_indicator(tab, "2")
self.server_is_stopped(tab)
self.web_server_is_stopped(tab)
@@ -244,3 +286,22 @@ class TestReceive(GuiBaseTest):
self.run_all_upload_non_writable_dir_tests(tab)
self.close_all_tabs()
+
+ def test_405_page_returned_for_invalid_methods(self):
+ """
+ Our custom 405 page should return for invalid methods
+ """
+ tab = self.new_receive_tab()
+
+ tab.get_mode().mode_settings_widget.public_checkbox.click()
+
+ self.run_all_common_setup_tests()
+ self.run_all_receive_mode_setup_tests(tab)
+ self.upload_file(tab, self.tmpfile_test, "test.txt")
+ 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.server_is_stopped(tab)
+ self.web_server_is_stopped(tab)
+ self.server_status_indicator_says_closed(tab)
+ self.close_all_tabs()