mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-25 10:42:58 -03:00
Prevent a scheduled share from starting after the scheduled time has passed. Add a test for this
This commit is contained in:
parent
8889d3d586
commit
00a8b88264
3 changed files with 41 additions and 3 deletions
|
@ -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()
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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()
|
Loading…
Add table
Reference in a new issue