diff options
Diffstat (limited to 'desktop')
24 files changed, 226 insertions, 53 deletions
diff --git a/desktop/package/linux/build-appimage.py b/desktop/package/linux/build-appimage.py index 0c64494f..dfaba1b4 100755 --- a/desktop/package/linux/build-appimage.py +++ b/desktop/package/linux/build-appimage.py @@ -43,4 +43,4 @@ def main(): if __name__ == "__main__": - main()
\ No newline at end of file + main() diff --git a/desktop/package/windows/build.py b/desktop/package/windows/build.py index 603b1514..5fc796d4 100644 --- a/desktop/package/windows/build.py +++ b/desktop/package/windows/build.py @@ -211,7 +211,7 @@ def main(): ] print(f"○ Created unsigned installer: {msi_filename}") - print(f"○ Signing installer") + print("○ Signing installer") run( [ "signtool.exe", diff --git a/desktop/scripts/get-tor-osx.py b/desktop/scripts/get-tor-osx.py index f3aa6e7b..76c7a5fe 100755 --- a/desktop/scripts/get-tor-osx.py +++ b/desktop/scripts/get-tor-osx.py @@ -24,7 +24,6 @@ This script downloads a pre-built tor binary to bundle with OnionShare. In order to avoid a Mac gnupg dependency, I manually verify the signature and hard-code the sha256 hash. """ - import inspect import os import sys diff --git a/desktop/scripts/get-tor-windows.py b/desktop/scripts/get-tor-windows.py index 9cb8898c..87080c4a 100644 --- a/desktop/scripts/get-tor-windows.py +++ b/desktop/scripts/get-tor-windows.py @@ -23,7 +23,6 @@ This script downloads a pre-built tor binary to bundle with OnionShare. In order to avoid a Windows gnupg dependency, I manually verify the signature and hard-code the sha256 hash. """ - import inspect import os import sys @@ -75,7 +74,7 @@ def main(): "e", "-y", exe_path, - "Browser\TorBrowser\Tor", + "Browser\\TorBrowser\\Tor", "-o%s" % os.path.join(working_path, "Tor"), ] ).wait() @@ -85,7 +84,7 @@ def main(): "e", "-y", exe_path, - "Browser\TorBrowser\Data\Tor\geoip*", + "Browser\\TorBrowser\\Data\\Tor\\geoip*", "-o%s" % os.path.join(working_path, "Data"), ] ).wait() diff --git a/desktop/src/onionshare/__init__.py b/desktop/src/onionshare/__init__.py index 1c69ffa5..8276dae4 100644 --- a/desktop/src/onionshare/__init__.py +++ b/desktop/src/onionshare/__init__.py @@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. from __future__ import division import os import sys -import platform import argparse import signal import json diff --git a/desktop/src/onionshare/gui_common.py b/desktop/src/onionshare/gui_common.py index 7703f7a8..1a44a128 100644 --- a/desktop/src/onionshare/gui_common.py +++ b/desktop/src/onionshare/gui_common.py @@ -353,6 +353,10 @@ class GuiCommon: color: #666666; font-size: 11px; }""", + "receive_message_button": """ + QPushButton { + padding: 5px 10px; + }""", # Settings dialog "settings_version": """ QLabel { diff --git a/desktop/src/onionshare/resources/images/open_message.png b/desktop/src/onionshare/resources/images/open_message.png Binary files differnew file mode 100644 index 00000000..6712ecf9 --- /dev/null +++ b/desktop/src/onionshare/resources/images/open_message.png diff --git a/desktop/src/onionshare/resources/locale/en.json b/desktop/src/onionshare/resources/locale/en.json index 7c74736a..8a69142c 100644 --- a/desktop/src/onionshare/resources/locale/en.json +++ b/desktop/src/onionshare/resources/locale/en.json @@ -175,6 +175,8 @@ "mode_settings_share_autostop_sharing_checkbox": "Stop sharing after files have been sent (uncheck to allow downloading individual files)", "mode_settings_receive_data_dir_label": "Save files to", "mode_settings_receive_data_dir_browse_button": "Browse", + "mode_settings_receive_disable_text_checkbox": "Disable submitting text", + "mode_settings_receive_disable_files_checkbox": "Disable uploading files", "mode_settings_receive_webhook_url_checkbox": "Use notification webhook", "mode_settings_website_disable_csp_checkbox": "Don't send Content Security Policy header (allows your website to use third-party resources)", "gui_all_modes_transfer_finished_range": "Transferred {} - {}", @@ -194,5 +196,6 @@ "gui_rendezvous_cleanup": "Waiting for Tor circuits to close to be sure your files have successfully transferred.\n\nThis might take a few minutes.", "gui_rendezvous_cleanup_quit_early": "Quit Early", "error_port_not_available": "OnionShare port not available", + "history_receive_read_message_button": "Read Message", "error_tor_protocol_error": "There was an error with Tor: {}" -} +}
\ No newline at end of file diff --git a/desktop/src/onionshare/tab/mode/__init__.py b/desktop/src/onionshare/tab/mode/__init__.py index 0cbccc51..567dc123 100644 --- a/desktop/src/onionshare/tab/mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/__init__.py @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from PySide2 import QtCore, QtWidgets, QtGui +from PySide2 import QtCore, QtWidgets from onionshare_cli.common import AutoStopTimer @@ -379,7 +379,7 @@ class Mode(QtWidgets.QWidget): if self.server_status.status != ServerStatus.STATUS_STOPPED: try: self.web.stop(self.app.port) - except: + except Exception: # Probably we had no port to begin with (Onion service didn't start) pass self.app.cleanup() @@ -447,12 +447,24 @@ class Mode(QtWidgets.QWidget): """ pass + def handle_request_upload_includes_message(self, event): + """ + Handle REQUEST_UPLOAD_INCLUDES_MESSAGE event. + """ + pass + def handle_request_upload_file_renamed(self, event): """ Handle REQUEST_UPLOAD_FILE_RENAMED event. """ pass + def handle_request_upload_message(self, event): + """ + Handle REQUEST_UPLOAD_MESSAGE event. + """ + pass + def handle_request_upload_set_dir(self, event): """ Handle REQUEST_UPLOAD_SET_DIR event. diff --git a/desktop/src/onionshare/tab/mode/chat_mode/__init__.py b/desktop/src/onionshare/tab/mode/chat_mode/__init__.py index 44a6d240..7f32aebb 100644 --- a/desktop/src/onionshare/tab/mode/chat_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/chat_mode/__init__.py @@ -18,14 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ -import os -import random -import string - from PySide2 import QtCore, QtWidgets, QtGui -from onionshare_cli.onion import * -from onionshare_cli.common import Common from onionshare_cli.web import Web from .. import Mode diff --git a/desktop/src/onionshare/tab/mode/history.py b/desktop/src/onionshare/tab/mode/history.py index 45e37c75..795b0cd9 100644 --- a/desktop/src/onionshare/tab/mode/history.py +++ b/desktop/src/onionshare/tab/mode/history.py @@ -253,7 +253,7 @@ class ReceiveHistoryItemFile(QtWidgets.QWidget): try: # If nautilus is available, open it subprocess.Popen(["xdg-open", self.dir]) - except: + except Exception: Alert( self.common, strings._("gui_open_folder_error").format(abs_filename), @@ -268,6 +268,60 @@ class ReceiveHistoryItemFile(QtWidgets.QWidget): subprocess.Popen(["explorer", f"/select,{abs_filename}"]) +class ReceiveHistoryItemMessage(QtWidgets.QWidget): + def __init__( + self, + common, + ): + super(ReceiveHistoryItemMessage, self).__init__() + self.common = common + self.filename = None + + # Read message button + message_pixmap = QtGui.QPixmap.fromImage( + QtGui.QImage(GuiCommon.get_resource_path("images/open_message.png")) + ) + message_icon = QtGui.QIcon(message_pixmap) + self.message_button = QtWidgets.QPushButton( + strings._("history_receive_read_message_button") + ) + self.message_button.setStyleSheet(self.common.gui.css["receive_message_button"]) + self.message_button.clicked.connect(self.open_message) + self.message_button.setIcon(message_icon) + self.message_button.setIconSize(message_pixmap.rect().size()) + + # Layouts + layout = QtWidgets.QHBoxLayout() + layout.addWidget(self.message_button) + layout.addStretch() + self.setLayout(layout) + + self.hide() + + def set_filename(self, new_filename): + self.filename = new_filename + self.show() + + def open_message(self): + """ + Open the message in the operating system's default text editor + """ + self.common.log("ReceiveHistoryItemMessage", "open_message", self.filename) + + # Linux + if self.common.platform == "Linux" or self.common.platform == "BSD": + # If nautilus is available, open it + subprocess.Popen(["xdg-open", self.filename]) + + # macOS + elif self.common.platform == "Darwin": + subprocess.call(["open", self.filename]) + + # Windows + elif self.common.platform == "Windows": + subprocess.Popen(["notepad", self.filename]) + + class ReceiveHistoryItem(HistoryItem): def __init__(self, common, id, content_length): super(ReceiveHistoryItem, self).__init__() @@ -277,6 +331,12 @@ class ReceiveHistoryItem(HistoryItem): self.started = datetime.now() self.status = HistoryItem.STATUS_STARTED + self.common.log( + "ReceiveHistoryItem", + "__init__", + f"id={self.id} content_length={self.content_length}", + ) + # Label self.label = QtWidgets.QLabel( strings._("gui_all_modes_transfer_started").format( @@ -295,6 +355,9 @@ class ReceiveHistoryItem(HistoryItem): self.common.gui.css["downloads_uploads_progress_bar"] ) + # The message widget, if a message was included + self.message = ReceiveHistoryItemMessage(self.common) + # This layout contains file widgets self.files_layout = QtWidgets.QVBoxLayout() self.files_layout.setContentsMargins(0, 0, 0, 0) @@ -305,6 +368,7 @@ class ReceiveHistoryItem(HistoryItem): # Layout layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label) + layout.addWidget(self.message) layout.addWidget(self.progress_bar) layout.addWidget(files_widget) layout.addStretch() @@ -313,6 +377,9 @@ class ReceiveHistoryItem(HistoryItem): # We're also making a dictionary of file widgets, to make them easier to access self.files = {} + def includes_message(self, message_filename): + self.message.set_filename(message_filename) + def update(self, data): """ Using the progress from Web, update the progress bar and file size labels @@ -560,6 +627,13 @@ class HistoryItemList(QtWidgets.QScrollArea): if id in self.items: self.items[id].cancel() + def includes_message(self, id, message_filename): + """ + Show message button for receive mode + """ + if id in self.items: + self.items[id].includes_message(message_filename) + def reset(self): """ Reset all items, emptying the list. Override this method. @@ -653,7 +727,7 @@ class History(QtWidgets.QWidget): """ Add a new item. """ - self.common.log("History", "add", f"id: {id}, item: {item}") + self.common.log("History", "add", f"id: {id}") # Hide empty, show not empty self.empty.hide() @@ -674,6 +748,12 @@ class History(QtWidgets.QWidget): """ self.item_list.cancel(id) + def includes_message(self, id, message_filename): + """ + Show the message button + """ + self.item_list.includes_message(id, message_filename) + def reset(self): """ Reset all items. diff --git a/desktop/src/onionshare/tab/mode/mode_settings_widget.py b/desktop/src/onionshare/tab/mode/mode_settings_widget.py index ef59f37e..98a6a01a 100644 --- a/desktop/src/onionshare/tab/mode/mode_settings_widget.py +++ b/desktop/src/onionshare/tab/mode/mode_settings_widget.py @@ -234,7 +234,7 @@ class ModeSettingsWidget(QtWidgets.QWidget): self.tab.change_title.emit( self.tab.tab_id, strings._("gui_tab_name_chat") ) - elif self.tab_mode == None: + elif self.tab_mode is None: pass else: title = self.title_lineedit.text() diff --git a/desktop/src/onionshare/tab/mode/receive_mode/__init__.py b/desktop/src/onionshare/tab/mode/receive_mode/__init__.py index b309d476..4dd2980c 100644 --- a/desktop/src/onionshare/tab/mode/receive_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/receive_mode/__init__.py @@ -78,6 +78,25 @@ class ReceiveMode(Mode): data_dir_layout.addWidget(data_dir_button) self.mode_settings_widget.mode_specific_layout.addLayout(data_dir_layout) + # Disable text or files + self.disable_text_checkbox = self.settings.get("receive", "disable_files") + self.disable_text_checkbox = QtWidgets.QCheckBox() + self.disable_text_checkbox.clicked.connect(self.disable_text_checkbox_clicked) + self.disable_text_checkbox.setText( + strings._("mode_settings_receive_disable_text_checkbox") + ) + self.disable_files_checkbox = self.settings.get("receive", "disable_files") + self.disable_files_checkbox = QtWidgets.QCheckBox() + self.disable_files_checkbox.clicked.connect(self.disable_files_checkbox_clicked) + self.disable_files_checkbox.setText( + strings._("mode_settings_receive_disable_files_checkbox") + ) + disable_layout = QtWidgets.QHBoxLayout() + disable_layout.addWidget(self.disable_text_checkbox) + disable_layout.addWidget(self.disable_files_checkbox) + disable_layout.addStretch() + self.mode_settings_widget.mode_specific_layout.addLayout(disable_layout) + # Webhook URL webhook_url = self.settings.get("receive", "webhook_url") self.webhook_url_checkbox = QtWidgets.QCheckBox() @@ -217,6 +236,16 @@ class ReceiveMode(Mode): self.data_dir_lineedit.setText(selected_dir) self.settings.set("receive", "data_dir", selected_dir) + def disable_text_checkbox_clicked(self): + self.settings.set( + "receive", "disable_text", self.disable_text_checkbox.isChecked() + ) + + def disable_files_checkbox_clicked(self): + self.settings.set( + "receive", "disable_files", self.disable_files_checkbox.isChecked() + ) + def webhook_url_checkbox_clicked(self): if self.webhook_url_checkbox.isChecked(): if self.settings.get("receive", "webhook_url"): @@ -312,8 +341,11 @@ class ReceiveMode(Mode): Handle REQUEST_STARTED event. """ item = ReceiveHistoryItem( - self.common, event["data"]["id"], event["data"]["content_length"] + self.common, + event["data"]["id"], + event["data"]["content_length"], ) + self.history.add(event["data"]["id"], item) self.toggle_history.update_indicator(True) self.history.in_progress_count += 1 @@ -333,6 +365,12 @@ class ReceiveMode(Mode): {"action": "progress", "progress": event["data"]["progress"]}, ) + def handle_request_upload_includes_message(self, event): + """ + Handle REQUEST_UPLOAD_INCLUDES_MESSAGE event. + """ + self.history.includes_message(event["data"]["id"], event["data"]["filename"]) + def handle_request_upload_file_renamed(self, event): """ Handle REQUEST_UPLOAD_FILE_RENAMED event. diff --git a/desktop/src/onionshare/tab/mode/share_mode/__init__.py b/desktop/src/onionshare/tab/mode/share_mode/__init__.py index 05038e20..676d34af 100644 --- a/desktop/src/onionshare/tab/mode/share_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/share_mode/__init__.py @@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import os from PySide2 import QtCore, QtWidgets, QtGui -from onionshare_cli.onion import * from onionshare_cli.common import Common from onionshare_cli.web import Web @@ -30,7 +29,7 @@ from .. import Mode from ..file_selection import FileSelection from ..history import History, ToggleHistory, ShareHistoryItem from .... import strings -from ....widgets import Alert, MinimumWidthWidget +from ....widgets import MinimumWidthWidget from ....gui_common import GuiCommon diff --git a/desktop/src/onionshare/tab/mode/share_mode/threads.py b/desktop/src/onionshare/tab/mode/share_mode/threads.py index 6f5c44ea..74d5099a 100644 --- a/desktop/src/onionshare/tab/mode/share_mode/threads.py +++ b/desktop/src/onionshare/tab/mode/share_mode/threads.py @@ -36,7 +36,7 @@ class CompressThread(QtCore.QThread): # prepare files to share def set_processed_size(self, x): - if self.mode._zip_progress_bar != None: + if self.mode._zip_progress_bar is not None: self.mode._zip_progress_bar.update_processed_size_signal.emit(x) def run(self): diff --git a/desktop/src/onionshare/tab/mode/website_mode/__init__.py b/desktop/src/onionshare/tab/mode/website_mode/__init__.py index f7cfa758..10caff51 100644 --- a/desktop/src/onionshare/tab/mode/website_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/website_mode/__init__.py @@ -19,12 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import os -import random -import string from PySide2 import QtCore, QtWidgets, QtGui -from onionshare_cli.onion import * from onionshare_cli.common import Common from onionshare_cli.web import Web @@ -32,7 +29,7 @@ from .. import Mode from ..file_selection import FileSelection from ..history import History, ToggleHistory from .... import strings -from ....widgets import Alert, MinimumWidthWidget +from ....widgets import MinimumWidthWidget from ....gui_common import GuiCommon diff --git a/desktop/src/onionshare/tab/server_status.py b/desktop/src/onionshare/tab/server_status.py index d8266820..7ca1af09 100644 --- a/desktop/src/onionshare/tab/server_status.py +++ b/desktop/src/onionshare/tab/server_status.py @@ -161,7 +161,7 @@ class ServerStatus(QtWidgets.QWidget): self.url.setText(wrapped_onion_url) else: self.url.setText(self.get_url()) - except: + except Exception: pass def show_url(self): diff --git a/desktop/src/onionshare/tab/tab.py b/desktop/src/onionshare/tab/tab.py index 2d4e164c..3d88ded5 100644 --- a/desktop/src/onionshare/tab/tab.py +++ b/desktop/src/onionshare/tab/tab.py @@ -540,6 +540,9 @@ class Tab(QtWidgets.QWidget): elif event["type"] == Web.REQUEST_CANCELED: mode.handle_request_canceled(event) + elif event["type"] == Web.REQUEST_UPLOAD_INCLUDES_MESSAGE: + mode.handle_request_upload_includes_message(event) + elif event["type"] == Web.REQUEST_UPLOAD_FILE_RENAMED: mode.handle_request_upload_file_renamed(event) diff --git a/desktop/src/onionshare/threads.py b/desktop/src/onionshare/threads.py index 504591f6..c9a3dba4 100644 --- a/desktop/src/onionshare/threads.py +++ b/desktop/src/onionshare/threads.py @@ -252,7 +252,7 @@ class EventHandlerThread(QtCore.QThread): "EventHandler", "run", f"invalid event type: {obj}" ) - except: + except Exception: pass if self.should_quit: diff --git a/desktop/src/onionshare/tor_connection_dialog.py b/desktop/src/onionshare/tor_connection_dialog.py index c3644f8b..b5c2f61c 100644 --- a/desktop/src/onionshare/tor_connection_dialog.py +++ b/desktop/src/onionshare/tor_connection_dialog.py @@ -166,7 +166,7 @@ class TorConnectionThread(QtCore.QThread): else: self.canceled_connecting_to_tor.emit() - except BundledTorCanceled as e: + except BundledTorCanceled: self.common.log( "TorConnectionThread", "run", "caught exception: BundledTorCanceled" ) diff --git a/desktop/src/onionshare/update_checker.py b/desktop/src/onionshare/update_checker.py index 43c83828..08755e6e 100644 --- a/desktop/src/onionshare/update_checker.py +++ b/desktop/src/onionshare/update_checker.py @@ -19,7 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ from PySide2 import QtCore -import datetime, re +import datetime +import re import socks from distutils.version import LooseVersion as Version diff --git a/desktop/src/setup.py b/desktop/src/setup.py index c2c91d28..82a5f98a 100644 --- a/desktop/src/setup.py +++ b/desktop/src/setup.py @@ -25,7 +25,12 @@ version = "2.3.1" setuptools.setup( name="onionshare", version=version, - description="OnionShare lets you securely and anonymously send and receive files. It works by starting a web server, making it accessible as a Tor onion service, and generating an unguessable web address so others can download files from you, or upload files to you. It does _not_ require setting up a separate server or using a third party file-sharing service.", + description=( + "OnionShare lets you securely and anonymously send and receive files. It works by starting a web " + "server, making it accessible as a Tor onion service, and generating an unguessable web address so " + "others can download files from you, or upload files to you. It does _not_ require setting up a " + "separate server or using a third party file-sharing service." + ), author="Micah Lee", author_email="micah@micahflee.com", maintainer="Micah Lee", diff --git a/desktop/tests/conftest.py b/desktop/tests/conftest.py index a043af0c..b17aa45c 100644 --- a/desktop/tests/conftest.py +++ b/desktop/tests/conftest.py @@ -1,20 +1,21 @@ import sys - -# Force tests to look for resources in the source code tree -sys.onionshare_dev_mode = True - -# Let OnionShare know the tests are running, to avoid colliding with settings files -sys.onionshare_test_mode = True - import os import shutil import tempfile from datetime import datetime, timedelta import pytest - from PySide2 import QtTest +from onionshare_cli import common, web, settings + + +# Force tests to look for resources in the source code tree +sys.onionshare_dev_mode = True + +# Let OnionShare know the tests are running, to avoid colliding with settings files +sys.onionshare_test_mode = True + @staticmethod def qWait(t, qtapp): @@ -36,9 +37,6 @@ sys.path.insert( ), ) -from onionshare_cli import common, web, settings - - # The temporary directory for CLI tests test_temp_dir = None @@ -69,7 +67,7 @@ def temp_dir(): @pytest.fixture def temp_dir_1024(temp_dir): - """ Create a temporary directory that has a single file of a + """Create a temporary directory that has a single file of a particular size (1024 bytes). """ @@ -83,7 +81,7 @@ def temp_dir_1024(temp_dir): # pytest > 2.9 only needs @pytest.fixture @pytest.yield_fixture def temp_dir_1024_delete(temp_dir): - """ Create a temporary directory that has a single file of a + """Create a temporary directory that has a single file of a particular size (1024 bytes). The temporary directory (including the file inside) will be deleted after fixture usage. """ @@ -97,7 +95,7 @@ def temp_dir_1024_delete(temp_dir): @pytest.fixture def temp_file_1024(temp_dir): - """ Create a temporary file of a particular size (1024 bytes). """ + """Create a temporary file of a particular size (1024 bytes).""" with tempfile.NamedTemporaryFile(delete=False, dir=temp_dir) as tmp_file: tmp_file.write(b"*" * 1024) @@ -141,7 +139,7 @@ def default_zw(): tmp_dir = os.path.dirname(zw.zip_filename) try: shutil.rmtree(tmp_dir, ignore_errors=True) - except: + except Exception: pass diff --git a/desktop/tests/test_gui_receive.py b/desktop/tests/test_gui_receive.py index 848b2f11..6e14ae67 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) |