mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-12 11:22:14 -04:00
Fix tests
This commit is contained in:
parent
9785be0375
commit
15d66c1a6f
7 changed files with 56 additions and 79 deletions
|
@ -7,18 +7,24 @@ from .GuiBaseTest import GuiBaseTest
|
|||
class GuiReceiveTest(GuiBaseTest):
|
||||
def upload_file(self, public_mode, file_to_upload, expected_basename, identical_files_at_once=False):
|
||||
'''Test that we can upload the file'''
|
||||
files = {'file[]': open(file_to_upload, 'rb')}
|
||||
url = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
|
||||
if not public_mode:
|
||||
r = requests.post(url, files=files)
|
||||
else:
|
||||
r = requests.post(url, files=files, auth=requests.auth.HTTPBasicAuth('onionshare', mode.web.password))
|
||||
if identical_files_at_once:
|
||||
# Send a duplicate upload to test for collisions
|
||||
r = requests.post(path, files=files)
|
||||
|
||||
# Wait 2 seconds to make sure the filename, based on timestamp, isn't accidentally reused
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
# Make sure the file is within the last 10 seconds worth of filenames
|
||||
files = {'file[]': open(file_to_upload, 'rb')}
|
||||
url = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
|
||||
if public_mode:
|
||||
r = requests.post(url, files=files)
|
||||
else:
|
||||
r = requests.post(url, files=files, auth=requests.auth.HTTPBasicAuth('onionshare', self.gui.receive_mode.web.password))
|
||||
|
||||
if identical_files_at_once:
|
||||
# Send a duplicate upload to test for collisions
|
||||
r = requests.post(url, files=files)
|
||||
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
# Make sure the file is within the last 10 seconds worth of fileames
|
||||
exists = False
|
||||
now = datetime.now()
|
||||
for i in range(10):
|
||||
|
@ -40,23 +46,23 @@ class GuiReceiveTest(GuiBaseTest):
|
|||
'''Test that we can't upload the file when permissions are wrong, and expected content is shown'''
|
||||
files = {'file[]': open('/tmp/test.txt', 'rb')}
|
||||
url = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
|
||||
if not public_mode:
|
||||
if public_mode:
|
||||
r = requests.post(url, files=files)
|
||||
else:
|
||||
r = requests.post(url, files=files, auth=requests.auth.HTTPBasicAuth('onionshare', mode.web.password))
|
||||
r = requests.post(url, files=files, auth=requests.auth.HTTPBasicAuth('onionshare', self.gui.receive_mode.web.password))
|
||||
|
||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
||||
self.assertTrue('Error uploading, please inform the OnionShare user' in response.text)
|
||||
self.assertTrue('Error uploading, please inform the OnionShare user' in r.text)
|
||||
|
||||
def upload_dir_permissions(self, mode=0o755):
|
||||
'''Manipulate the permissions on the upload dir in between tests'''
|
||||
os.chmod('/tmp/OnionShare', mode)
|
||||
|
||||
def try_public_paths_in_non_public_mode(self):
|
||||
def try_without_auth_in_non_public_mode(self):
|
||||
r = requests.post('http://127.0.0.1:{}/upload'.format(self.gui.app.port))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
self.assertEqual(r.status_code, 401)
|
||||
r = requests.get('http://127.0.0.1:{}/close'.format(self.gui.app.port))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
self.assertEqual(r.status_code, 401)
|
||||
|
||||
def uploading_zero_files_shouldnt_change_ui(self, mode, public_mode):
|
||||
'''If you submit the receive mode form without selecting any files, the UI shouldn't get updated'''
|
||||
|
@ -68,7 +74,7 @@ class GuiReceiveTest(GuiBaseTest):
|
|||
before_number_of_history_items = len(mode.history.item_list.items)
|
||||
|
||||
# Click submit without including any files a few times
|
||||
if not public_mode:
|
||||
if public_mode:
|
||||
r = requests.post(url, files={})
|
||||
r = requests.post(url, files={})
|
||||
r = requests.post(url, files={})
|
||||
|
@ -102,11 +108,11 @@ class GuiReceiveTest(GuiBaseTest):
|
|||
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)
|
||||
|
||||
def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown):
|
||||
def run_all_receive_mode_tests(self, public_mode):
|
||||
'''Upload files in receive mode and stop the share'''
|
||||
self.run_all_receive_mode_setup_tests(public_mode)
|
||||
if not public_mode:
|
||||
self.try_public_paths_in_non_public_mode()
|
||||
self.try_without_auth_in_non_public_mode()
|
||||
self.upload_file(public_mode, '/tmp/test.txt', 'test.txt')
|
||||
self.history_widgets_present(self.gui.receive_mode)
|
||||
self.counter_incremented(self.gui.receive_mode, 1)
|
||||
|
@ -128,7 +134,7 @@ class GuiReceiveTest(GuiBaseTest):
|
|||
self.server_is_started(self.gui.receive_mode)
|
||||
self.history_indicator(self.gui.receive_mode, public_mode)
|
||||
|
||||
def run_all_receive_mode_unwritable_dir_tests(self, public_mode, receive_allow_receiver_shutdown):
|
||||
def run_all_receive_mode_unwritable_dir_tests(self, public_mode):
|
||||
'''Attempt to upload (unwritable) files in receive mode and stop the share'''
|
||||
self.run_all_receive_mode_setup_tests(public_mode)
|
||||
self.upload_dir_permissions(0o400)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue