Merge branch 'develop' into v3-revisited

This commit is contained in:
Micah Lee 2018-11-18 17:04:20 -08:00
commit eca1f9cc8d
84 changed files with 1859 additions and 3805 deletions

39
.circleci/config.yml Normal file
View File

@ -0,0 +1,39 @@
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
- image: circleci/python:3.6.6
working_directory: ~/repo
steps:
- checkout
- run:
name: install dependencies
command: |
sudo apt-get update && sudo apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy
sudo pip3 install -r install/requirements.txt
sudo pip3 install -r install/requirements-tests.txt
sudo pip3 install pytest-cov flake8
# run tests!
- run:
name: run flake tests
command: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- run:
name: run tests
command: |
xvfb-run pytest --cov=onionshare --cov=onionshare_gui --cov-report=term-missing -vvv tests/

View File

@ -1,24 +0,0 @@
language: python
dist: trusty
sudo: required
python:
- "3.5.3"
- "3.6"
- "3.6-dev"
- "3.7-dev"
- "nightly"
# command to install dependencies
install:
- sudo apt-get update && sudo apt-get install python3-pyqt5
- pip install -r install/requirements.txt
- pip install -r install/requirements-tests.txt
- pip install pytest-cov flake8
before_script:
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# run CLI tests and local GUI tests
script:
- pytest --cov=onionshare tests/
- cd tests_gui_local/ && xvfb-run ./run_unit_tests.sh

View File

