summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2019-03-06 16:49:32 +1100
committerMiguel Jacq <mig@mig5.net>2019-03-06 16:49:32 +1100
commit00a8b88264776f232495849c7366240e372f57cd (patch)
treec867270508bc5cee86f974bac18198690509d95b
parent8889d3d5860e5bf35c9dd49bf499f1d3d1399009 (diff)
downloadonionshare-00a8b88264776f232495849c7366240e372f57cd.tar.gz
onionshare-00a8b88264776f232495849c7366240e372f57cd.zip
Prevent a scheduled share from starting after the scheduled time has passed. Add a test for this
-rw-r--r--onionshare_gui/server_status.py10
-rw-r--r--share/locale/en.json1
-rw-r--r--tests/local_onionshare_share_mode_autostart_timer_too_short_test.py33
3 files changed, 41 insertions, 3 deletions
diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py
index 4bd9241b..3ee10f14 100644
--- a/onionshare_gui/server_status.py
+++ b/onionshare_gui/server_status.py
@@ -312,11 +312,16 @@ class ServerStatus(QtWidgets.QWidget):
Toggle starting or stopping the server.
"""
if self.status == self.STATUS_STOPPED:
+ can_start = True
if self.common.settings.get('startup_timer'):
if self.local_only:
self.scheduled_start = self.startup_timer.dateTime().toPyDateTime()
else:
self.scheduled_start = self.startup_timer.dateTime().toPyDateTime().replace(second=0, microsecond=0)
+ # If the timer has actually passed already before the user hit Start, refuse to start the server.
+ if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.scheduled_start:
+ can_start = False
+ Alert(self.common, strings._('gui_server_startup_timer_expired'), QtWidgets.QMessageBox.Warning)
if self.common.settings.get('shutdown_timeout'):
if self.local_only:
self.timeout = self.shutdown_timeout.dateTime().toPyDateTime()
@@ -325,10 +330,9 @@ class ServerStatus(QtWidgets.QWidget):
self.timeout = self.shutdown_timeout.dateTime().toPyDateTime().replace(second=0, microsecond=0)
# If the timeout has actually passed already before the user hit Start, refuse to start the server.
if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.timeout:
+ can_start = False
Alert(self.common, strings._('gui_server_timeout_expired'), QtWidgets.QMessageBox.Warning)
- else:
- self.start_server()
- else:
+ if can_start:
self.start_server()
elif self.status == self.STATUS_STARTED:
self.stop_server()
diff --git a/share/locale/en.json b/share/locale/en.json
index d21052a5..a86341da 100644
--- a/share/locale/en.json
+++ b/share/locale/en.json
@@ -125,6 +125,7 @@
"gui_tor_connection_lost": "Disconnected from Tor.",
"gui_server_started_after_timeout": "The auto-stop timer ran out before the server started.\nPlease make a new share.",
"gui_server_timeout_expired": "The auto-stop timer already ran out.\nPlease update it to start sharing.",
+ "gui_server_startup_timer_expired": "The scheduled time has already passed.\nPlease update it to start sharing.",
"share_via_onionshare": "OnionShare it",
"gui_connect_to_tor_for_onion_settings": "Connect to Tor to see onion service settings",
"gui_use_legacy_v2_onions_checkbox": "Use legacy addresses",
diff --git a/tests/local_onionshare_share_mode_autostart_timer_too_short_test.py b/tests/local_onionshare_share_mode_autostart_timer_too_short_test.py
new file mode 100644
index 00000000..12343478
--- /dev/null
+++ b/tests/local_onionshare_share_mode_autostart_timer_too_short_test.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+import pytest
+import unittest
+from PyQt5 import QtCore, QtTest
+
+from .GuiShareTest import GuiShareTest
+
+class LocalShareModeStartupTimerTooShortTest(unittest.TestCase, GuiShareTest):
+ @classmethod
+ def setUpClass(cls):
+ test_settings = {
+ "public_mode": False,
+ "startup_timer": True,
+ }
+ cls.gui = GuiShareTest.set_up(test_settings)
+
+ @classmethod
+ def tearDownClass(cls):
+ GuiShareTest.tear_down()
+
+ @pytest.mark.gui
+ def test_gui(self):
+ self.run_all_common_setup_tests()
+ self.run_all_share_mode_setup_tests()
+ # Set a low timeout
+ self.set_startup_timer(self.gui.share_mode, 2)
+ QtTest.QTest.qWait(3000)
+ QtCore.QTimer.singleShot(4000, self.accept_dialog)
+ QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
+ self.assertEqual(self.gui.share_mode.server_status.status, 0)
+
+if __name__ == "__main__":
+ unittest.main()