More test coverage, particularly of Receive Mode

This commit is contained in:
Miguel Jacq 2018-10-17 15:21:04 +11:00
parent b826528603
commit a093d41102
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
8 changed files with 63 additions and 18 deletions

View File

@ -29,7 +29,7 @@ class GuiBaseTest(object):
# Create a test dir and files # Create a test dir and files
if not os.path.exists('/tmp/testdir'): if not os.path.exists('/tmp/testdir'):
testdir = os.mkdir('/tmp/testdir') testdir = os.mkdir('/tmp/testdir')
testfile = open('/tmp/testdir/test.txt', 'w') testfile = open('/tmp/testdir/test', 'w')
testfile.write('onionshare') testfile.write('onionshare')
testfile.close() testfile.close()

View File

@ -4,9 +4,9 @@ from PyQt5 import QtCore, QtTest
from .GuiBaseTest import GuiBaseTest from .GuiBaseTest import GuiBaseTest
class GuiReceiveTest(GuiBaseTest): class GuiReceiveTest(GuiBaseTest):
def upload_file(self, public_mode, expected_file): def upload_file(self, public_mode, file_to_upload, expected_file):
'''Test that we can upload the file''' '''Test that we can upload the file'''
files = {'file[]': open('/tmp/test.txt', 'rb')} files = {'file[]': open(file_to_upload, 'rb')}
if not public_mode: if not public_mode:
path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug) path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug)
else: else:
@ -31,6 +31,12 @@ class GuiReceiveTest(GuiBaseTest):
'''Manipulate the permissions on the upload dir in between tests''' '''Manipulate the permissions on the upload dir in between tests'''
os.chmod('/tmp/OnionShare', mode) os.chmod('/tmp/OnionShare', mode)
def try_public_paths_in_non_public_mode(self):
response = requests.post('http://127.0.0.1:{}/upload'.format(self.gui.app.port))
self.assertEqual(response.status_code, 404)
response = requests.get('http://127.0.0.1:{}/close'.format(self.gui.app.port))
self.assertEqual(response.status_code, 404)
def run_receive_mode_sender_closed_tests(self, public_mode): def run_receive_mode_sender_closed_tests(self, public_mode):
'''Test that the share can be stopped by the sender in receive mode''' '''Test that the share can be stopped by the sender in receive mode'''
if not public_mode: if not public_mode:
@ -65,11 +71,17 @@ class GuiReceiveTest(GuiBaseTest):
def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown):
'''Upload files in receive mode and stop the share''' '''Upload files in receive mode and stop the share'''
self.run_all_receive_mode_setup_tests(public_mode) self.run_all_receive_mode_setup_tests(public_mode)
self.upload_file(public_mode, '/tmp/OnionShare/test.txt') if not public_mode:
self.try_public_paths_in_non_public_mode()
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt')
self.history_widgets_present(self.gui.receive_mode) self.history_widgets_present(self.gui.receive_mode)
self.counter_incremented(self.gui.receive_mode, 1) self.counter_incremented(self.gui.receive_mode, 1)
self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt') self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt')
self.counter_incremented(self.gui.receive_mode, 2) self.counter_incremented(self.gui.receive_mode, 2)
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test')
self.counter_incremented(self.gui.receive_mode, 3)
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2')
self.counter_incremented(self.gui.receive_mode, 4)
self.history_indicator(self.gui.receive_mode, public_mode) self.history_indicator(self.gui.receive_mode, public_mode)
self.server_is_stopped(self.gui.receive_mode, False) self.server_is_stopped(self.gui.receive_mode, False)
self.web_server_is_stopped() self.web_server_is_stopped()

View File

@ -5,13 +5,13 @@ from .TorGuiBaseTest import TorGuiBaseTest
class TorGuiReceiveTest(TorGuiBaseTest): class TorGuiReceiveTest(TorGuiBaseTest):
def upload_file(self, public_mode, expected_file): def upload_file(self, public_mode, file_to_upload, expected_file):
'''Test that we can upload the file''' '''Test that we can upload the file'''
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
session = requests.session() session = requests.session()
session.proxies = {} session.proxies = {}
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port) session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
files = {'file[]': open('/tmp/test.txt', 'rb')} files = {'file[]': open(file_to_upload, 'rb')}
if not public_mode: if not public_mode:
path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug) path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug)
else: else:
@ -40,11 +40,15 @@ class TorGuiReceiveTest(TorGuiBaseTest):
self.have_copy_url_button(self.gui.receive_mode, public_mode) self.have_copy_url_button(self.gui.receive_mode, public_mode)
self.server_status_indicator_says_started(self.gui.receive_mode) self.server_status_indicator_says_started(self.gui.receive_mode)
self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode)
self.upload_file(public_mode, '/tmp/OnionShare/test.txt') self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt')
self.history_widgets_present(self.gui.receive_mode) self.history_widgets_present(self.gui.receive_mode)
self.counter_incremented(self.gui.receive_mode, 1) self.counter_incremented(self.gui.receive_mode, 1)
self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt') self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt')
self.counter_incremented(self.gui.receive_mode, 2) self.counter_incremented(self.gui.receive_mode, 2)
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test')
self.counter_incremented(self.gui.receive_mode, 3)
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2')
self.counter_incremented(self.gui.receive_mode, 4)
self.history_indicator(self.gui.receive_mode, public_mode) self.history_indicator(self.gui.receive_mode, public_mode)
self.server_is_stopped(self.gui.receive_mode, False) self.server_is_stopped(self.gui.receive_mode, False)
self.web_server_is_stopped() self.web_server_is_stopped()

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import unittest
from .GuiReceiveTest import GuiReceiveTest
class LocalReceivePublicModeUnwritableTest(unittest.TestCase, GuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
"receive_allow_receiver_shutdown": True
}
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceivePublicModeUnwritableTest')
@classmethod
def tearDownClass(cls):
GuiReceiveTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_receive_mode_unwritable_dir_tests(True, True)
if __name__ == "__main__":
unittest.main()