@ -149,30 +149,22 @@ OnionShare includes PyTest unit tests. To run the tests, first install some depe
pip3 install -r install/requirements-tests.txt
```
You must have `pytest` in your path point to python 3's pytest. If necessary, you might need to make a symlink, like:
```sh
ln -s /usr/bin/pytest-3 /usr/local/bin/pytest
```
If you'd like to run the CLI-based tests that Travis runs:
Then you can run `pytest` against the `tests/` directory.
```sh
pytest tests/
```
If you would like to run the GUI unit tests in 'local only mode':
If you would like to also run the GUI unit tests in 'tor' mode, start Tor Browser in the background, then run:
```sh
cd tests_gui_local/
./run_unit_tests.sh
```
If you would like to run the GUI unit tests in 'tor' (bundled) mode:
```sh
cd tests_gui_tor/
./run_unit_tests.sh
pytest --runtor tests/
```
Keep in mind that the Tor tests take a lot longer to run than local mode, but they are also more comprehensive.
You can also choose to wrap the tests in `xvfb-run` so that a ton of OnionShare windows don't pop up on your desktop (you may need to install the `xorg-x11-server-Xvfb` package), like this:
```sh
xvfb-run pytest tests/
```

View File

@ -1,6 +1,6 @@
# OnionShare
[![Build Status](https://travis-ci.org/micahflee/onionshare.png)](https://travis-ci.org/micahflee/onionshare)
[![CircleCI](https://circleci.com/gh/micahflee/onionshare.svg?style=svg)](https://circleci.com/gh/micahflee/onionshare)
[OnionShare](https://onionshare.org) lets you securely and anonymously share files of any size. It works by starting a web server, making it accessible as a Tor Onion Service, and generating an unguessable URL to access and download the files. It does _not_ require setting up a separate server or using a third party file-sharing service. You host the files on your own computer and use a Tor Onion Service to make it temporarily accessible over the internet. The receiving user just needs to open the URL in Tor Browser to download the file.
@ -18,5 +18,5 @@ You can set up your development environment to build OnionShare yourself by foll
# Screenshots
![Server Screenshot](/screenshots/server.png)
![Server Screenshot](/screenshots/appdata-server.png)
![Client Screenshot](/screenshots/client.png)

View File

@ -1,14 +0,0 @@
#!/bin/bash
ROOT="$( dirname $(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd ))"
# CLI tests
cd $ROOT
pytest tests/
# Local GUI tests
cd $ROOT/tests_gui_local
./run_unit_tests.sh
# Tor GUI tests
cd $ROOT/tests_gui_tor
./run_unit_tests.sh

View File

@ -1,11 +1,10 @@
atomicwrites==1.2.1
attrs==18.2.0
more-itertools==4.3.0
pluggy==0.6.0
py==1.6.0
pytest==3.4.2
pluggy==0.7.1
py==1.7.0
pytest==3.8.2
pytest-faulthandler==1.5.0
pytest-ordering==0.5
pytest-qt==3.1.0
pytest-qt==3.2.1
six==1.11.0
urllib3==1.23

View File

@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import os, sys, time, argparse, threading
from . import strings
from .common import Common, DownloadsDirErrorCannotCreate, DownloadsDirErrorNotWritable
from .common import Common
from .web import Web
from .onion import *
from .onionshare import OnionShare

View File

@ -32,20 +32,6 @@ import time
from .settings import Settings
class DownloadsDirErrorCannotCreate(Exception):
"""
Error creating the downloads dir (~/OnionShare by default).
"""
pass
class DownloadsDirErrorNotWritable(Exception):
"""
Downloads dir is not writable.
"""
pass
class Common(object):
"""
The Common object is shared amongst all parts of OnionShare.
@ -390,19 +376,6 @@ class Common(object):
}"""
}
def validate_downloads_dir(self):
"""
Validate that downloads_dir exists, and create it if it doesn't
"""
if not os.path.isdir(self.settings.get('downloads_dir')):
try:
os.mkdir(self.settings.get('downloads_dir'), 0o700)
except:
raise DownloadsDirErrorCannotCreate
if not os.access(self.settings.get('downloads_dir'), os.W_OK):
raise DownloadsDirErrorNotWritable
@staticmethod
def random_string(num_bytes, output_len=None):
"""

View File

@ -4,7 +4,6 @@ from datetime import datetime
from flask import Request, request, render_template, make_response, flash, redirect
from werkzeug.utils import secure_filename
from ..common import DownloadsDirErrorCannotCreate, DownloadsDirErrorNotWritable
from .. import strings
@ -59,17 +58,19 @@ class ReceiveModeWeb(object):
"""
Upload files.
"""
# Make sure downloads_dir exists
# Make sure the receive mode dir exists
now = datetime.now()
date_dir = now.strftime("%Y-%m-%d")
time_dir = now.strftime("%H.%M.%S")
receive_mode_dir = os.path.join(self.common.settings.get('downloads_dir'), date_dir, time_dir)
valid = True
try:
self.common.validate_downloads_dir()
except DownloadsDirErrorCannotCreate:
self.web.add_request(self.web.REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE, request.path)
print(strings._('error_cannot_create_downloads_dir').format(self.common.settings.get('downloads_dir')))
valid = False
except DownloadsDirErrorNotWritable:
self.web.add_request(self.web.REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE, request.path)
print(strings._('error_downloads_dir_not_writable').format(self.common.settings.get('downloads_dir')))
os.makedirs(receive_mode_dir, 0o700)
except PermissionError:
self.web.add_request(self.web.REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE, request.path, {
"receive_mode_dir": receive_mode_dir
})
print(strings._('error_cannot_create_downloads_dir').format(receive_mode_dir))
valid = False
if not valid:
flash('Error uploading, please inform the OnionShare user', 'error')
@ -86,7 +87,7 @@ class ReceiveModeWeb(object):
# Automatically rename the file, if a file of the same name already exists
filename = secure_filename(f.filename)
filenames.append(filename)
local_path = os.path.join(self.common.settings.get('downloads_dir'), filename)
local_path = os.path.join(receive_mode_dir, filename)
if os.path.exists(local_path):
if '.' in filename:
# Add "-i", e.g. change "foo.txt" to "foo-2.txt"
@ -98,7 +99,7 @@ class ReceiveModeWeb(object):
valid = False
while not valid:
new_filename = '{}-{}.{}'.format('.'.join(name), i, ext)
local_path = os.path.join(self.common.settings.get('downloads_dir'), new_filename)
local_path = os.path.join(receive_mode_dir, new_filename)
if os.path.exists(local_path):
i += 1
else:
@ -109,7 +110,7 @@ class ReceiveModeWeb(object):
valid = False
while not valid:
new_filename = '{}-{}'.format(filename, i)
local_path = os.path.join(self.common.settings.get('downloads_dir'), new_filename)
local_path = os.path.join(receive_mode_dir, new_filename)
if os.path.exists(local_path):
i += 1
else:
@ -124,6 +125,13 @@ class ReceiveModeWeb(object):
'new_filename': basename
})
# Tell the GUI the receive mode directory for this file
self.web.add_request(self.web.REQUEST_UPLOAD_SET_DIR, request.path, {
'id': request.upload_id,
'filename': basename,
'dir': receive_mode_dir
})
self.common.log('ReceiveModeWeb', 'define_routes', '/upload, uploaded {}, saving to {}'.format(f.filename, local_path))
print(strings._('receive_mode_received_file').format(local_path))
f.save(local_path)

View File

@ -37,9 +37,9 @@ class Web(object):
REQUEST_RATE_LIMIT = 5
REQUEST_CLOSE_SERVER = 6
REQUEST_UPLOAD_FILE_RENAMED = 7
REQUEST_UPLOAD_FINISHED = 8
REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 9
REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE = 10
REQUEST_UPLOAD_SET_DIR = 8
REQUEST_UPLOAD_FINISHED = 9
REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 10
def __init__(self, common, is_gui, mode='share'):
self.common = common

View File

@ -324,6 +324,12 @@ class Mode(QtWidgets.QWidget):
"""
pass
def handle_request_upload_set_dir(self, event):
"""
Handle REQUEST_UPLOAD_SET_DIR event.
"""
pass
def handle_request_upload_finished(self, event):
"""
Handle REQUEST_UPLOAD_FINISHED event.

View File

@ -118,6 +118,7 @@ class UploadHistoryItemFile(QtWidgets.QWidget):
self.common.log('UploadHistoryItemFile', '__init__', 'filename: {}'.format(filename))
self.filename = filename
self.dir = None
self.started = datetime.now()
# Filename label
@ -158,13 +159,20 @@ class UploadHistoryItemFile(QtWidgets.QWidget):
self.filename = new_filename
self.filename_label.setText(self.filename)
def set_dir(self, dir):
self.dir = dir
def open_folder(self):
"""
Open the downloads folder, with the file selected, in a cross-platform manner
"""
self.common.log('UploadHistoryItemFile', 'open_folder')
abs_filename = os.path.join(self.common.settings.get('downloads_dir'), self.filename)
if not self.dir:
self.common.log('UploadHistoryItemFile', 'open_folder', "dir has not been set yet, can't open folder")
return
abs_filename = os.path.join(self.dir, self.filename)
# Linux
if self.common.platform == 'Linux' or self.common.platform == 'BSD':
@ -266,6 +274,9 @@ class UploadHistoryItem(HistoryItem):
self.files[data['old_filename']].rename(data['new_filename'])
self.files[data['new_filename']] = self.files.pop(data['old_filename'])
elif data['action'] == 'set_dir':
self.files[data['filename']].set_dir(data['dir'])
elif data['action'] == 'finished':
# Hide the progress bar
self.progress_bar.hide()

View File

@ -168,6 +168,16 @@ class ReceiveMode(Mode):
'new_filename': event["data"]["new_filename"]
})
def handle_request_upload_set_dir(self, event):
"""
Handle REQUEST_UPLOAD_SET_DIR event.
"""
self.history.update(event["data"]["id"], {
'action': 'set_dir',
'filename': event["data"]["filename"],
'dir': event["data"]["dir"]
})
def handle_request_upload_finished(self, event):
"""
Handle REQUEST_UPLOAD_FINISHED event.

View File

@ -284,7 +284,7 @@ class ShareMode(Mode):
# Update in progress count
self.history.in_progress_count -= 1
self.history.update_in_progress()
self.system_tray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True))
self.system_tray.showMessage(strings._('systray_download_canceled_title'), strings._('systray_download_canceled_message'))
def on_reload_settings(self):
"""

View File

@ -390,14 +390,14 @@ class OnionShareGui(QtWidgets.QMainWindow):
elif event["type"] == Web.REQUEST_UPLOAD_FILE_RENAMED:
mode.handle_request_upload_file_renamed(event)
elif event["type"] == Web.REQUEST_UPLOAD_SET_DIR:
mode.handle_request_upload_set_dir(event)
elif event["type"] == Web.REQUEST_UPLOAD_FINISHED:
mode.handle_request_upload_finished(event)
if event["type"] == Web.REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE:
Alert(self.common, strings._('error_cannot_create_downloads_dir').format(self.common.settings.get('downloads_dir')))
if event["type"] == Web.REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE:
Alert(self.common, strings._('error_downloads_dir_not_writable').format(self.common.settings.get('downloads_dir')))
Alert(self.common, strings._('error_cannot_create_downloads_dir').format(event["data"]["receive_mode_dir"]))
if event["type"] == Web.REQUEST_OTHER:
if event["path"] != '/favicon.ico' and event["path"] != "/{}/shutdown".format(mode.web.shutdown_slug):

View File

@ -35,6 +35,7 @@ class File(QtWidgets.QWidget):
self.common.log('File', '__init__', 'filename: {}'.format(filename))
self.filename = filename
self.dir = None
self.started = datetime.now()
# Filename label
@ -71,6 +72,9 @@ class File(QtWidgets.QWidget):
if complete:
self.folder_button.show()
def set_dir(self, dir):
self.dir = dir
def rename(self, new_filename):
self.filename = new_filename
self.filename_label.setText(self.filename)
@ -81,7 +85,10 @@ class File(QtWidgets.QWidget):
"""
self.common.log('File', 'open_folder')
abs_filename = os.path.join(self.common.settings.get('downloads_dir'), self.filename)
if not self.dir:
return
abs_filename = os.path.join(self.dir, self.filename)
# Linux
if self.common.platform == 'Linux' or self.common.platform == 'BSD':
@ -182,6 +189,9 @@ class Upload(QtWidgets.QWidget):
self.files[old_filename].rename(new_filename)
self.files[new_filename] = self.files.pop(old_filename)
def set_dir(self, filename, dir):
self.files[filename].set_dir(dir)
def finished(self):
# Hide the progress bar
self.progress_bar.hide()

View File

@ -269,7 +269,7 @@ 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:
Alert(self.common, strings._('gui_server_timeout_expired', QtWidgets.QMessageBox.Warning))
Alert(self.common, strings._('gui_server_timeout_expired'), QtWidgets.QMessageBox.Warning)
else:
self.start_server()
else:

View File

@ -62,7 +62,7 @@
"gui_receive_quit_warning": "You're in the process of receiving files. Are you sure you want to quit OnionShare?",
"gui_quit_warning_quit": "Quit",
"gui_quit_warning_dont_quit": "Cancel",
"error_rate_limit": "Someone has made too many wrong attempts on your address, which means they could be trying to guess it, so OnionShare has stopped the server. Start sharing again and send the receipient a new address to share.",
"error_rate_limit": "Someone has made too many wrong attempts on your address, which means they could be trying to guess it, so OnionShare has stopped the server. Start sharing again and send the recipient a new address to share.",
"zip_progress_bar_format": "Compressing: %p%",
"error_stealth_not_supported": "To use client authorization, you need at least both Tor 0.2.9.1-alpha (or Tor Browser 6.5) and python3-stem 1.5.0.",
"error_ephemeral_not_supported": "OnionShare requires at least both Tor 0.2.7.1 and python3-stem 1.4.0.",
@ -155,7 +155,6 @@
"info_in_progress_uploads_tooltip": "{} upload(s) in progress",
"info_completed_uploads_tooltip": "{} upload(s) completed",
"error_cannot_create_downloads_dir": "Could not create receive mode folder: {}",
"error_downloads_dir_not_writable": "The receive mode folder is write protected: {}",
"receive_mode_downloads_dir": "Files sent to you appear in this folder: {}",
"receive_mode_warning": "Warning: Receive mode lets people upload files to your computer. Some files can potentially take control of your computer if you open them. Only open things from people you trust, or if you know what you are doing.",
"gui_receive_mode_warning": "Receive mode lets people upload files to your computer.<br><br><b>Some files can potentially take control of your computer if you open them. Only open things from people you trust, or if you know what you are doing.</b>",

View File

@ -1,10 +1,9 @@
import json
import os
import requests
import shutil
import socket
import socks
import zipfile
import json
import shutil
from PyQt5 import QtCore, QtTest
@ -18,7 +17,7 @@ from onionshare_gui.mode.share_mode import ShareMode
from onionshare_gui.mode.receive_mode import ReceiveMode
class CommonTests(object):
class GuiBaseTest(object):
@staticmethod
def set_up(test_settings):
'''Create GUI with given settings'''
@ -27,6 +26,13 @@ class CommonTests(object):
testfile.write('onionshare')
testfile.close()
# Create a test dir and files
if not os.path.exists('/tmp/testdir'):
testdir = os.mkdir('/tmp/testdir')
testfile = open('/tmp/testdir/test', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.settings = Settings(common)
common.define_css()
@ -45,37 +51,52 @@ class CommonTests(object):
app = OnionShare(common, testonion, True, 0)
web = Web(common, False, True)
settings_filename = '/tmp/testsettings.json'
open(settings_filename, 'w').write(json.dumps(test_settings))
open('/tmp/settings.json', 'w').write(json.dumps(test_settings))
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True)
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/settings.json', True)
return gui
@staticmethod
def tear_down():
'''Clean up after tests'''
try:
os.remove('/tmp/test.txt')
os.remove('/tmp/settings.json')
os.remove('/tmp/large_file')
os.remove('/tmp/download.zip')
os.remove('/tmp/webpage')
shutil.rmtree('/tmp/testdir')
shutil.rmtree('/tmp/OnionShare')
except:
pass
def test_gui_loaded(self):
def gui_loaded(self):
'''Test that the GUI actually is shown'''
self.assertTrue(self.gui.show)
def test_windowTitle_seen(self):
def windowTitle_seen(self):
'''Test that the window title is OnionShare'''
self.assertEqual(self.gui.windowTitle(), 'OnionShare')
def test_settings_button_is_visible(self):
def settings_button_is_visible(self):
'''Test that the settings button is visible'''
self.assertTrue(self.gui.settings_button.isVisible())
def test_server_status_bar_is_visible(self):
def settings_button_is_hidden(self):
'''Test that the settings button is hidden when the server starts'''
self.assertFalse(self.gui.settings_button.isVisible())
def server_status_bar_is_visible(self):
'''Test that the status bar is visible'''
self.assertTrue(self.gui.status_bar.isVisible())
def test_click_mode(self, mode):
def click_mode(self, mode):
'''Test that we can switch Mode by clicking the button'''
if type(mode) == ReceiveMode:
QtTest.QTest.mouseClick(self.gui.receive_mode_button, QtCore.Qt.LeftButton)
@ -84,13 +105,15 @@ class CommonTests(object):
QtTest.QTest.mouseClick(self.gui.share_mode_button, QtCore.Qt.LeftButton)
self.assertTrue(self.gui.mode, self.gui.MODE_SHARE)
def test_click_toggle_history(self, mode):
def click_toggle_history(self, mode):
'''Test that we can toggle Download or Upload history by clicking the toggle button'''
currently_visible = mode.history.isVisible()
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
self.assertEqual(mode.history.isVisible(), not currently_visible)
def test_history_indicator(self, mode, public_mode):
def history_indicator(self, mode, public_mode):
'''Test that we can make sure the history is toggled off, do an action, and the indiciator works'''
# Make sure history is toggled off
if mode.history.isVisible():
@ -115,7 +138,7 @@ class CommonTests(object):
if public_mode:
url = "http://127.0.0.1:{}/download".format(self.gui.app.port)
else:
url = "http://127.0.0.1:{}/{}/download".format(self.gui.app.port, self.gui.share_mode.web.slug)
url = "http://127.0.0.1:{}/{}/download".format(self.gui.app.port, mode.web.slug)
r = requests.get(url)
QtTest.QTest.qWait(2000)
@ -127,41 +150,44 @@ class CommonTests(object):
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
def test_history_is_not_visible(self, mode):
def history_is_not_visible(self, mode):
'''Test that the History section is not visible'''
self.assertFalse(mode.history.isVisible())
def test_history_is_visible(self, mode):
def history_is_visible(self, mode):
'''Test that the History section is visible'''
self.assertTrue(mode.history.isVisible())
def test_server_working_on_start_button_pressed(self, mode):
def server_working_on_start_button_pressed(self, mode):
'''Test we can start the service'''
# Should be in SERVER_WORKING state
QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEqual(mode.server_status.status, 1)
def test_server_status_indicator_says_starting(self, mode):
def server_status_indicator_says_starting(self, mode):
'''Test that the Server Status indicator shows we are Starting'''
self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
def test_settings_button_is_hidden(self):
'''Test that the settings button is hidden when the server starts'''
self.assertFalse(self.gui.settings_button.isVisible())
def test_a_server_is_started(self, mode):
def server_is_started(self, mode, startup_time=2000):
'''Test that the server has started'''
QtTest.QTest.qWait(2000)
QtTest.QTest.qWait(startup_time)
# Should now be in SERVER_STARTED state
self.assertEqual(mode.server_status.status, 2)
def test_a_web_server_is_running(self):
def web_server_is_running(self):
'''Test that the web server has started'''
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.assertEqual(sock.connect_ex(('127.0.0.1',self.gui.app.port)), 0)
def test_have_a_slug(self, mode, public_mode):
def have_a_slug(self, mode, public_mode):
'''Test that we have a valid slug'''
if not public_mode:
self.assertRegex(mode.server_status.web.slug, r'(\w+)-(\w+)')
@ -169,22 +195,32 @@ class CommonTests(object):
self.assertIsNone(mode.server_status.web.slug, r'(\w+)-(\w+)')
def test_url_description_shown(self, mode):
def url_description_shown(self, mode):
'''Test that the URL label is showing'''
self.assertTrue(mode.server_status.url_description.isVisible())
def test_have_copy_url_button(self, mode):
'''Test that the Copy URL button is shown'''
def have_copy_url_button(self, mode, public_mode):
'''Test that the Copy URL button is shown and that the clipboard is correct'''
self.assertTrue(mode.server_status.copy_url_button.isVisible())
def test_server_status_indicator_says_started(self, mode):
QtTest.QTest.mouseClick(mode.server_status.copy_url_button, QtCore.Qt.LeftButton)
clipboard = self.gui.qtapp.clipboard()
if public_mode:
self.assertEqual(clipboard.text(), 'http://127.0.0.1:{}'.format(self.gui.app.port))
else:
self.assertEqual(clipboard.text(), 'http://127.0.0.1:{}/{}'.format(self.gui.app.port, mode.server_status.web.slug))
def server_status_indicator_says_started(self, mode):
'''Test that the Server Status indicator shows we are started'''
if type(mode) == ReceiveMode:
self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started'))
self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started'))
if type(mode) == ShareMode:
self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_started'))
self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_started'))
def test_web_page(self, mode, string, public_mode):
def web_page(self, mode, string, public_mode):
'''Test that the web page contains a string'''
s = socks.socksocket()
s.settimeout(60)
@ -212,22 +248,26 @@ class CommonTests(object):
self.assertTrue(string in f.read())
f.close()
def test_history_widgets_present(self, mode):
def history_widgets_present(self, mode):
'''Test that the relevant widgets are present in the history view after activity has taken place'''
self.assertFalse(mode.history.empty.isVisible())
self.assertTrue(mode.history.not_empty.isVisible())
def test_counter_incremented(self, mode, count):
'''Test that the counter has incremented'''
self.assertEquals(mode.history.completed_count, count)
def test_server_is_stopped(self, mode, stay_open):
def counter_incremented(self, mode, count):
'''Test that the counter has incremented'''
self.assertEqual(mode.history.completed_count, count)
def server_is_stopped(self, mode, stay_open):
'''Test that the server stops when we click Stop'''
if type(mode) == ReceiveMode or (type(mode) == ShareMode and stay_open):
QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEquals(mode.server_status.status, 0)
self.assertEqual(mode.server_status.status, 0)
def test_web_service_is_stopped(self):
def web_server_is_stopped(self):
'''Test that the web server also stopped'''
QtTest.QTest.qWait(2000)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@ -235,105 +275,49 @@ class CommonTests(object):
# We should be closed by now. Fail if not!
self.assertNotEqual(sock.connect_ex(('127.0.0.1',self.gui.app.port)), 0)
def test_server_status_indicator_says_closed(self, mode, stay_open):
def server_status_indicator_says_closed(self, mode, stay_open):
'''Test that the Server Status indicator shows we closed'''
if type(mode) == ReceiveMode:
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped'))
self.assertEqual(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped'))
if type(mode) == ShareMode:
if stay_open:
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped'))
self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped'))
else:
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically'))
self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically'))
# Auto-stop timer tests
def test_set_timeout(self, mode, timeout):
def set_timeout(self, mode, timeout):
'''Test that the timeout can be set'''
timer = QtCore.QDateTime.currentDateTime().addSecs(timeout)
mode.server_status.shutdown_timeout.setDateTime(timer)
self.assertTrue(mode.server_status.shutdown_timeout.dateTime(), timer)
def test_timeout_widget_hidden(self, mode):
def timeout_widget_hidden(self, mode):
'''Test that the timeout widget is hidden when share has started'''
self.assertFalse(mode.server_status.shutdown_timeout_container.isVisible())
def test_server_timed_out(self, mode, wait):
def server_timed_out(self, mode, wait):
'''Test that the server has timed out after the timer ran out'''
QtTest.QTest.qWait(wait)
# We should have timed out now
self.assertEqual(mode.server_status.status, 0)
# Receive-specific tests
def test_upload_file(self, public_mode, expected_file):
'''Test that we can upload the file'''
files = {'file[]': open('/tmp/test.txt', 'rb')}
if not public_mode:
path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug)
else:
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
response = requests.post(path, files=files)
QtTest.QTest.qWait(2000)
self.assertTrue(os.path.isfile(expected_file))
# Hack to close an Alert dialog that would otherwise block tests
def accept_dialog(self):
window = self.gui.qtapp.activeWindow()
if window:
window.close()
# Share-specific tests
def test_file_selection_widget_has_a_file(self):
'''Test that the number of files in the list is 1'''
self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 1)
# 'Grouped' tests follow from here
def test_deleting_only_file_hides_delete_button(self):
'''Test that clicking on the file item shows the delete button. Test that deleting the only item in the list hides the delete button'''
rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0))
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center())
# Delete button should be visible
self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible())
# Click delete, and since there's no more files, the delete button should be hidden
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton)
self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible())
def run_all_common_setup_tests(self):
self.gui_loaded()
self.windowTitle_seen()
self.settings_button_is_visible()
self.server_status_bar_is_visible()
def test_add_a_file_and_delete_using_its_delete_widget(self):
'''Test that we can also delete a file by clicking on its [X] widget'''
self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts')
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.item(0).item_button, QtCore.Qt.LeftButton)
self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 0)
def test_file_selection_widget_readd_files(self):
'''Re-add some files to the list so we can share'''
self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts')
self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/test.txt')
self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2)
def test_add_delete_buttons_hidden(self):
'''Test that the add and delete buttons are hidden when the server starts'''
self.assertFalse(self.gui.share_mode.server_status.file_selection.add_button.isVisible())
self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible())
def test_download_share(self, public_mode):
'''Test that we can download the share'''
s = socks.socksocket()
s.settimeout(60)
s.connect(('127.0.0.1', self.gui.app.port))
if public_mode:
path = '/download'
else:
path = '{}/download'.format(self.gui.share_mode.web.slug)
http_request = 'GET {} HTTP/1.0\r\n'.format(path)
http_request += 'Host: 127.0.0.1\r\n'
http_request += '\r\n'
s.sendall(http_request.encode('utf-8'))
with open('/tmp/download.zip', 'wb') as file_to_write:
while True:
data = s.recv(1024)
if not data:
break
file_to_write.write(data)
file_to_write.close()
zip = zipfile.ZipFile('/tmp/download.zip')
QtTest.QTest.qWait(2000)
self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8'))
def test_add_button_visible(self):
'''Test that the add button should be visible'''
self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible())

124
tests/GuiReceiveTest.py Normal file
View File

@ -0,0 +1,124 @@
import os
import requests
from datetime import datetime, timedelta
from PyQt5 import QtCore, QtTest
from .GuiBaseTest import GuiBaseTest
class GuiReceiveTest(GuiBaseTest):
def upload_file(self, public_mode, file_to_upload, expected_basename):
'''Test that we can upload the file'''
files = {'file[]': open(file_to_upload, 'rb')}
if not public_mode:
path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug)
else:
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
response = requests.post(path, files=files)
QtTest.QTest.qWait(2000)
# Make sure the file is within the last 10 seconds worth of filenames
exists = False
now = datetime.now()
for i in range(10):
date_dir = now.strftime("%Y-%m-%d")
time_dir = now.strftime("%H.%M.%S")
receive_mode_dir = os.path.join(self.gui.common.settings.get('downloads_dir'), date_dir, time_dir)
expected_filename = os.path.join(receive_mode_dir, expected_basename)
if os.path.exists(expected_filename):
exists = True
break
now = now - timedelta(seconds=1)
self.assertTrue(exists)
def upload_file_should_fail(self, public_mode):
'''Test that we can't upload the file when permissions are wrong, and expected content is shown'''
files = {'file[]': open('/tmp/test.txt', 'rb')}
if not public_mode:
path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug)
else:
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
response = requests.post(path, files=files)
QtCore.QTimer.singleShot(1000, self.accept_dialog)
self.assertTrue('Error uploading, please inform the OnionShare user' in response.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):
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):
'''Test that the share can be stopped by the sender in receive mode'''
if not public_mode:
path = 'http://127.0.0.1:{}/{}/close'.format(self.gui.app.port, self.gui.receive_mode.web.slug)
else:
path = 'http://127.0.0.1:{}/close'.format(self.gui.app.port)
response = requests.post(path)
self.server_is_stopped(self.gui.receive_mode, False)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.receive_mode, False)
# 'Grouped' tests follow from here
def run_all_receive_mode_setup_tests(self, public_mode):
'''Set up a share in Receive mode and start it'''
self.click_mode(self.gui.receive_mode)
self.history_is_not_visible(self.gui.receive_mode)
self.click_toggle_history(self.gui.receive_mode)
self.history_is_visible(self.gui.receive_mode)
self.server_working_on_start_button_pressed(self.gui.receive_mode)
self.server_status_indicator_says_starting(self.gui.receive_mode)
self.settings_button_is_hidden()
self.server_is_started(self.gui.receive_mode)
self.web_server_is_running()
self.have_a_slug(self.gui.receive_mode, public_mode)
self.url_description_shown(self.gui.receive_mode)
self.have_copy_url_button(self.gui.receive_mode, public_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)
def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown):
'''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.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)
self.upload_file(public_mode, '/tmp/test.txt', 'test.txt')
self.counter_incremented(self.gui.receive_mode, 2)
self.upload_file(public_mode, '/tmp/testdir/test', 'test')
self.counter_incremented(self.gui.receive_mode, 3)
self.upload_file(public_mode, '/tmp/testdir/test', 'test')
self.counter_incremented(self.gui.receive_mode, 4)
self.history_indicator(self.gui.receive_mode, public_mode)
self.server_is_stopped(self.gui.receive_mode, False)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.receive_mode, False)
self.server_working_on_start_button_pressed(self.gui.receive_mode)
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):
'''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)
self.upload_file_should_fail(public_mode)
self.server_is_stopped(self.gui.receive_mode, True)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.receive_mode, False)
self.upload_dir_permissions(0o755)
def run_all_receive_mode_timer_tests(self, public_mode):
"""Auto-stop timer tests in receive mode"""
self.run_all_receive_mode_setup_tests(public_mode)
self.set_timeout(self.gui.receive_mode, 5)
self.timeout_widget_hidden(self.gui.receive_mode)
self.server_timed_out(self.gui.receive_mode, 15000)
self.web_server_is_stopped()

204
tests/GuiShareTest.py Normal file
View File

@ -0,0 +1,204 @@
import os
import requests
import socks
import zipfile
from PyQt5 import QtCore, QtTest
from .GuiBaseTest import GuiBaseTest
class GuiShareTest(GuiBaseTest):
# Persistence tests
def have_same_slug(self, slug):
'''Test that we have the same slug'''
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
# Share-specific tests
def file_selection_widget_has_files(self, num=2):
'''Test that the number of items in the list is as expected'''
self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), num)
def deleting_all_files_hides_delete_button(self):
'''Test that clicking on the file item shows the delete button. Test that deleting the only item in the list hides the delete button'''
rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0))
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center())
# Delete button should be visible
self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible())
# Click delete, delete button should still be visible since we have one more file
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton)
rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0))
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center())
self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible())
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton)
# No more files, the delete button should be hidden
self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible())
def add_a_file_and_delete_using_its_delete_widget(self):
'''Test that we can also delete a file by clicking on its [X] widget'''
self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts')
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.item(0).item_button, QtCore.Qt.LeftButton)
self.file_selection_widget_has_files(0)
def file_selection_widget_readd_files(self):
'''Re-add some files to the list so we can share'''
self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts')
self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/test.txt')
self.file_selection_widget_has_files(2)
def add_large_file(self):
'''Add a large file to the share'''
size = 1024*1024*155
with open('/tmp/large_file', 'wb') as fout:
fout.write(os.urandom(size))
self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/large_file')
def add_delete_buttons_hidden(self):
'''Test that the add and delete buttons are hidden when the server starts'''
self.assertFalse(self.gui.share_mode.server_status.file_selection.add_button.isVisible())
self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible())
def download_share(self, public_mode):
'''Test that we can download the share'''
s = socks.socksocket()
s.settimeout(60)
s.connect(('127.0.0.1', self.gui.app.port))
if public_mode:
path = '/download'
else:
path = '{}/download'.format(self.gui.share_mode.web.slug)
http_request = 'GET {} HTTP/1.0\r\n'.format(path)
http_request += 'Host: 127.0.0.1\r\n'
http_request += '\r\n'
s.sendall(http_request.encode('utf-8'))
with open('/tmp/download.zip', 'wb') as file_to_write:
while True:
data = s.recv(1024)
if not data:
break
file_to_write.write(data)
file_to_write.close()
zip = zipfile.ZipFile('/tmp/download.zip')
QtTest.QTest.qWait(2000)
self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8'))
def hit_404(self, public_mode):
'''Test that the server stops after too many 404s, or doesn't when in public_mode'''
bogus_path = '/gimme'
url = "http://127.0.0.1:{}/{}".format(self.gui.app.port, bogus_path)
for _ in range(20):
r = requests.get(url)
# A nasty hack to avoid the Alert dialog that blocks the rest of the test
if not public_mode:
QtCore.QTimer.singleShot(1000, self.accept_dialog)
# In public mode, we should still be running (no rate-limiting)
if public_mode:
self.web_server_is_running()
# In non-public mode, we should be shut down (rate-limiting)
else:
self.web_server_is_stopped()
def add_button_visible(self):
'''Test that the add button should be visible'''
self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible())
# 'Grouped' tests follow from here
def run_all_share_mode_setup_tests(self):
"""Tests in share mode prior to starting a share"""
self.click_mode(self.gui.share_mode)
self.file_selection_widget_has_files()
self.history_is_not_visible(self.gui.share_mode)
self.click_toggle_history(self.gui.share_mode)
self.history_is_visible(self.gui.share_mode)
self.deleting_all_files_hides_delete_button()
self.add_a_file_and_delete_using_its_delete_widget()
self.file_selection_widget_readd_files()
def run_all_share_mode_started_tests(self, public_mode, startup_time=2000):
"""Tests in share mode after starting a share"""
self.server_working_on_start_button_pressed(self.gui.share_mode)
self.server_status_indicator_says_starting(self.gui.share_mode)
self.add_delete_buttons_hidden()
self.settings_button_is_hidden()
self.server_is_started(self.gui.share_mode, startup_time)
self.web_server_is_running()
self.have_a_slug(self.gui.share_mode, public_mode)
self.url_description_shown(self.gui.share_mode)
self.have_copy_url_button(self.gui.share_mode, public_mode)
self.server_status_indicator_says_started(self.gui.share_mode)
def run_all_share_mode_download_tests(self, public_mode, stay_open):
"""Tests in share mode after downloading a share"""
self.web_page(self.gui.share_mode, 'Total size', public_mode)
self.download_share(public_mode)
self.history_widgets_present(self.gui.share_mode)
self.server_is_stopped(self.gui.share_mode, stay_open)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.share_mode, stay_open)
self.add_button_visible()
self.server_working_on_start_button_pressed(self.gui.share_mode)
self.server_is_started(self.gui.share_mode)
self.history_indicator(self.gui.share_mode, public_mode)
def run_all_share_mode_tests(self, public_mode, stay_open):
"""End-to-end share tests"""
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(public_mode)
self.run_all_share_mode_download_tests(public_mode, stay_open)
def run_all_large_file_tests(self, public_mode, stay_open):
"""Same as above but with a larger file"""
self.run_all_share_mode_setup_tests()
self.add_large_file()
self.run_all_share_mode_started_tests(public_mode, startup_time=15000)
self.assertTrue(self.gui.share_mode.filesize_warning.isVisible())
self.server_is_stopped(self.gui.share_mode, stay_open)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.share_mode, stay_open)
def run_all_share_mode_persistent_tests(self, public_mode, stay_open):
"""Same as end-to-end share tests but also test the slug is the same on multiple shared"""
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(public_mode)
slug = self.gui.share_mode.server_status.web.slug
self.run_all_share_mode_download_tests(public_mode, stay_open)
self.have_same_slug(slug)
def run_all_share_mode_timer_tests(self, public_mode):
"""Auto-stop timer tests in share mode"""
self.run_all_share_mode_setup_tests()
self.set_timeout(self.gui.share_mode, 5)
self.run_all_share_mode_started_tests(public_mode)
self.timeout_widget_hidden(self.gui.share_mode)
self.server_timed_out(self.gui.share_mode, 10000)
self.web_server_is_stopped()
def run_all_share_mode_unreadable_file_tests(self):
'''Attempt to share an unreadable file'''
self.run_all_share_mode_setup_tests()
QtCore.QTimer.singleShot(1000, self.accept_dialog)
self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/nonexistent.txt')
self.file_selection_widget_has_files(2)

View File

@ -0,0 +1,44 @@
import json
import os
from onionshare import strings
from onionshare.common import Common
from onionshare.settings import Settings
from onionshare.onion import Onion
from onionshare_gui import Application, OnionShare
from onionshare_gui.settings_dialog import SettingsDialog
class SettingsGuiBaseTest(object):
@staticmethod
def set_up(test_settings):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.settings = Settings(common)
common.define_css()
strings.load_strings(common)
# Start the Onion
testonion = Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, True, 0)
for key, val in common.settings.default_settings.items():
if key not in test_settings:
test_settings[key] = val
open('/tmp/settings.json', 'w').write(json.dumps(test_settings))
gui = SettingsDialog(common, testonion, qtapp, '/tmp/settings.json', True)
return gui
@staticmethod
def tear_down():
'''Clean up after tests'''
os.remove('/tmp/settings.json')

173
tests/TorGuiBaseTest.py Normal file
View File

@ -0,0 +1,173 @@
import json
import os
import requests
import socks
from PyQt5 import QtCore, QtTest
from onionshare import strings
from onionshare.common import Common
from onionshare.settings import Settings
from onionshare.onion import Onion
from onionshare.web import Web
from onionshare_gui import Application, OnionShare, OnionShareGui
from onionshare_gui.mode.share_mode import ShareMode
from onionshare_gui.mode.receive_mode import ReceiveMode
from .GuiBaseTest import GuiBaseTest
class TorGuiBaseTest(GuiBaseTest):
@staticmethod
def set_up(test_settings):
'''Create GUI with given settings'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
# Create a test dir and files
if not os.path.exists('/tmp/testdir'):
testdir = os.mkdir('/tmp/testdir')
testfile = open('/tmp/testdir/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.settings = Settings(common)
common.define_css()
strings.load_strings(common)
# Get all of the settings in test_settings
test_settings['connection_type'] = 'automatic'
test_settings['downloads_dir'] = '/tmp/OnionShare'
for key, val in common.settings.default_settings.items():
if key not in test_settings:
test_settings[key] = val
# Start the Onion
testonion = Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, False)
open('/tmp/settings.json', 'w').write(json.dumps(test_settings))
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/settings.json', False)
return gui
def history_indicator(self, mode, public_mode):
'''Test that we can make sure the history is toggled off, do an action, and the indiciator works'''
# Make sure history is toggled off
if mode.history.isVisible():
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
self.assertFalse(mode.history.isVisible())
# Indicator should not be visible yet
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
# Set up connecting to the onion
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
if type(mode) == ReceiveMode:
# Upload a file
files = {'file[]': open('/tmp/test.txt', 'rb')}
if not public_mode:
path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, mode.web.slug)
else:
path = 'http://{}/upload'.format(self.gui.app.onion_host)
response = session.post(path, files=files)
QtTest.QTest.qWait(4000)
if type(mode) == ShareMode:
# Download files
if public_mode:
path = "http://{}/download".format(self.gui.app.onion_host)
else:
path = "http://{}/{}/download".format(self.gui.app.onion_host, mode.web.slug)
response = session.get(path)
QtTest.QTest.qWait(4000)
# Indicator should be visible, have a value of "1"
self.assertTrue(mode.toggle_history.indicator_label.isVisible())
self.assertEqual(mode.toggle_history.indicator_label.text(), "1")
# Toggle history back on, indicator should be hidden again
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
def have_an_onion_service(self):
'''Test that we have a valid Onion URL'''
self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion')
def web_page(self, mode, string, public_mode):
'''Test that the web page contains a string'''
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
socks.set_default_proxy(socks.SOCKS5, socks_address, socks_port)
s = socks.socksocket()
s.settimeout(60)
s.connect((self.gui.app.onion_host, 80))
if not public_mode:
path = '/{}'.format(mode.server_status.web.slug)
else:
path = '/'
http_request = 'GET {} HTTP/1.0\r\n'.format(path)
http_request += 'Host: {}\r\n'.format(self.gui.app.onion_host)
http_request += '\r\n'
s.sendall(http_request.encode('utf-8'))
with open('/tmp/webpage', 'wb') as file_to_write:
while True:
data = s.recv(1024)
if not data:
break
file_to_write.write(data)
file_to_write.close()
f = open('/tmp/webpage')
self.assertTrue(string in f.read())
f.close()
def have_copy_url_button(self, mode, public_mode):
'''Test that the Copy URL button is shown and that the clipboard is correct'''
self.assertTrue(mode.server_status.copy_url_button.isVisible())
QtTest.QTest.mouseClick(mode.server_status.copy_url_button, QtCore.Qt.LeftButton)
clipboard = self.gui.qtapp.clipboard()
if public_mode:
self.assertEqual(clipboard.text(), 'http://{}'.format(self.gui.app.onion_host))
else:
self.assertEqual(clipboard.text(), 'http://{}/{}'.format(self.gui.app.onion_host, mode.server_status.web.slug))
def cancel_the_share(self, mode):
'''Test that we can cancel this share before it's started up '''
self.server_working_on_start_button_pressed(self.gui.share_mode)
self.server_status_indicator_says_starting(self.gui.share_mode)
self.add_delete_buttons_hidden()
self.settings_button_is_hidden()
QtTest.QTest.mousePress(mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(1000)
QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEqual(mode.server_status.status, 0)
self.server_is_stopped(self.gui.share_mode, False)
self.web_server_is_stopped()
# Stealth tests
def copy_have_hidserv_auth_button(self, mode):
'''Test that the Copy HidservAuth button is shown'''
self.assertTrue(mode.server_status.copy_hidservauth_button.isVisible())
def hidserv_auth_string(self):
'''Test the validity of the HidservAuth string'''
self.assertRegex(self.gui.app.auth_string, r'HidServAuth {} [a-zA-Z1-9]'.format(self.gui.app.onion_host))
# Miscellaneous tests
def tor_killed_statusbar_message_shown(self, mode):
'''Test that the status bar message shows Tor was disconnected'''
self.gui.app.onion.c = None
QtTest.QTest.qWait(1000)
self.assertTrue(mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))

View File

@ -0,0 +1,59 @@
import os
import requests
from PyQt5 import QtTest
from .TorGuiBaseTest import TorGuiBaseTest
class TorGuiReceiveTest(TorGuiBaseTest):
def upload_file(self, public_mode, file_to_upload, expected_file):
'''Test that we can upload the file'''
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
files = {'file[]': open(file_to_upload, 'rb')}
if not public_mode:
path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug)
else:
path = 'http://{}/upload'.format(self.gui.app.onion_host)
response = session.post(path, files=files)
QtTest.QTest.qWait(4000)
self.assertTrue(os.path.isfile(expected_file))
# 'Grouped' tests follow from here
def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown):
'''Run a full suite of tests in Receive mode'''
self.click_mode(self.gui.receive_mode)
self.history_is_not_visible(self.gui.receive_mode)
self.click_toggle_history(self.gui.receive_mode)
self.history_is_visible(self.gui.receive_mode)
self.server_working_on_start_button_pressed(self.gui.receive_mode)
self.server_status_indicator_says_starting(self.gui.receive_mode)
self.settings_button_is_hidden()
self.server_is_started(self.gui.receive_mode, startup_time=45000)
self.web_server_is_running()
self.have_an_onion_service()
self.have_a_slug(self.gui.receive_mode, public_mode)
self.url_description_shown(self.gui.receive_mode)
self.have_copy_url_button(self.gui.receive_mode, public_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.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt')
self.history_widgets_present(self.gui.receive_mode)
self.counter_incremented(self.gui.receive_mode, 1)
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt')
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.server_is_stopped(self.gui.receive_mode, False)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.receive_mode, False)
self.server_working_on_start_button_pressed(self.gui.receive_mode)
self.server_is_started(self.gui.receive_mode, startup_time=45000)
self.history_indicator(self.gui.receive_mode, public_mode)

95
tests/TorGuiShareTest.py Normal file
View File

@ -0,0 +1,95 @@
import requests
import zipfile
from PyQt5 import QtTest
from .TorGuiBaseTest import TorGuiBaseTest
from .GuiShareTest import GuiShareTest
class TorGuiShareTest(TorGuiBaseTest, GuiShareTest):
def download_share(self, public_mode):
'''Test downloading a share'''
# Set up connecting to the onion
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
# Download files
if public_mode:
path = "http://{}/download".format(self.gui.app.onion_host)
else:
path = "http://{}/{}/download".format(self.gui.app.onion_host, self.gui.share_mode.web.slug)
response = session.get(path, stream=True)
QtTest.QTest.qWait(4000)
if response.status_code == 200:
with open('/tmp/download.zip', 'wb') as file_to_write:
for chunk in response.iter_content(chunk_size=128):
file_to_write.write(chunk)
file_to_write.close()
zip = zipfile.ZipFile('/tmp/download.zip')
QtTest.QTest.qWait(4000)
self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8'))
# Persistence tests
def have_same_onion(self, onion):
'''Test that we have the same onion'''
self.assertEqual(self.gui.app.onion_host, onion)
# legacy v2 onion test
def have_v2_onion(self):
'''Test that the onion is a v2 style onion'''
self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion')
self.assertEqual(len(self.gui.app.onion_host), 22)
# 'Grouped' tests follow from here
def run_all_share_mode_started_tests(self, public_mode):
'''Tests in share mode after starting a share'''
self.server_working_on_start_button_pressed(self.gui.share_mode)
self.server_status_indicator_says_starting(self.gui.share_mode)
self.add_delete_buttons_hidden()
self.settings_button_is_hidden()
self.server_is_started(self.gui.share_mode, startup_time=45000)
self.web_server_is_running()
self.have_an_onion_service()
self.have_a_slug(self.gui.share_mode, public_mode)
self.url_description_shown(self.gui.share_mode)
self.have_copy_url_button(self.gui.share_mode, public_mode)
self.server_status_indicator_says_started(self.gui.share_mode)
def run_all_share_mode_download_tests(self, public_mode, stay_open):
"""Tests in share mode after downloading a share"""
self.web_page(self.gui.share_mode, 'Total size', public_mode)
self.download_share(public_mode)
self.history_widgets_present(self.gui.share_mode)
self.server_is_stopped(self.gui.share_mode, stay_open)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.share_mode, stay_open)
self.add_button_visible()
self.server_working_on_start_button_pressed(self.gui.share_mode)
self.server_is_started(self.gui.share_mode, startup_time=45000)
self.history_indicator(self.gui.share_mode, public_mode)
def run_all_share_mode_persistent_tests(self, public_mode, stay_open):
"""Same as end-to-end share tests but also test the slug is the same on multiple shared"""
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(public_mode)
slug = self.gui.share_mode.server_status.web.slug
onion = self.gui.app.onion_host
self.run_all_share_mode_download_tests(public_mode, stay_open)
self.have_same_onion(onion)
self.have_same_slug(slug)
def run_all_share_mode_timer_tests(self, public_mode):
"""Auto-stop timer tests in share mode"""
self.run_all_share_mode_setup_tests()
self.set_timeout(self.gui.share_mode, 120)
self.run_all_share_mode_started_tests(public_mode)
self.timeout_widget_hidden(self.gui.share_mode)
self.server_timed_out(self.gui.share_mode, 125000)
self.web_server_is_stopped()

View File

@ -10,6 +10,22 @@ import pytest
from onionshare import common, web, settings, strings
def pytest_addoption(parser):
parser.addoption(
"--runtor", action="store_true", default=False, help="run tor tests"
)
def pytest_collection_modifyitems(config, items):
if config.getoption("--runtor"):
# --runtor given in cli: do not skip tor tests
return
skip_tor = pytest.mark.skip(reason="need --runtor option to run")
for item in items:
if "tor" in item.keywords:
item.add_marker(skip_tor)
@pytest.fixture
def temp_dir_1024():
""" Create a temporary directory that has a single file of a
@ -151,13 +167,11 @@ def time_strftime(monkeypatch):
@pytest.fixture
def common_obj():
_common = common.Common()
_common.settings = settings.Settings(_common)
strings.load_strings(_common)
return _common
return common.Common()
@pytest.fixture
def settings_obj(sys_onionshare_dev_mode, platform_linux):
_common = common.Common()
_common.version = 'DUMMY_VERSION_1.2.3'
strings.load_strings(_common)
return settings.Settings(_common)

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import unittest
from .GuiShareTest import GuiShareTest
class Local404PublicModeRateLimitTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False,
"public_mode": True
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(True, True)
self.hit_404(True)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import unittest
from .GuiShareTest import GuiShareTest
class Local404RateLimitTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, True)
self.hit_404(False)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import unittest
from PyQt5 import QtCore, QtTest
from .GuiShareTest import GuiShareTest
class LocalQuittingDuringSharePromptsWarningTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, True)
# Prepare our auto-accept of prompt
QtCore.QTimer.singleShot(5000, self.accept_dialog)
# Try to close the app
self.gui.close()
# Server should still be running (we've been prompted first)
self.server_is_started(self.gui.share_mode, 0)
self.web_server_is_running()
if __name__ == "__main__":
unittest.main()

View File

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

View File

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

View File

@ -0,0 +1,23 @@
#!/usr/bin/env python3
import unittest
from .GuiReceiveTest import GuiReceiveTest
class LocalReceiveModeUnwritableTest(unittest.TestCase, GuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"receive_allow_receiver_shutdown": True
}
cls.gui = GuiReceiveTest.set_up(test_settings)
@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(False, True)
if __name__ == "__main__":
unittest.main()

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)
@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

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

View File

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

View File

@ -0,0 +1,178 @@
#!/usr/bin/env python3
import json
import unittest
from PyQt5 import QtCore, QtTest
from onionshare import strings
from .SettingsGuiBaseTest import SettingsGuiBaseTest
class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest):
@classmethod
def setUpClass(cls):
test_settings = {
"no_bridges": False,
"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)
@classmethod
def tearDownClass(cls):
SettingsGuiBaseTest.tear_down()
def test_gui(self):
self.gui.show()
# Window is shown
self.assertTrue(self.gui.isVisible())
self.assertEqual(self.gui.windowTitle(), strings._('gui_settings_window_title'))
# Check for updates button is hidden
self.assertFalse(self.gui.check_for_updates_button.isVisible())
# public mode is off
self.assertFalse(self.gui.public_mode_checkbox.isChecked())
# enable public mode
QtTest.QTest.mouseClick(self.gui.public_mode_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.public_mode_checkbox.height()/2))
self.assertTrue(self.gui.public_mode_checkbox.isChecked())
# shutdown timer is off
self.assertFalse(self.gui.shutdown_timeout_checkbox.isChecked())
# enable shutdown timer
QtTest.QTest.mouseClick(self.gui.shutdown_timeout_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.shutdown_timeout_checkbox.height()/2))
self.assertTrue(self.gui.shutdown_timeout_checkbox.isChecked())
# legacy mode checkbox and related widgets
# legacy mode is off
self.assertFalse(self.gui.use_legacy_v2_onions_checkbox.isChecked())
# persistence, stealth is hidden and disabled
self.assertFalse(self.gui.save_private_key_widget.isVisible())
self.assertFalse(self.gui.save_private_key_checkbox.isChecked())
self.assertFalse(self.gui.use_stealth_widget.isVisible())
self.assertFalse(self.gui.stealth_checkbox.isChecked())
self.assertFalse(self.gui.hidservauth_copy_button.isVisible())
# enable legacy mode
QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2))
self.assertTrue(self.gui.use_legacy_v2_onions_checkbox.isChecked())
self.assertTrue(self.gui.save_private_key_checkbox.isVisible())
self.assertTrue(self.gui.use_stealth_widget.isVisible())
# enable persistent mode
QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2))
self.assertTrue(self.gui.save_private_key_checkbox.isChecked())
# enable stealth mode
QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2))
self.assertTrue(self.gui.stealth_checkbox.isChecked())
# now that stealth, persistence are enabled, we can't turn off legacy mode
self.assertFalse(self.gui.use_legacy_v2_onions_checkbox.isEnabled())
# disable stealth, persistence
QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2))
QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2))
# legacy mode checkbox is enabled again
self.assertTrue(self.gui.use_legacy_v2_onions_checkbox.isEnabled())
# uncheck legacy mode
QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2))
# legacy options hidden again
self.assertFalse(self.gui.save_private_key_widget.isVisible())
self.assertFalse(self.gui.use_stealth_widget.isVisible())
# enable them all again so that we can see the setting stick in settings.json
QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2))
QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2))
QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2))
# stay open toggled off, on
self.assertTrue(self.gui.close_after_first_download_checkbox.isChecked())
QtTest.QTest.mouseClick(self.gui.close_after_first_download_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.close_after_first_download_checkbox.height()/2))
self.assertFalse(self.gui.close_after_first_download_checkbox.isChecked())
# receive mode
self.gui.downloads_dir_lineedit.setText('/tmp/OnionShareSettingsTest')
# allow receiver shutdown is on
self.assertTrue(self.gui.receive_allow_receiver_shutdown_checkbox.isChecked())
# disable receiver shutdown
QtTest.QTest.mouseClick(self.gui.receive_allow_receiver_shutdown_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.receive_allow_receiver_shutdown_checkbox.height()/2))
self.assertFalse(self.gui.receive_allow_receiver_shutdown_checkbox.isChecked())
# bundled mode is enabled
self.assertTrue(self.gui.connection_type_bundled_radio.isEnabled())
self.assertTrue(self.gui.connection_type_bundled_radio.isChecked())
# bridge options are shown
self.assertTrue(self.gui.connection_type_bridges_radio_group.isVisible())
# bridges are set to custom
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())
# custom bridges are hidden
self.assertFalse(self.gui.tor_bridges_use_custom_textbox_options.isVisible())
# other modes are unchecked but enabled
self.assertTrue(self.gui.connection_type_automatic_radio.isEnabled())
self.assertTrue(self.gui.connection_type_control_port_radio.isEnabled())
self.assertTrue(self.gui.connection_type_socket_file_radio.isEnabled())
self.assertFalse(self.gui.connection_type_automatic_radio.isChecked())
self.assertFalse(self.gui.connection_type_control_port_radio.isChecked())
self.assertFalse(self.gui.connection_type_socket_file_radio.isChecked())
# enable automatic mode
QtTest.QTest.mouseClick(self.gui.connection_type_automatic_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_automatic_radio.height()/2))
self.assertTrue(self.gui.connection_type_automatic_radio.isChecked())
# bundled is off
self.assertFalse(self.gui.connection_type_bundled_radio.isChecked())
# bridges are hidden
self.assertFalse(self.gui.connection_type_bridges_radio_group.isVisible())
# auth type is hidden in bundled or automatic mode
self.assertFalse(self.gui.authenticate_no_auth_radio.isVisible())
self.assertFalse(self.gui.authenticate_password_radio.isVisible())
# enable control port mode
QtTest.QTest.mouseClick(self.gui.connection_type_control_port_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_control_port_radio.height()/2))
self.assertTrue(self.gui.connection_type_control_port_radio.isChecked())
# automatic is off
self.assertFalse(self.gui.connection_type_automatic_radio.isChecked())
# auth options appear
self.assertTrue(self.gui.authenticate_no_auth_radio.isVisible())
self.assertTrue(self.gui.authenticate_password_radio.isVisible())
# enable socket mode
QtTest.QTest.mouseClick(self.gui.connection_type_socket_file_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_socket_file_radio.height()/2))
self.assertTrue(self.gui.connection_type_socket_file_radio.isChecked())
# control port is off
self.assertFalse(self.gui.connection_type_control_port_radio.isChecked())
# auth options are still present
self.assertTrue(self.gui.authenticate_no_auth_radio.isVisible())
self.assertTrue(self.gui.authenticate_password_radio.isVisible())
# 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))
# 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))
self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked())
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')
# Test that the Settings Dialog can save the settings and close itself
QtTest.QTest.mouseClick(self.gui.save_button, QtCore.Qt.LeftButton)
self.assertFalse(self.gui.isVisible())
# Test our settings are reflected in the settings json
with open('/tmp/settings.json') as f:
data = json.load(f)
self.assertTrue(data["public_mode"])
self.assertTrue(data["shutdown_timeout"])
self.assertTrue(data["use_legacy_v2_onions"])
self.assertTrue(data["save_private_key"])
self.assertTrue(data["use_stealth"])
self.assertEqual(data["downloads_dir"], "/tmp/OnionShareSettingsTest")
self.assertFalse(data["receive_allow_receiver_shutdown"])
self.assertFalse(data["close_after_first_download"])
self.assertEqual(data["connection_type"], "bundled")
self.assertFalse(data["tor_bridges_use_obfs4"])
self.assertEqual(data["tor_bridges_use_custom_bridges"], "Bridge 94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\nBridge 148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\nBridge 93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3\n")
if __name__ == "__main__":
unittest.main()

View File

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

View File

@ -0,0 +1,23 @@
#!/usr/bin/env python3
import unittest
from .GuiShareTest import GuiShareTest
class LocalShareModeStayOpenTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False,
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, True)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import unittest
from .GuiShareTest import GuiShareTest
class LocalShareModeTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, False)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import unittest
from .GuiShareTest import GuiShareTest
class LocalShareModeLargeDownloadTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_large_file_tests(False, True)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import unittest
from .GuiShareTest import GuiShareTest
class LocalShareModePersistentSlugTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"slug": "",
"save_private_key": True,
"close_after_first_download": False,
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_persistent_tests(False, True)
if __name__ == "__main__":
unittest.main()

View File

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

View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import unittest
from PyQt5 import QtCore, QtTest
from .GuiShareTest import GuiShareTest
class LocalShareModeTimerTooShortTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"shutdown_timeout": True,
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_setup_tests()
# Set a low timeout
self.set_timeout(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()

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import unittest
from .GuiShareTest import GuiShareTest
class LocalShareModeUnReadableFileTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_unreadable_file_tests()
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
# Tests #790 regression
class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": True
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, False)
self.cancel_the_share(self.gui.share_mode)
self.server_is_stopped(self.gui.share_mode, False)
self.web_server_is_stopped()
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiReceiveTest import TorGuiReceiveTest
class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
"receive_allow_receiver_shutdown": True
}
cls.gui = TorGuiReceiveTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiReceiveTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_receive_mode_tests(True, True)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiReceiveTest import TorGuiReceiveTest
class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"receive_allow_receiver_shutdown": True
}
cls.gui = TorGuiReceiveTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiReceiveTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_receive_mode_tests(False, True)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_setup_tests()
self.cancel_the_share(self.gui.share_mode)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModePublicModeTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(True, False)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeStayOpenTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False,
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, True)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, False)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"use_legacy_v2_onions": True,
"public_mode": False,
"slug": "",
"save_private_key": True,
"close_after_first_download": False,
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_persistent_tests(False, True)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"use_legacy_v2_onions": True,
"use_stealth": True,
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(False)
self.hidserv_auth_string()
self.copy_have_hidserv_auth_button(self.gui.share_mode)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeTimerTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"shutdown_timeout": True,
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_timer_tests(False)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeTorConnectionKilledTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(False)
self.tor_killed_statusbar_message_shown(self.gui.share_mode)
self.server_is_stopped(self.gui.share_mode, False)
self.web_server_is_stopped()
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeV2OnionTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"use_legacy_v2_onions": True,
}
cls.gui = TorGuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
TorGuiShareTest.tear_down()
@pytest.mark.tor
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_share_mode_tests(False, False)
self.have_v2_onion()
if __name__ == "__main__":
unittest.main()

View File

@ -23,7 +23,7 @@ import types
import pytest
from onionshare import strings
from onionshare.settings import Settings
# # Stub get_resource_path so it finds the correct path while running tests
# def get_resource_path(filename):
@ -40,6 +40,7 @@ class TestLoadStrings:
def test_load_strings_defaults_to_english(
self, common_obj, locale_en, sys_onionshare_dev_mode):
""" load_strings() loads English by default """
common_obj.settings = Settings(common_obj)
strings.load_strings(common_obj)
assert strings._('preparing_files') == "Compressing files."
@ -47,6 +48,7 @@ class TestLoadStrings:
def test_load_strings_loads_other_languages(
self, common_obj, locale_fr, sys_onionshare_dev_mode):
""" load_strings() loads other languages in different locales """
common_obj.settings = Settings(common_obj)
common_obj.settings.set('locale', 'fr')
strings.load_strings(common_obj)
assert strings._('preparing_files') == "Préparation des fichiers à partager."
@ -55,5 +57,6 @@ class TestLoadStrings:
self, common_obj, locale_invalid, sys_onionshare_dev_mode):
""" load_strings() raises a KeyError for an invalid locale """
with pytest.raises(KeyError):
common_obj.settings = Settings(common_obj)
common_obj.settings.set('locale', 'XX')
strings.load_strings(common_obj)

View File

@ -31,6 +31,7 @@ import tempfile
import pytest
from onionshare.common import Common
from onionshare import strings
from onionshare.web import Web
from onionshare.settings import Settings
@ -41,7 +42,7 @@ RANDOM_STR_REGEX = re.compile(r'^[a-z2-7]+$')
def web_obj(common_obj, mode, num_files=0):
""" Creates a Web object, in either share mode or receive mode, ready for testing """
common_obj.load_settings()
strings.load_strings(common_obj)
web = Web(common_obj, False, mode)
web.generate_slug()
web.stay_open = True

View File

@ -1 +0,0 @@
from .commontests import CommonTests

View File

@ -1,160 +0,0 @@
import sys
# Force tests to look for resources in the source code tree
sys.onionshare_dev_mode = True
import os
import shutil
import tempfile
import pytest
from onionshare import common, web, settings
@pytest.fixture
def temp_dir_1024():
""" Create a temporary directory that has a single file of a
particular size (1024 bytes).
"""
tmp_dir = tempfile.mkdtemp()
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
with open(tmp_file, 'wb') as f:
f.write(b'*' * 1024)
return tmp_dir
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture
def temp_dir_1024_delete():
""" 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.
"""
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
with open(tmp_file, 'wb') as f:
f.write(b'*' * 1024)
yield tmp_dir
@pytest.fixture
def temp_file_1024():
""" Create a temporary file of a particular size (1024 bytes). """
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
tmp_file.write(b'*' * 1024)
return tmp_file.name
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture
def temp_file_1024_delete():
"""
Create a temporary file of a particular size (1024 bytes).
The temporary file will be deleted after fixture usage.
"""
with tempfile.NamedTemporaryFile() as tmp_file:
tmp_file.write(b'*' * 1024)
tmp_file.flush()
yield tmp_file.name
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture(scope='session')
def custom_zw():
zw = web.share_mode.ZipWriter(
common.Common(),
zip_filename=common.Common.random_string(4, 6),
processed_size_callback=lambda _: 'custom_callback'
)
yield zw
zw.close()
os.remove(zw.zip_filename)
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture(scope='session')
def default_zw():
zw = web.share_mode.ZipWriter(common.Common())
yield zw
zw.close()
tmp_dir = os.path.dirname(zw.zip_filename)
shutil.rmtree(tmp_dir)
@pytest.fixture
def locale_en(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8'))
@pytest.fixture
def locale_fr(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8'))
@pytest.fixture
def locale_invalid(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8'))
@pytest.fixture
def locale_ru(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8'))
@pytest.fixture
def platform_darwin(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Darwin')
@pytest.fixture # (scope="session")
def platform_linux(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Linux')
@pytest.fixture
def platform_windows(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Windows')
@pytest.fixture
def sys_argv_sys_prefix(monkeypatch):
monkeypatch.setattr('sys.argv', [sys.prefix])
@pytest.fixture
def sys_frozen(monkeypatch):
monkeypatch.setattr('sys.frozen', True, raising=False)
@pytest.fixture
def sys_meipass(monkeypatch):
monkeypatch.setattr(
'sys._MEIPASS', os.path.expanduser('~'), raising=False)
@pytest.fixture # (scope="session")
def sys_onionshare_dev_mode(monkeypatch):
monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False)
@pytest.fixture
def time_time_100(monkeypatch):
monkeypatch.setattr('time.time', lambda: 100)
@pytest.fixture
def time_strftime(monkeypatch):
monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00')
@pytest.fixture
def common_obj():
return common.Common()
@pytest.fixture
def settings_obj(sys_onionshare_dev_mode, platform_linux):
_common = common.Common()
_common.version = 'DUMMY_VERSION_1.2.3'
return settings.Settings(_common)

View File

@ -1,139 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"receive_allow_receiver_shutdown": True
}
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=6)
def test_click_mode(self):
CommonTests.test_click_mode(self, self.gui.receive_mode)
@pytest.mark.run(order=6)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, self.gui.receive_mode)
@pytest.mark.run(order=7)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, self.gui.receive_mode)
@pytest.mark.run(order=8)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, self.gui.receive_mode)
@pytest.mark.run(order=8)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.receive_mode)
@pytest.mark.run(order=9)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, self.gui.receive_mode)
@pytest.mark.run(order=10)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=11)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, self.gui.receive_mode)
@pytest.mark.run(order=12)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=14)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, self.gui.receive_mode, False)
@pytest.mark.run(order=15)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, self.gui.receive_mode)
@pytest.mark.run(order=16)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, self.gui.receive_mode)
@pytest.mark.run(order=17)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, self.gui.receive_mode)
@pytest.mark.run(order=18)
def test_web_page(self):
CommonTests.test_web_page(self, self.gui.receive_mode, 'Select the files you want to send, then click', False)
@pytest.mark.run(order=19)
def test_upload_file(self):
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test.txt')
@pytest.mark.run(order=20)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, self.gui.receive_mode)
@pytest.mark.run(order=21)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, self.gui.receive_mode, 1)
@pytest.mark.run(order=22)
def test_upload_same_file_is_renamed(self):
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=23)
def test_upload_count_incremented_again(self):
CommonTests.test_counter_incremented(self, self.gui.receive_mode, 2)
@pytest.mark.run(order=24)
def test_history_indicator(self):
CommonTests.test_history_indicator(self, self.gui.receive_mode, False)
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, self.gui.receive_mode, False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=27)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, self.gui.receive_mode, False)
if __name__ == "__main__":
unittest.main()

View File

@ -1,140 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.settings import Settings
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
"receive_allow_receiver_shutdown": True
}
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_click_mode(self):
CommonTests.test_click_mode(self, self.gui.receive_mode)
@pytest.mark.run(order=6)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, self.gui.receive_mode)
@pytest.mark.run(order=7)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, self.gui.receive_mode)
@pytest.mark.run(order=8)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, self.gui.receive_mode)
@pytest.mark.run(order=9)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.receive_mode)
@pytest.mark.run(order=10)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, self.gui.receive_mode)
@pytest.mark.run(order=11)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=12)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, self.gui.receive_mode)
@pytest.mark.run(order=13)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=14)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, self.gui.receive_mode, True)
@pytest.mark.run(order=15)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, self.gui.receive_mode)
@pytest.mark.run(order=16)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, self.gui.receive_mode)
@pytest.mark.run(order=17)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, self.gui.receive_mode)
@pytest.mark.run(order=18)
def test_web_page(self):
CommonTests.test_web_page(self, self.gui.receive_mode, 'Select the files you want to send, then click', True)
@pytest.mark.run(order=19)
def test_upload_file(self):
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test.txt')
@pytest.mark.run(order=20)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, self.gui.receive_mode)
@pytest.mark.run(order=21)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, self.gui.receive_mode, 1)
@pytest.mark.run(order=22)
def test_upload_same_file_is_renamed(self):
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=23)
def test_upload_count_incremented_again(self):
CommonTests.test_counter_incremented(self, self.gui.receive_mode, 2)
@pytest.mark.run(order=24)
def test_history_indicator(self):
CommonTests.test_history_indicator(self, self.gui.receive_mode, True)
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, self.gui.receive_mode, False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=27)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, self.gui.receive_mode, False)
if __name__ == "__main__":
unittest.main()

View File

@ -1,150 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"close_after_first_download": True
}
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, self.gui.share_mode)
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, self.gui.share_mode)
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, self.gui.share_mode)
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode)
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, self.gui.share_mode, False)
@pytest.mark.run(order=20)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, self.gui.share_mode)
@pytest.mark.run(order=21)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, self.gui.share_mode)
@pytest.mark.run(order=22)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode)
@pytest.mark.run(order=23)
def test_web_page(self):
CommonTests.test_web_page(self, self.gui.share_mode, 'Total size', False)
@pytest.mark.run(order=24)
def test_download_share(self):
CommonTests.test_download_share(self, False)
@pytest.mark.run(order=25)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, self.gui.share_mode)
@pytest.mark.run(order=26)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, self.gui.share_mode, False)
@pytest.mark.run(order=27)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=28)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, False)
@pytest.mark.run(order=29)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
@pytest.mark.run(order=30)
def test_history_indicator(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
CommonTests.test_history_indicator(self, self.gui.share_mode, False)
if __name__ == "__main__":
unittest.main()

View File

@ -1,149 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True
}
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, self.gui.share_mode)
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, self.gui.share_mode)
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, self.gui.share_mode)
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode)
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, self.gui.share_mode, True)
@pytest.mark.run(order=20)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, self.gui.share_mode)
@pytest.mark.run(order=21)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, self.gui.share_mode)
@pytest.mark.run(order=22)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode)
@pytest.mark.run(order=23)
def test_web_page(self):
CommonTests.test_web_page(self, self.gui.share_mode, 'Total size', True)
@pytest.mark.run(order=24)
def test_download_share(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=25)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, self.gui.share_mode)
@pytest.mark.run(order=26)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, self.gui.share_mode, False)
@pytest.mark.run(order=27)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=28)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, False)
@pytest.mark.run(order=29)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
@pytest.mark.run(order=30)
def test_history_indicator(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
CommonTests.test_history_indicator(self, self.gui.share_mode, True)
if __name__ == "__main__":
unittest.main()

View File

@ -1,162 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
"close_after_first_download": False
}
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, self.gui.share_mode)
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, self.gui.share_mode)
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, self.gui.share_mode)
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode)
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, self.gui.share_mode, True)
@pytest.mark.run(order=20)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, self.gui.share_mode)
@pytest.mark.run(order=21)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, self.gui.share_mode)
@pytest.mark.run(order=22)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode)
@pytest.mark.run(order=23)
def test_web_page(self):
CommonTests.test_web_page(self, self.gui.share_mode, 'Total size', True)
@pytest.mark.run(order=24)
def test_download_share(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=25)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, self.gui.share_mode)
@pytest.mark.run(order=26)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, self.gui.share_mode, 1)
@pytest.mark.run(order=27)
def test_download_share_again(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=28)
def test_counter_incremented_again(self):
CommonTests.test_counter_incremented(self, self.gui.share_mode, 2)
@pytest.mark.run(order=29)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, self.gui.share_mode, True)
@pytest.mark.run(order=30)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=31)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, True)
@pytest.mark.run(order=32)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
@pytest.mark.run(order=33)
def test_history_indicator(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
CommonTests.test_history_indicator(self, self.gui.share_mode, True)
if __name__ == "__main__":
unittest.main()

View File

@ -1,125 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"slug": "",
"save_private_key": True
}
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, self.gui.share_mode)
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, self.gui.share_mode)
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, self.gui.share_mode)
@pytest.mark.run(order=10)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
@pytest.mark.run(order=11)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode)
@pytest.mark.run(order=12)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=13)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
@pytest.mark.run(order=14)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=15)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, self.gui.share_mode, False)
global slug
slug = self.gui.share_mode.server_status.web.slug
@pytest.mark.run(order=16)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode)
@pytest.mark.run(order=17)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, self.gui.share_mode, True)
@pytest.mark.run(order=18)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=19)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, True)
@pytest.mark.run(order=20)
def test_server_started_again(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode)
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
@pytest.mark.run(order=21)
def test_have_same_slug(self):
'''Test that we have the same slug'''
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
@pytest.mark.run(order=22)
def test_server_is_stopped_again(self):
CommonTests.test_server_is_stopped(self, self.gui.share_mode, True)
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=23)
def test_history_indicator(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
CommonTests.test_history_indicator(self, self.gui.share_mode, False)
if __name__ == "__main__":
unittest.main()

View File

@ -1,87 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"shutdown_timeout": True
}
cls.gui = CommonTests.set_up(test_settings)
@classmethod
def tearDownClass(cls):
CommonTests.tear_down()
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, self.gui.share_mode)
@pytest.mark.run(order=8)
def test_set_timeout(self):
CommonTests.test_set_timeout(self, self.gui.share_mode, 5)
@pytest.mark.run(order=9)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode)
@pytest.mark.run(order=10)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode)
@pytest.mark.run(order=11)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, self.gui.share_mode)
@pytest.mark.run(order=12)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=13)
def test_timeout_widget_hidden(self):
CommonTests.test_timeout_widget_hidden(self, self.gui.share_mode)
@pytest.mark.run(order=14)
def test_timeout(self):
CommonTests.test_server_timed_out(self, self.gui.share_mode, 10000)
@pytest.mark.run(order=15)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,5 +0,0 @@
#!/bin/bash
for test in `ls -1 | egrep ^onionshare_`; do
pytest $test -vvv || exit 1
done

View File

@ -1,61 +0,0 @@
import os
import requests
import socket
import socks
import zipfile
from PyQt5 import QtCore, QtTest
from onionshare import strings
from tests_gui_local import CommonTests as LocalCommonTests
class CommonTests(LocalCommonTests):
def test_a_server_is_started(self, mode):
'''Test that the server has started (overriding from local tests to wait for longer)'''
QtTest.QTest.qWait(45000)
# Should now be in SERVER_STARTED state
if mode == 'receive':
self.assertEqual(self.gui.receive_mode.server_status.status, 2)
if mode == 'share':
self.assertEqual(self.gui.share_mode.server_status.status, 2)
def test_have_an_onion_service(self):
'''Test that we have a valid Onion URL'''
self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion')
def test_cancel_the_share(self, mode):
'''Test that we can cancel this share before it's started up '''
if mode == 'share':
QtTest.QTest.mousePress(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(1000)
QtTest.QTest.mouseRelease(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEqual(self.gui.share_mode.server_status.status, 0)
if mode == 'receive':
QtTest.QTest.mousePress(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(1000)
QtTest.QTest.mouseRelease(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEqual(self.gui.receive_mode.server_status.status, 0)
# Stealth tests
def test_copy_have_hidserv_auth_button(self, mode):
'''Test that the Copy HidservAuth button is shown'''
if mode == 'share':
self.assertTrue(self.gui.share_mode.server_status.copy_hidservauth_button.isVisible())
if mode == 'receive':
self.assertTrue(self.gui.receive_mode.server_status.copy_hidservauth_button.isVisible())
def test_hidserv_auth_string(self):
'''Test the validity of the HidservAuth string'''
self.assertRegex(self.gui.app.auth_string, r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host)
# Miscellaneous tests
def test_tor_killed_statusbar_message_shown(self, mode):
'''Test that the status bar message shows Tor was disconnected'''
self.gui.app.onion.cleanup(stop_tor=True)
QtTest.QTest.qWait(2500)
if mode == 'share':
self.assertTrue(self.gui.share_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))
if mode == 'receive':
self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))

View File

@ -1,163 +0,0 @@
import sys
# Force tests to look for resources in the source code tree
sys.onionshare_dev_mode = True
import os
import shutil
import tempfile
import pytest
from onionshare import common, web, settings, strings
@pytest.fixture
def temp_dir_1024():
""" Create a temporary directory that has a single file of a
particular size (1024 bytes).
"""
tmp_dir = tempfile.mkdtemp()
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
with open(tmp_file, 'wb') as f:
f.write(b'*' * 1024)
return tmp_dir
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture
def temp_dir_1024_delete():
""" 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.
"""
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
with open(tmp_file, 'wb') as f:
f.write(b'*' * 1024)
yield tmp_dir
@pytest.fixture
def temp_file_1024():
""" Create a temporary file of a particular size (1024 bytes). """
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
tmp_file.write(b'*' * 1024)
return tmp_file.name
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture
def temp_file_1024_delete():
"""
Create a temporary file of a particular size (1024 bytes).
The temporary file will be deleted after fixture usage.
"""
with tempfile.NamedTemporaryFile() as tmp_file:
tmp_file.write(b'*' * 1024)
tmp_file.flush()
yield tmp_file.name
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture(scope='session')
def custom_zw():
zw = web.share_mode.ZipWriter(
common.Common(),
zip_filename=common.Common.random_string(4, 6),
processed_size_callback=lambda _: 'custom_callback'
)
yield zw
zw.close()
os.remove(zw.zip_filename)
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture(scope='session')
def default_zw():
zw = web.share_mode.ZipWriter(common.Common())
yield zw
zw.close()
tmp_dir = os.path.dirname(zw.zip_filename)
shutil.rmtree(tmp_dir)
@pytest.fixture
def locale_en(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8'))
@pytest.fixture
def locale_fr(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8'))
@pytest.fixture
def locale_invalid(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8'))
@pytest.fixture
def locale_ru(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8'))
@pytest.fixture
def platform_darwin(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Darwin')
@pytest.fixture # (scope="session")
def platform_linux(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Linux')
@pytest.fixture
def platform_windows(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Windows')
@pytest.fixture
def sys_argv_sys_prefix(monkeypatch):
monkeypatch.setattr('sys.argv', [sys.prefix])
@pytest.fixture
def sys_frozen(monkeypatch):
monkeypatch.setattr('sys.frozen', True, raising=False)
@pytest.fixture
def sys_meipass(monkeypatch):
monkeypatch.setattr(
'sys._MEIPASS', os.path.expanduser('~'), raising=False)
@pytest.fixture # (scope="session")
def sys_onionshare_dev_mode(monkeypatch):
monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False)
@pytest.fixture
def time_time_100(monkeypatch):
monkeypatch.setattr('time.time', lambda: 100)
@pytest.fixture
def time_strftime(monkeypatch):
monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00')
@pytest.fixture
def common_obj():
_common = common.Common()
_common.settings = settings.Settings(_common)
strings.load_strings(_common)
return _common
@pytest.fixture
def settings_obj(sys_onionshare_dev_mode, platform_linux):
_common = common.Common()
_common.version = 'DUMMY_VERSION_1.2.3'
return settings.Settings(_common)

View File

@ -1,197 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_is_visible(self):
CommonTests.test_info_widget_is_visible(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=8)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=9)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=10)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=11)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=12)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=13)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=14)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=15)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=16)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=17)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=18)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=19)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=20)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=21)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=22)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', True)
@pytest.mark.run(order=23)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=24)
def test_server_working_on_start_button_pressed_round2(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=25)
def test_server_status_indicator_says_starting_round2(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=26)
def test_cancel_the_share(self):
CommonTests.test_cancel_the_share(self, 'share')
@pytest.mark.run(order=27)
def test_server_is_stopped_round2(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=28)
def test_web_service_is_stopped_round2(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=29)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,190 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
os.remove('/tmp/OnionShare/test.txt')
os.remove('/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=6)
def test_click_mode(self):
CommonTests.test_click_mode(self, 'receive')
@pytest.mark.run(order=6)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'receive')
@pytest.mark.run(order=7)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'receive')
@pytest.mark.run(order=8)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'receive')
@pytest.mark.run(order=8)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'receive')
@pytest.mark.run(order=9)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'receive')
@pytest.mark.run(order=10)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=11)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'receive')
@pytest.mark.run(order=12)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=14)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'receive', False)
@pytest.mark.run(order=15)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=20)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'receive')
@pytest.mark.run(order=21)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'receive')
@pytest.mark.run(order=22)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'receive')
@pytest.mark.run(order=23)
def test_web_page(self):
CommonTests.test_web_page(self, 'receive', 'Select the files you want to send, then click', False)
@pytest.mark.run(order=24)
def test_upload_file(self):
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test.txt')
@pytest.mark.run(order=25)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'receive')
@pytest.mark.run(order=26)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, 'receive', 1)
@pytest.mark.run(order=27)
def test_upload_same_file_is_renamed(self):
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=28)
def test_upload_count_incremented_again(self):
CommonTests.test_counter_incremented(self, 'receive', 2)
@pytest.mark.run(order=29)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'receive', False)
@pytest.mark.run(order=30)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=31)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'receive', False)
if __name__ == "__main__":
unittest.main()

View File

@ -1,190 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": True,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
os.remove('/tmp/OnionShare/test.txt')
os.remove('/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_click_mode(self):
CommonTests.test_click_mode(self, 'receive')
@pytest.mark.run(order=6)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'receive')
@pytest.mark.run(order=7)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'receive')
@pytest.mark.run(order=8)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'receive')
@pytest.mark.run(order=9)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'receive')
@pytest.mark.run(order=10)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'receive')
@pytest.mark.run(order=11)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=12)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'receive')
@pytest.mark.run(order=13)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=14)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'receive', True)
@pytest.mark.run(order=15)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=20)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'receive')
@pytest.mark.run(order=21)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'receive')
@pytest.mark.run(order=22)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'receive')
@pytest.mark.run(order=23)
def test_web_page(self):
CommonTests.test_web_page(self, 'receive', 'Select the files you want to send, then click', True)
@pytest.mark.run(order=24)
def test_upload_file(self):
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test.txt')
@pytest.mark.run(order=25)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'receive')
@pytest.mark.run(order=26)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, 'receive', 1)
@pytest.mark.run(order=27)
def test_upload_same_file_is_renamed(self):
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=28)
def test_upload_count_incremented_again(self):
CommonTests.test_counter_incremented(self, 'receive', 2)
@pytest.mark.run(order=29)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'receive', False)
@pytest.mark.run(order=30)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=31)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'receive', False)
if __name__ == "__main__":
unittest.main()

View File

@ -1,149 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=8)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=9)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=10)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=11)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=12)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=13)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=14)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=16)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=17)
def test_cancel_the_share(self):
CommonTests.test_cancel_the_share(self, 'share')
@pytest.mark.run(order=18)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=19)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=20)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,193 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=11)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=12)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=13)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=14)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=15)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=16)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=17)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=18)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=19)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=20)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=21)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=22)
def test_web_page(self):
CommonTests.test_web_page(self, 'share', 'Total size', False)
@pytest.mark.run(order=23)
def test_download_share(self):
CommonTests.test_download_share(self, False)
@pytest.mark.run(order=24)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'share')
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=27)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', False)
@pytest.mark.run(order=28)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,201 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": True,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', True)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_web_page(self):
CommonTests.test_web_page(self, 'share', 'Total size', True)
@pytest.mark.run(order=25)
def test_download_share(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=26)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'share')
@pytest.mark.run(order=27)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=28)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=29)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', False)
@pytest.mark.run(order=30)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,213 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": False,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": True,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', True)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_web_page(self):
CommonTests.test_web_page(self, 'share', 'Total size', True)
@pytest.mark.run(order=25)
def test_download_share(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=26)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'share')
@pytest.mark.run(order=27)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, 'share', 1)
@pytest.mark.run(order=28)
def test_download_share_again(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=29)
def test_counter_incremented_again(self):
CommonTests.test_counter_incremented(self, 'share', 2)
@pytest.mark.run(order=30)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', True)
@pytest.mark.run(order=31)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=32)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
@pytest.mark.run(order=33)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,185 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
slug = ''
onion_host = ''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": True,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=11)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=12)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=13)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=14)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=15)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
global slug
slug = self.gui.share_mode.server_status.web.slug
@pytest.mark.run(order=16)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
global onion_host
onion_host = self.gui.app.onion_host
@pytest.mark.run(order=17)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=18)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', True)
@pytest.mark.run(order=19)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=20)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
@pytest.mark.run(order=21)
def test_server_started_again(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
CommonTests.test_server_status_indicator_says_starting(self, 'share')
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=22)
def test_have_same_slug(self):
'''Test that we have the same slug'''
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
@pytest.mark.run(order=23)
def test_have_same_onion(self):
'''Test that we have the same onion'''
self.assertEqual(self.gui.app.onion_host, onion_host)
@pytest.mark.run(order=24)
def test_server_is_stopped_again(self):
CommonTests.test_server_is_stopped(self, 'share', True)
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,180 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": True,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_copy_have_hidserv_auth_button(self):
CommonTests.test_copy_have_hidserv_auth_button(self, 'share')
@pytest.mark.run(order=25)
def test_hidserv_auth_string(self):
CommonTests.test_hidserv_auth_string(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,185 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_tor_killed_statusbar_message_shown(self):
CommonTests.test_tor_killed_statusbar_message_shown(self, 'share')
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,148 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": True,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_set_timeout(self):
CommonTests.test_set_timeout(self, 'share', 120)
@pytest.mark.run(order=11)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=12)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=13)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=14)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=15)
def test_timeout_widget_hidden(self):
CommonTests.test_timeout_widget_hidden(self, 'share')
@pytest.mark.run(order=16)
def test_timeout(self):
CommonTests.test_server_timed_out(self, 'share', 125000)
@pytest.mark.run(order=17)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,185 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@classmethod
def setUpClass(cls):
'''Create the GUI'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.define_css()
# Start the Onion
strings.load_strings(common)
testonion = onion.Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": True,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"shutdown_timeout": False,
"slug": "",
"socks_address": "127.0.0.1",
"socks_port": 9050,
"socket_file_path": "/var/run/tor/control",
"systray_notifications": True,
"tor_bridges_use_meek_lite_azure": False,
"tor_bridges_use_meek_lite_amazon": False,
"tor_bridges_use_custom_bridges": "",
"tor_bridges_use_obfs4": False,
"use_stealth": False,
"use_legacy_v2_onions": False,
"use_autoupdate": True,
"version": "1.3.1"
}
testsettings = '/tmp/testsettings.json'
open(testsettings, 'w').write(json.dumps(test_settings))
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
def test_info_widget_shows_less(self):
CommonTests.test_info_widget_shows_less(self, 'share')
@pytest.mark.run(order=7)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'share')
@pytest.mark.run(order=8)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'share')
@pytest.mark.run(order=9)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_tor_killed_statusbar_message_shown(self):
CommonTests.test_tor_killed_statusbar_message_shown(self, 'share')
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View File

@ -1,5 +0,0 @@
#!/bin/bash
for test in `ls -1 | egrep ^onionshare_`; do
pytest $test -vvv || exit 1
done