View File

@ -3,13 +3,13 @@ import unittest
from .GuiReceiveTest import GuiReceiveTest from .GuiReceiveTest import GuiReceiveTest
class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): class LocalReceiveModeSenderClosedTest(unittest.TestCase, GuiReceiveTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"receive_allow_receiver_shutdown": True "receive_allow_receiver_shutdown": True
} }
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeSenderClosedTest')
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):

View File

@ -3,13 +3,13 @@ import unittest
from .GuiReceiveTest import GuiReceiveTest from .GuiReceiveTest import GuiReceiveTest
class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): class LocalReceiveModeUnwritableTest(unittest.TestCase, GuiReceiveTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"receive_allow_receiver_shutdown": True "receive_allow_receiver_shutdown": True
} }
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeUnwritableTest')
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):

View File

@ -11,7 +11,7 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest):
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"no_bridges": False, "no_bridges": False,
"tor_bridges_use_obfs4": True, "tor_bridges_use_custom_bridges": "Bridge 1.2.3.4:56 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 5.6.7.8:910 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 11.12.13.14:1516 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n",
} }
cls.gui = SettingsGuiBaseTest.set_up(test_settings, 'settings') cls.gui = SettingsGuiBaseTest.set_up(test_settings, 'settings')
@ -97,8 +97,12 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest):
self.assertTrue(self.gui.connection_type_bundled_radio.isChecked()) self.assertTrue(self.gui.connection_type_bundled_radio.isChecked())
# bridge options are shown # bridge options are shown
self.assertTrue(self.gui.connection_type_bridges_radio_group.isVisible()) self.assertTrue(self.gui.connection_type_bridges_radio_group.isVisible())
# bridges are set to obfs4 # bridges are set to custom
self.assertFalse(self.gui.tor_bridges_no_bridges_radio.isChecked()) self.assertFalse(self.gui.tor_bridges_no_bridges_radio.isChecked())
self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked())
# switch to obfs4
QtTest.QTest.mouseClick(self.gui.tor_bridges_use_obfs4_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_obfs4_radio.height()/2))
self.assertTrue(self.gui.tor_bridges_use_obfs4_radio.isChecked()) self.assertTrue(self.gui.tor_bridges_use_obfs4_radio.isChecked())
# custom bridges are hidden # custom bridges are hidden
@ -143,10 +147,11 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest):
# re-enable bundled mode # re-enable bundled mode
QtTest.QTest.mouseClick(self.gui.connection_type_bundled_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_bundled_radio.height()/2)) QtTest.QTest.mouseClick(self.gui.connection_type_bundled_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_bundled_radio.height()/2))
# set some custom bridges # go back to custom bridges
QtTest.QTest.mouseClick(self.gui.tor_bridges_use_custom_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_custom_radio.height()/2)) QtTest.QTest.mouseClick(self.gui.tor_bridges_use_custom_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_custom_radio.height()/2))
self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked()) self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked())
self.assertTrue(self.gui.tor_bridges_use_custom_textbox.isVisible()) self.assertTrue(self.gui.tor_bridges_use_custom_textbox.isVisible())
self.assertFalse(self.gui.tor_bridges_use_obfs4_radio.isChecked())
self.gui.tor_bridges_use_custom_textbox.setPlainText('94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\n148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\n93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3') self.gui.tor_bridges_use_custom_textbox.setPlainText('94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\n148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\n93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3')
# Test that the Settings Dialog can save the settings and close itself # Test that the Settings Dialog can save the settings and close itself

View File

@ -3,12 +3,12 @@ import unittest
from .GuiShareTest import GuiShareTest from .GuiShareTest import GuiShareTest
class LocalShareModeTest(unittest.TestCase, GuiShareTest): class LocalShareModeLargeDownloadTest(unittest.TestCase, GuiShareTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
} }
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeLargeDownloadTest')
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):