Merge develop branch and fix conflicts
39
.circleci/config.yml
Normal 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/
|
||||
|
23
.travis.yml
@ -1,23 +0,0 @@
|
||||
language: python
|
||||
dist: trusty
|
||||
sudo: required
|
||||
python:
|
||||
- "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
|
20
BUILD.md
@ -143,24 +143,22 @@ OnionShare includes PyTest unit tests. To run the tests, first install some depe
|
||||
pip3 install -r install/requirements-tests.txt
|
||||
```
|
||||
|
||||
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/
|
||||
```
|
||||
|
@ -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)
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
@ -33,7 +33,15 @@ def main(cwd=None):
|
||||
"""
|
||||
common = Common()
|
||||
|
||||
# Load the default settings and strings early, for the sake of being able to parse options.
|
||||
# These won't be in the user's chosen locale necessarily, but we need to parse them
|
||||
# early in order to even display the option to pass alternate settings (which might
|
||||
# contain a preferred locale).
|
||||
# If an alternate --config is passed, we'll reload strings later.
|
||||
common.load_settings()
|
||||
strings.load_strings(common)
|
||||
|
||||
# Display OnionShare banner
|
||||
print(strings._('version_string').format(common.version))
|
||||
|
||||
# OnionShare CLI in OSX needs to change current working directory (#132)
|
||||
@ -88,8 +96,11 @@ def main(cwd=None):
|
||||
if not valid:
|
||||
sys.exit()
|
||||
|
||||
# Load settings
|
||||
common.load_settings(config)
|
||||
# Re-load settings, if a custom config was passed in
|
||||
if config:
|
||||
common.load_settings(config)
|
||||
# Re-load the strings, in case the provided config has changed locale
|
||||
strings.load_strings(common)
|
||||
|
||||
# Debug mode?
|
||||
common.debug = debug
|
||||
|
@ -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.
|
||||
@ -211,6 +197,7 @@ class Common(object):
|
||||
color: #000000;
|
||||
padding: 10px;
|
||||
border: 1px solid #666666;
|
||||
font-size: 12px;
|
||||
}
|
||||
""",
|
||||
|
||||
@ -248,11 +235,46 @@ class Common(object):
|
||||
border-radius: 5px;
|
||||
}""",
|
||||
|
||||
'downloads_uploads_empty': """
|
||||
QWidget {
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #999999;
|
||||
}
|
||||
QWidget QLabel {
|
||||
background-color: none;
|
||||
border: 0px;
|
||||
}
|
||||
""",
|
||||
|
||||
'downloads_uploads_empty_text': """
|
||||
QLabel {
|
||||
color: #999999;
|
||||
}""",
|
||||
|
||||
'downloads_uploads_label': """
|
||||
QLabel {
|
||||
font-weight: bold;
|
||||
font-size 14px;
|
||||
text-align: center;
|
||||
background-color: none;
|
||||
border: none;
|
||||
}""",
|
||||
|
||||
'downloads_uploads_clear': """
|
||||
QPushButton {
|
||||
color: #3f7fcf;
|
||||
}
|
||||
""",
|
||||
|
||||
'download_uploads_indicator': """
|
||||
QLabel {
|
||||
color: #ffffff;
|
||||
background-color: #f44449;
|
||||
font-weight: bold;
|
||||
font-size: 10px;
|
||||
padding: 2px;
|
||||
border-radius: 7px;
|
||||
text-align: center;
|
||||
}""",
|
||||
|
||||
'downloads_uploads_progress_bar': """
|
||||
@ -261,7 +283,7 @@ class Common(object):
|
||||
background-color: #ffffff !important;
|
||||
text-align: center;
|
||||
color: #9b9b9b;
|
||||
font-size: 12px;
|
||||
font-size: 14px;
|
||||
}
|
||||
QProgressBar::chunk {
|
||||
background-color: #4e064f;
|
||||
@ -354,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):
|
||||
"""
|
||||
|
@ -247,7 +247,7 @@ class Onion(object):
|
||||
self.c = Controller.from_socket_file(path=self.tor_control_socket)
|
||||
self.c.authenticate()
|
||||
except Exception as e:
|
||||
raise BundledTorBroken(strings._('settings_error_bundled_tor_broken', True).format(e.args[0]))
|
||||
raise BundledTorBroken(strings._('settings_error_bundled_tor_broken').format(e.args[0]))
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import locale
|
||||
|
||||
from . import strings
|
||||
|
||||
@ -47,6 +48,25 @@ class Settings(object):
|
||||
else:
|
||||
self.common.log('Settings', '__init__', 'Supplied config does not exist or is unreadable. Falling back to default location')
|
||||
|
||||
# Dictionary of available languages in this version of OnionShare,
|
||||
# mapped to the language name, in that language
|
||||
self.available_locales = {
|
||||
'cs': 'Hrvatski', # Croatian
|
||||
'da': 'Dansk', # Danish
|
||||
'de': 'Deutsch', # German
|
||||
'en': 'English', # English
|
||||
'eo': 'Esperanto', # Esperanto
|
||||
'es': 'Español', # Spanish
|
||||
'fi': 'Suomi', # Finnish
|
||||
'fr': 'Français', # French
|
||||
'it': 'Italiano', # Italian
|
||||
'nl': 'Nederlands', # Dutch
|
||||
'no': 'Norsk', # Norweigan
|
||||
'pt': 'Português', # Portuguese
|
||||
'ru': 'Русский', # Russian
|
||||
'tr': 'Türkçe' # Turkish
|
||||
}
|
||||
|
||||
# These are the default settings. They will get overwritten when loading from disk
|
||||
self.default_settings = {
|
||||
'version': self.common.version,
|
||||
@ -73,7 +93,8 @@ class Settings(object):
|
||||
'public_mode': False,
|
||||
'slug': '',
|
||||
'hidservauth_string': '',
|
||||
'downloads_dir': self.build_default_downloads_dir()
|
||||
'downloads_dir': self.build_default_downloads_dir(),
|
||||
'locale': None # this gets defined in fill_in_defaults()
|
||||
}
|
||||
self._settings = {}
|
||||
self.fill_in_defaults()
|
||||
@ -87,14 +108,26 @@ class Settings(object):
|
||||
if key not in self._settings:
|
||||
self._settings[key] = self.default_settings[key]
|
||||
|
||||
# Choose the default locale based on the OS preference, and fall-back to English
|
||||
if self._settings['locale'] is None:
|
||||
default_locale = locale.getdefaultlocale()[0][:2]
|
||||
if default_locale not in self.available_locales:
|
||||
default_locale = 'en'
|
||||
self._settings['locale'] = default_locale
|
||||
|
||||
def build_filename(self):
|
||||
"""
|
||||
Returns the path of the settings file.
|
||||
"""
|
||||
p = platform.system()
|
||||
if p == 'Windows':
|
||||
appdata = os.environ['APPDATA']
|
||||
return '{}\\OnionShare\\onionshare.json'.format(appdata)
|
||||
try:
|
||||
appdata = os.environ['APPDATA']
|
||||
return '{}\\OnionShare\\onionshare.json'.format(appdata)
|
||||
except:
|
||||
# If for some reason we don't have the 'APPDATA' environment variable
|
||||
# (like running tests in Linux while pretending to be in Windows)
|
||||
return os.path.expanduser('~/.config/onionshare/onionshare.json')
|
||||
elif p == 'Darwin':
|
||||
return os.path.expanduser('~/Library/Application Support/OnionShare/onionshare.json')
|
||||
else:
|
||||
@ -135,7 +168,7 @@ class Settings(object):
|
||||
except:
|
||||
pass
|
||||
open(self.filename, 'w').write(json.dumps(self._settings))
|
||||
print(strings._('settings_saved').format(self.filename))
|
||||
self.common.log('Settings', 'save', 'Settings saved in {}'.format(self.filename))
|
||||
|
||||
def get(self, key):
|
||||
return self._settings[key]
|
||||
|
@ -22,39 +22,36 @@ import locale
|
||||
import os
|
||||
|
||||
strings = {}
|
||||
translations = {}
|
||||
|
||||
|
||||
def load_strings(common, default="en"):
|
||||
def load_strings(common):
|
||||
"""
|
||||
Loads translated strings and fallback to English
|
||||
if the translation does not exist.
|
||||
"""
|
||||
global strings
|
||||
global strings, translations
|
||||
|
||||
# find locale dir
|
||||
locale_dir = common.get_resource_path('locale')
|
||||
|
||||
# load all translations
|
||||
# Load all translations
|
||||
translations = {}
|
||||
for filename in os.listdir(locale_dir):
|
||||
abs_filename = os.path.join(locale_dir, filename)
|
||||
lang, ext = os.path.splitext(filename)
|
||||
if ext == '.json':
|
||||
with open(abs_filename, encoding='utf-8') as f:
|
||||
translations[lang] = json.load(f)
|
||||
for locale in common.settings.available_locales:
|
||||
locale_dir = common.get_resource_path('locale')
|
||||
filename = os.path.join(locale_dir, "{}.json".format(locale))
|
||||
with open(filename, encoding='utf-8') as f:
|
||||
translations[locale] = json.load(f)
|
||||
|
||||
strings = translations[default]
|
||||
lc, enc = locale.getdefaultlocale()
|
||||
if lc:
|
||||
lang = lc[:2]
|
||||
if lang in translations:
|
||||
# if a string doesn't exist, fallback to English
|
||||
for key in translations[default]:
|
||||
if key in translations[lang]:
|
||||
strings[key] = translations[lang][key]
|
||||
# Build strings
|
||||
default_locale = 'en'
|
||||
current_locale = common.settings.get('locale')
|
||||
strings = {}
|
||||
for s in translations[default_locale]:
|
||||
if s in translations[current_locale]:
|
||||
strings[s] = translations[current_locale][s]
|
||||
else:
|
||||
strings[s] = translations[default_locale][s]
|
||||
|
||||
|
||||
def translated(k, gui=False):
|
||||
def translated(k):
|
||||
"""
|
||||
Returns a translated string.
|
||||
"""
|
||||
|
@ -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
|
||||
|
||||
|
||||
@ -61,17 +60,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')
|
||||
@ -88,7 +89,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"
|
||||
@ -100,7 +101,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:
|
||||
@ -111,7 +112,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:
|
||||
@ -126,6 +127,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)
|
||||
|
@ -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
|
||||
|
@ -59,7 +59,15 @@ def main():
|
||||
common = Common()
|
||||
common.define_css()
|
||||
|
||||
# Load the default settings and strings early, for the sake of being able to parse options.
|
||||
# These won't be in the user's chosen locale necessarily, but we need to parse them
|
||||
# early in order to even display the option to pass alternate settings (which might
|
||||
# contain a preferred locale).
|
||||
# If an alternate --config is passed, we'll reload strings later.
|
||||
common.load_settings()
|
||||
strings.load_strings(common)
|
||||
|
||||
# Display OnionShare banner
|
||||
print(strings._('version_string').format(common.version))
|
||||
|
||||
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
|
||||
@ -84,6 +92,10 @@ def main():
|
||||
filenames[i] = os.path.abspath(filenames[i])
|
||||
|
||||
config = args.config
|
||||
if config:
|
||||
# Re-load the strings, in case the provided config has changed locale
|
||||
common.load_settings(config)
|
||||
strings.load_strings(common)
|
||||
|
||||
local_only = bool(args.local_only)
|
||||
debug = bool(args.debug)
|
||||
@ -96,10 +108,10 @@ def main():
|
||||
valid = True
|
||||
for filename in filenames:
|
||||
if not os.path.isfile(filename) and not os.path.isdir(filename):
|
||||
Alert(common, strings._("not_a_file", True).format(filename))
|
||||
Alert(common, strings._("not_a_file").format(filename))
|
||||
valid = False
|
||||
if not os.access(filename, os.R_OK):
|
||||
Alert(common, strings._("not_a_readable_file", True).format(filename))
|
||||
Alert(common, strings._("not_a_readable_file").format(filename))
|
||||
valid = False
|
||||
if not valid:
|
||||
sys.exit()
|
||||
|
@ -22,9 +22,9 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
from onionshare import strings
|
||||
from onionshare.common import ShutdownTimer
|
||||
|
||||
from .server_status import ServerStatus
|
||||
from .threads import OnionThread
|
||||
from .widgets import Alert
|
||||
from ..server_status import ServerStatus
|
||||
from ..threads import OnionThread
|
||||
from ..widgets import Alert
|
||||
|
||||
class Mode(QtWidgets.QWidget):
|
||||
"""
|
||||
@ -49,8 +49,6 @@ class Mode(QtWidgets.QWidget):
|
||||
|
||||
self.filenames = filenames
|
||||
|
||||
self.setMinimumWidth(450)
|
||||
|
||||
# The web object gets created in init()
|
||||
self.web = None
|
||||
|
||||
@ -72,24 +70,17 @@ class Mode(QtWidgets.QWidget):
|
||||
self.starting_server_step3.connect(self.start_server_step3)
|
||||
self.starting_server_error.connect(self.start_server_error)
|
||||
|
||||
# Primary action layout
|
||||
# Primary action
|
||||
# Note: It's up to the downstream Mode to add this to its layout
|
||||
self.primary_action_layout = QtWidgets.QVBoxLayout()
|
||||
self.primary_action_layout.addWidget(self.server_status)
|
||||
self.primary_action = QtWidgets.QWidget()
|
||||
self.primary_action.setLayout(self.primary_action_layout)
|
||||
|
||||
# Layout
|
||||
self.layout = QtWidgets.QVBoxLayout()
|
||||
self.layout.addWidget(self.primary_action)
|
||||
# Hack to allow a minimum width on self.layout
|
||||
min_width_widget = QtWidgets.QWidget()
|
||||
min_width_widget.setMinimumWidth(450)
|
||||
self.layout.addWidget(min_width_widget)
|
||||
|
||||
self.horizontal_layout_wrapper = QtWidgets.QHBoxLayout()
|
||||
self.horizontal_layout_wrapper.addLayout(self.layout)
|
||||
|
||||
self.setLayout(self.horizontal_layout_wrapper)
|
||||
# Hack to allow a minimum width on the main layout
|
||||
# Note: It's up to the downstream Mode to add this to its layout
|
||||
self.min_width_widget = QtWidgets.QWidget()
|
||||
self.min_width_widget.setMinimumWidth(600)
|
||||
|
||||
def init(self):
|
||||
"""
|
||||
@ -333,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.
|
564
onionshare_gui/mode/history.py
Normal file
@ -0,0 +1,564 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OnionShare | https://onionshare.org/
|
||||
|
||||
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
import time
|
||||
import subprocess
|
||||
import os
|
||||
from datetime import datetime
|
||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from onionshare import strings
|
||||
from ..widgets import Alert
|
||||
|
||||
|
||||
class HistoryItem(QtWidgets.QWidget):
|
||||
"""
|
||||
The base history item
|
||||
"""
|
||||
def __init__(self):
|
||||
super(HistoryItem, self).__init__()
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
def cancel(self):
|
||||
pass
|
||||
|
||||
|
||||
class DownloadHistoryItem(HistoryItem):
|
||||
"""
|
||||
Download history item, for share mode
|
||||
"""
|
||||
def __init__(self, common, id, total_bytes):
|
||||
super(DownloadHistoryItem, self).__init__()
|
||||
self.common = common
|
||||
|
||||
self.id = id
|
||||
self.total_bytes = total_bytes
|
||||
self.downloaded_bytes = 0
|
||||
self.started = time.time()
|
||||
self.started_dt = datetime.fromtimestamp(self.started)
|
||||
|
||||
# Label
|
||||
self.label = QtWidgets.QLabel(strings._('gui_download_in_progress').format(self.started_dt.strftime("%b %d, %I:%M%p")))
|
||||
|
||||
# Progress bar
|
||||
self.progress_bar = QtWidgets.QProgressBar()
|
||||
self.progress_bar.setTextVisible(True)
|
||||
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||
self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
self.progress_bar.setMinimum(0)
|
||||
self.progress_bar.setMaximum(total_bytes)
|
||||
self.progress_bar.setValue(0)
|
||||
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
||||
self.progress_bar.total_bytes = total_bytes
|
||||
|
||||
# Layout
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
layout.addWidget(self.label)
|
||||
layout.addWidget(self.progress_bar)
|
||||
self.setLayout(layout)
|
||||
|
||||
# Start at 0
|
||||
self.update(0)
|
||||
|
||||
def update(self, downloaded_bytes):
|
||||
self.downloaded_bytes = downloaded_bytes
|
||||
|
||||
self.progress_bar.setValue(downloaded_bytes)
|
||||
if downloaded_bytes == self.progress_bar.total_bytes:
|
||||
pb_fmt = strings._('gui_download_upload_progress_complete').format(
|
||||
self.common.format_seconds(time.time() - self.started))
|
||||
else:
|
||||
elapsed = time.time() - self.started
|
||||
if elapsed < 10:
|
||||
# Wait a couple of seconds for the download rate to stabilize.
|
||||
# This prevents a "Windows copy dialog"-esque experience at
|
||||
# the beginning of the download.
|
||||
pb_fmt = strings._('gui_download_upload_progress_starting').format(
|
||||
self.common.human_readable_filesize(downloaded_bytes))
|
||||
else:
|
||||
pb_fmt = strings._('gui_download_upload_progress_eta').format(
|
||||
self.common.human_readable_filesize(downloaded_bytes),
|
||||
self.estimated_time_remaining)
|
||||
|
||||
self.progress_bar.setFormat(pb_fmt)
|
||||
|
||||
def cancel(self):
|
||||
self.progress_bar.setFormat(strings._('gui_canceled'))
|
||||
|
||||
@property
|
||||
def estimated_time_remaining(self):
|
||||
return self.common.estimated_time_remaining(self.downloaded_bytes,
|
||||
self.total_bytes,
|
||||
self.started)
|
||||
|
||||
|
||||
class UploadHistoryItemFile(QtWidgets.QWidget):
|
||||
def __init__(self, common, filename):
|
||||
super(UploadHistoryItemFile, self).__init__()
|
||||
self.common = common
|
||||
|
||||
self.common.log('UploadHistoryItemFile', '__init__', 'filename: {}'.format(filename))
|
||||
|
||||
self.filename = filename
|
||||
self.dir = None
|
||||
self.started = datetime.now()
|
||||
|
||||
# Filename label
|
||||
self.filename_label = QtWidgets.QLabel(self.filename)
|
||||
self.filename_label_width = self.filename_label.width()
|
||||
|
||||
# File size label
|
||||
self.filesize_label = QtWidgets.QLabel()
|
||||
self.filesize_label.setStyleSheet(self.common.css['receive_file_size'])
|
||||
self.filesize_label.hide()
|
||||
|
||||
# Folder button
|
||||
folder_pixmap = QtGui.QPixmap.fromImage(QtGui.QImage(self.common.get_resource_path('images/open_folder.png')))
|
||||
folder_icon = QtGui.QIcon(folder_pixmap)
|
||||
self.folder_button = QtWidgets.QPushButton()
|
||||
self.folder_button.clicked.connect(self.open_folder)
|
||||
self.folder_button.setIcon(folder_icon)
|
||||
self.folder_button.setIconSize(folder_pixmap.rect().size())
|
||||
self.folder_button.setFlat(True)
|
||||
self.folder_button.hide()
|
||||
|
||||
# Layouts
|
||||
layout = QtWidgets.QHBoxLayout()
|
||||
layout.addWidget(self.filename_label)
|
||||
layout.addWidget(self.filesize_label)
|
||||
layout.addStretch()
|
||||
layout.addWidget(self.folder_button)
|
||||
self.setLayout(layout)
|
||||
|
||||
def update(self, uploaded_bytes, complete):
|
||||
self.filesize_label.setText(self.common.human_readable_filesize(uploaded_bytes))
|
||||
self.filesize_label.show()
|
||||
|
||||
if complete:
|
||||
self.folder_button.show()
|
||||
|
||||
def rename(self, new_filename):
|
||||
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')
|
||||
|
||||
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':
|
||||
try:
|
||||
# If nautilus is available, open it
|
||||
subprocess.Popen(['nautilus', abs_filename])
|
||||
except:
|
||||
Alert(self.common, strings._('gui_open_folder_error_nautilus').format(abs_filename))
|
||||
|
||||
# macOS
|
||||
elif self.common.platform == 'Darwin':
|
||||
# TODO: Implement opening folder with file selected in macOS
|
||||
# This seems helpful: https://stackoverflow.com/questions/3520493/python-show-in-finder
|
||||
self.common.log('UploadHistoryItemFile', 'open_folder', 'not implemented for Darwin yet')
|
||||
|
||||
# Windows
|
||||
elif self.common.platform == 'Windows':
|
||||
# TODO: Implement opening folder with file selected in Windows
|
||||
# This seems helpful: https://stackoverflow.com/questions/6631299/python-opening-a-folder-in-explorer-nautilus-mac-thingie
|
||||
self.common.log('UploadHistoryItemFile', 'open_folder', 'not implemented for Windows yet')
|
||||
|
||||
|
||||
class UploadHistoryItem(HistoryItem):
|
||||
def __init__(self, common, id, content_length):
|
||||
super(UploadHistoryItem, self).__init__()
|
||||
self.common = common
|
||||
self.id = id
|
||||
self.content_length = content_length
|
||||
self.started = datetime.now()
|
||||
|
||||
# Label
|
||||
self.label = QtWidgets.QLabel(strings._('gui_upload_in_progress').format(self.started.strftime("%b %d, %I:%M%p")))
|
||||
|
||||
# Progress bar
|
||||
self.progress_bar = QtWidgets.QProgressBar()
|
||||
self.progress_bar.setTextVisible(True)
|
||||
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||
self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
self.progress_bar.setMinimum(0)
|
||||
self.progress_bar.setValue(0)
|
||||
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
||||
|
||||
# This layout contains file widgets
|
||||
self.files_layout = QtWidgets.QVBoxLayout()
|
||||
self.files_layout.setContentsMargins(0, 0, 0, 0)
|
||||
files_widget = QtWidgets.QWidget()
|
||||
files_widget.setStyleSheet(self.common.css['receive_file'])
|
||||
files_widget.setLayout(self.files_layout)
|
||||
|
||||
# Layout
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
layout.addWidget(self.label)
|
||||
layout.addWidget(self.progress_bar)
|
||||
layout.addWidget(files_widget)
|
||||
layout.addStretch()
|
||||
self.setLayout(layout)
|
||||
|
||||
# We're also making a dictionary of file widgets, to make them easier to access
|
||||
self.files = {}
|
||||
|
||||
def update(self, data):
|
||||
"""
|
||||
Using the progress from Web, update the progress bar and file size labels
|
||||
for each file
|
||||
"""
|
||||
if data['action'] == 'progress':
|
||||
total_uploaded_bytes = 0
|
||||
for filename in data['progress']:
|
||||
total_uploaded_bytes += data['progress'][filename]['uploaded_bytes']
|
||||
|
||||
# Update the progress bar
|
||||
self.progress_bar.setMaximum(self.content_length)
|
||||
self.progress_bar.setValue(total_uploaded_bytes)
|
||||
|
||||
elapsed = datetime.now() - self.started
|
||||
if elapsed.seconds < 10:
|
||||
pb_fmt = strings._('gui_download_upload_progress_starting').format(
|
||||
self.common.human_readable_filesize(total_uploaded_bytes))
|
||||
else:
|
||||
estimated_time_remaining = self.common.estimated_time_remaining(
|
||||
total_uploaded_bytes,
|
||||
self.content_length,
|
||||
self.started.timestamp())
|
||||
pb_fmt = strings._('gui_download_upload_progress_eta').format(
|
||||
self.common.human_readable_filesize(total_uploaded_bytes),
|
||||
estimated_time_remaining)
|
||||
|
||||
# Using list(progress) to avoid "RuntimeError: dictionary changed size during iteration"
|
||||
for filename in list(data['progress']):
|
||||
# Add a new file if needed
|
||||
if filename not in self.files:
|
||||
self.files[filename] = UploadHistoryItemFile(self.common, filename)
|
||||
self.files_layout.addWidget(self.files[filename])
|
||||
|
||||
# Update the file
|
||||
self.files[filename].update(data['progress'][filename]['uploaded_bytes'], data['progress'][filename]['complete'])
|
||||
|
||||
elif data['action'] == 'rename':
|
||||
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()
|
||||
|
||||
# Change the label
|
||||
self.ended = self.started = datetime.now()
|
||||
if self.started.year == self.ended.year and self.started.month == self.ended.month and self.started.day == self.ended.day:
|
||||
if self.started.hour == self.ended.hour and self.started.minute == self.ended.minute:
|
||||
text = strings._('gui_upload_finished').format(
|
||||
self.started.strftime("%b %d, %I:%M%p")
|
||||
)
|
||||
else:
|
||||
text = strings._('gui_upload_finished_range').format(
|
||||
self.started.strftime("%b %d, %I:%M%p"),
|
||||
self.ended.strftime("%I:%M%p")
|
||||
)
|
||||
else:
|
||||
text = strings._('gui_upload_finished_range').format(
|
||||
self.started.strftime("%b %d, %I:%M%p"),
|
||||
self.ended.strftime("%b %d, %I:%M%p")
|
||||
)
|
||||
self.label.setText(text)
|
||||
|
||||
|
||||
class HistoryItemList(QtWidgets.QScrollArea):
|
||||
"""
|
||||
List of items
|
||||
"""
|
||||
def __init__(self, common):
|
||||
super(HistoryItemList, self).__init__()
|
||||
self.common = common
|
||||
|
||||
self.items = {}
|
||||
|
||||
# The layout that holds all of the items
|
||||
self.items_layout = QtWidgets.QVBoxLayout()
|
||||
self.items_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.items_layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
|
||||
|
||||
# Wrapper layout that also contains a stretch
|
||||
wrapper_layout = QtWidgets.QVBoxLayout()
|
||||
wrapper_layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
|
||||
wrapper_layout.addLayout(self.items_layout)
|
||||
wrapper_layout.addStretch()
|
||||
|
||||
# The internal widget of the scroll area
|
||||
widget = QtWidgets.QWidget()
|
||||
widget.setLayout(wrapper_layout)
|
||||
self.setWidget(widget)
|
||||
self.setWidgetResizable(True)
|
||||
|
||||
# Other scroll area settings
|
||||
self.setBackgroundRole(QtGui.QPalette.Light)
|
||||
self.verticalScrollBar().rangeChanged.connect(self.resizeScroll)
|
||||
|
||||
def resizeScroll(self, minimum, maximum):
|
||||
"""
|
||||
Scroll to the bottom of the window when the range changes.
|
||||
"""
|
||||
self.verticalScrollBar().setValue(maximum)
|
||||
|
||||
def add(self, id, item):
|
||||
"""
|
||||
Add a new item. Override this method.
|
||||
"""
|
||||
self.items[id] = item
|
||||
self.items_layout.addWidget(item)
|
||||
|
||||
def update(self, id, data):
|
||||
"""
|
||||
Update an item. Override this method.
|
||||
"""
|
||||
self.items[id].update(data)
|
||||
|
||||
def cancel(self, id):
|
||||
"""
|
||||
Cancel an item. Override this method.
|
||||
"""
|
||||
self.items[id].cancel()
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Reset all items, emptying the list. Override this method.
|
||||
"""
|
||||
for item in self.items.values():
|
||||
self.items_layout.removeWidget(item)
|
||||
item.close()
|
||||
self.items = {}
|
||||
|
||||
|
||||
class History(QtWidgets.QWidget):
|
||||
"""
|
||||
A history of what's happened so far in this mode. This contains an internal
|
||||
object full of a scrollable list of items.
|
||||
"""
|
||||
def __init__(self, common, empty_image, empty_text, header_text):
|
||||
super(History, self).__init__()
|
||||
self.common = common
|
||||
|
||||
self.setMinimumWidth(350)
|
||||
|
||||
# In progress and completed counters
|
||||
self.in_progress_count = 0
|
||||
self.completed_count = 0
|
||||
|
||||
# In progress and completed labels
|
||||
self.in_progress_label = QtWidgets.QLabel()
|
||||
self.in_progress_label.setStyleSheet(self.common.css['mode_info_label'])
|
||||
self.completed_label = QtWidgets.QLabel()
|
||||
self.completed_label.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
# Header
|
||||
self.header_label = QtWidgets.QLabel(header_text)
|
||||
self.header_label.setStyleSheet(self.common.css['downloads_uploads_label'])
|
||||
clear_button = QtWidgets.QPushButton(strings._('gui_clear_history'))
|
||||
clear_button.setStyleSheet(self.common.css['downloads_uploads_clear'])
|
||||
clear_button.setFlat(True)
|
||||
clear_button.clicked.connect(self.reset)
|
||||
header_layout = QtWidgets.QHBoxLayout()
|
||||
header_layout.addWidget(self.header_label)
|
||||
header_layout.addStretch()
|
||||
header_layout.addWidget(self.in_progress_label)
|
||||
header_layout.addWidget(self.completed_label)
|
||||
header_layout.addWidget(clear_button)
|
||||
|
||||
# When there are no items
|
||||
self.empty_image = QtWidgets.QLabel()
|
||||
self.empty_image.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.empty_image.setPixmap(empty_image)
|
||||
self.empty_text = QtWidgets.QLabel(empty_text)
|
||||
self.empty_text.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.empty_text.setStyleSheet(self.common.css['downloads_uploads_empty_text'])
|
||||
empty_layout = QtWidgets.QVBoxLayout()
|
||||
empty_layout.addStretch()
|
||||
empty_layout.addWidget(self.empty_image)
|
||||
empty_layout.addWidget(self.empty_text)
|
||||
empty_layout.addStretch()
|
||||
self.empty = QtWidgets.QWidget()
|
||||
self.empty.setStyleSheet(self.common.css['downloads_uploads_empty'])
|
||||
self.empty.setLayout(empty_layout)
|
||||
|
||||
# When there are items
|
||||
self.item_list = HistoryItemList(self.common)
|
||||
self.not_empty_layout = QtWidgets.QVBoxLayout()
|
||||
self.not_empty_layout.addLayout(header_layout)
|
||||
self.not_empty_layout.addWidget(self.item_list)
|
||||
self.not_empty = QtWidgets.QWidget()
|
||||
self.not_empty.setLayout(self.not_empty_layout)
|
||||
|
||||
# Layout
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.addWidget(self.empty)
|
||||
layout.addWidget(self.not_empty)
|
||||
self.setLayout(layout)
|
||||
|
||||
# Reset once at the beginning
|
||||
self.reset()
|
||||
|
||||
def add(self, id, item):
|
||||
"""
|
||||
Add a new item.
|
||||
"""
|
||||
self.common.log('History', 'add', 'id: {}, item: {}'.format(id, item))
|
||||
|
||||
# Hide empty, show not empty
|
||||
self.empty.hide()
|
||||
self.not_empty.show()
|
||||
|
||||
# Add it to the list
|
||||
self.item_list.add(id, item)
|
||||
|
||||
def update(self, id, data):
|
||||
"""
|
||||
Update an item.
|
||||
"""
|
||||
self.item_list.update(id, data)
|
||||
|
||||
def cancel(self, id):
|
||||
"""
|
||||
Cancel an item.
|
||||
"""
|
||||
self.item_list.cancel(id)
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Reset all items.
|
||||
"""
|
||||
self.item_list.reset()
|
||||
|
||||
# Hide not empty, show empty
|
||||
self.not_empty.hide()
|
||||
self.empty.show()
|
||||
|
||||
# Reset counters
|
||||
self.completed_count = 0
|
||||
self.in_progress_count = 0
|
||||
self.update_completed()
|
||||
self.update_in_progress()
|
||||
|
||||
def update_completed(self):
|
||||
"""
|
||||
Update the 'completed' widget.
|
||||
"""
|
||||
if self.completed_count == 0:
|
||||
image = self.common.get_resource_path('images/share_completed_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_completed.png')
|
||||
self.completed_label.setText('<img src="{0:s}" /> {1:d}'.format(image, self.completed_count))
|
||||
self.completed_label.setToolTip(strings._('history_completed_tooltip').format(self.completed_count))
|
||||
|
||||
def update_in_progress(self):
|
||||
"""
|
||||
Update the 'in progress' widget.
|
||||
"""
|
||||
if self.in_progress_count == 0:
|
||||
image = self.common.get_resource_path('images/share_in_progress_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_in_progress.png')
|
||||
self.in_progress_label.setText('<img src="{0:s}" /> {1:d}'.format(image, self.in_progress_count))
|
||||
self.in_progress_label.setToolTip(strings._('history_in_progress_tooltip').format(self.in_progress_count))
|
||||
|
||||
|
||||
class ToggleHistory(QtWidgets.QPushButton):
|
||||
"""
|
||||
Widget for toggling showing or hiding the history, as well as keeping track
|
||||
of the indicator counter if it's hidden
|
||||
"""
|
||||
def __init__(self, common, current_mode, history_widget, icon, selected_icon):
|
||||
super(ToggleHistory, self).__init__()
|
||||
self.common = common
|
||||
self.current_mode = current_mode
|
||||
self.history_widget = history_widget
|
||||
self.icon = icon
|
||||
self.selected_icon = selected_icon
|
||||
|
||||
# Toggle button
|
||||
self.setDefault(False)
|
||||
self.setFixedWidth(35)
|
||||
self.setFixedHeight(30)
|
||||
self.setFlat(True)
|
||||
self.setIcon(icon)
|
||||
self.clicked.connect(self.toggle_clicked)
|
||||
|
||||
# Keep track of indicator
|
||||
self.indicator_count = 0
|
||||
self.indicator_label = QtWidgets.QLabel(parent=self)
|
||||
self.indicator_label.setStyleSheet(self.common.css['download_uploads_indicator'])
|
||||
self.update_indicator()
|
||||
|
||||
def update_indicator(self, increment=False):
|
||||
"""
|
||||
Update the display of the indicator count. If increment is True, then
|
||||
only increment the counter if Downloads is hidden.
|
||||
"""
|
||||
if increment and not self.history_widget.isVisible():
|
||||
self.indicator_count += 1
|
||||
|
||||
self.indicator_label.setText("{}".format(self.indicator_count))
|
||||
|
||||
if self.indicator_count == 0:
|
||||
self.indicator_label.hide()
|
||||
else:
|
||||
size = self.indicator_label.sizeHint()
|
||||
self.indicator_label.setGeometry(35-size.width(), 0, size.width(), size.height())
|
||||
self.indicator_label.show()
|
||||
|
||||
def toggle_clicked(self):
|
||||
"""
|
||||
Toggle showing and hiding the history widget
|
||||
"""
|
||||
self.common.log('ToggleHistory', 'toggle_clicked')
|
||||
|
||||
if self.history_widget.isVisible():
|
||||
self.history_widget.hide()
|
||||
self.setIcon(self.icon)
|
||||
self.setFlat(True)
|
||||
else:
|
||||
self.history_widget.show()
|
||||
self.setIcon(self.selected_icon)
|
||||
self.setFlat(False)
|
||||
|
||||
# Reset the indicator count
|
||||
self.indicator_count = 0
|
||||
self.update_indicator()
|
206
onionshare_gui/mode/receive_mode/__init__.py
Normal file
@ -0,0 +1,206 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OnionShare | https://onionshare.org/
|
||||
|
||||
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from onionshare import strings
|
||||
from onionshare.web import Web
|
||||
|
||||
from ..history import History, ToggleHistory, UploadHistoryItem
|
||||
from .. import Mode
|
||||
|
||||
class ReceiveMode(Mode):
|
||||
"""
|
||||
Parts of the main window UI for receiving files.
|
||||
"""
|
||||
def init(self):
|
||||
"""
|
||||
Custom initialization for ReceiveMode.
|
||||
"""
|
||||
# Create the Web object
|
||||
self.web = Web(self.common, True, 'receive')
|
||||
|
||||
# Server status
|
||||
self.server_status.set_mode('receive')
|
||||
self.server_status.server_started_finished.connect(self.update_primary_action)
|
||||
self.server_status.server_stopped.connect(self.update_primary_action)
|
||||
self.server_status.server_canceled.connect(self.update_primary_action)
|
||||
|
||||
# Tell server_status about web, then update
|
||||
self.server_status.web = self.web
|
||||
self.server_status.update()
|
||||
|
||||
# Upload history
|
||||
self.history = History(
|
||||
self.common,
|
||||
QtGui.QPixmap.fromImage(QtGui.QImage(self.common.get_resource_path('images/uploads_transparent.png'))),
|
||||
strings._('gui_no_uploads'),
|
||||
strings._('gui_uploads')
|
||||
)
|
||||
self.history.hide()
|
||||
|
||||
# Toggle history
|
||||
self.toggle_history = ToggleHistory(
|
||||
self.common, self, self.history,
|
||||
QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle.png')),
|
||||
QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle_selected.png'))
|
||||
)
|
||||
|
||||
# Receive mode warning
|
||||
receive_warning = QtWidgets.QLabel(strings._('gui_receive_mode_warning'))
|
||||
receive_warning.setMinimumHeight(80)
|
||||
receive_warning.setWordWrap(True)
|
||||
|
||||
# Top bar
|
||||
top_bar_layout = QtWidgets.QHBoxLayout()
|
||||
top_bar_layout.addStretch()
|
||||
top_bar_layout.addWidget(self.toggle_history)
|
||||
|
||||
# Main layout
|
||||
self.main_layout = QtWidgets.QVBoxLayout()
|
||||
self.main_layout.addLayout(top_bar_layout)
|
||||
self.main_layout.addWidget(receive_warning)
|
||||
self.main_layout.addWidget(self.primary_action)
|
||||
self.main_layout.addStretch()
|
||||
self.main_layout.addWidget(self.min_width_widget)
|
||||
|
||||
# Wrapper layout
|
||||
self.wrapper_layout = QtWidgets.QHBoxLayout()
|
||||
self.wrapper_layout.addLayout(self.main_layout)
|
||||
self.wrapper_layout.addWidget(self.history)
|
||||
self.setLayout(self.wrapper_layout)
|
||||
|
||||
def get_stop_server_shutdown_timeout_text(self):
|
||||
"""
|
||||
Return the string to put on the stop server button, if there's a shutdown timeout
|
||||
"""
|
||||
return strings._('gui_receive_stop_server_shutdown_timeout')
|
||||
|
||||
def timeout_finished_should_stop_server(self):
|
||||
"""
|
||||
The shutdown timer expired, should we stop the server? Returns a bool
|
||||
"""
|
||||
# TODO: wait until the final upload is done before stoppign the server?
|
||||
return True
|
||||
|
||||
def start_server_custom(self):
|
||||
"""
|
||||
Starting the server.
|
||||
"""
|
||||
# Reset web counters
|
||||
self.web.receive_mode.upload_count = 0
|
||||
self.web.error404_count = 0
|
||||
|
||||
# Hide and reset the uploads if we have previously shared
|
||||
self.reset_info_counters()
|
||||
|
||||
def start_server_step2_custom(self):
|
||||
"""
|
||||
Step 2 in starting the server.
|
||||
"""
|
||||
# Continue
|
||||
self.starting_server_step3.emit()
|
||||
self.start_server_finished.emit()
|
||||
|
||||
def handle_tor_broke_custom(self):
|
||||
"""
|
||||
Connection to Tor broke.
|
||||
"""
|
||||
self.primary_action.hide()
|
||||
|
||||
def handle_request_load(self, event):
|
||||
"""
|
||||
Handle REQUEST_LOAD event.
|
||||
"""
|
||||
self.system_tray.showMessage(strings._('systray_page_loaded_title'), strings._('systray_upload_page_loaded_message'))
|
||||
|
||||
def handle_request_started(self, event):
|
||||
"""
|
||||
Handle REQUEST_STARTED event.
|
||||
"""
|
||||
item = UploadHistoryItem(self.common, event["data"]["id"], event["data"]["content_length"])
|
||||
self.history.add(event["data"]["id"], item)
|
||||
self.toggle_history.update_indicator(True)
|
||||
self.history.in_progress_count += 1
|
||||
self.history.update_in_progress()
|
||||
|
||||
self.system_tray.showMessage(strings._('systray_upload_started_title'), strings._('systray_upload_started_message'))
|
||||
|
||||
def handle_request_progress(self, event):
|
||||
"""
|
||||
Handle REQUEST_PROGRESS event.
|
||||
"""
|
||||
self.history.update(event["data"]["id"], {
|
||||
'action': 'progress',
|
||||
'progress': event["data"]["progress"]
|
||||
})
|
||||
|
||||
def handle_request_close_server(self, event):
|
||||
"""
|
||||
Handle REQUEST_CLOSE_SERVER event.
|
||||
"""
|
||||
self.stop_server()
|
||||
self.system_tray.showMessage(strings._('systray_close_server_title'), strings._('systray_close_server_message'))
|
||||
|
||||
def handle_request_upload_file_renamed(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_FILE_RENAMED event.
|
||||
"""
|
||||
self.history.update(event["data"]["id"], {
|
||||
'action': 'rename',
|
||||
'old_filename': event["data"]["old_filename"],
|
||||
'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.
|
||||
"""
|
||||
self.history.update(event["data"]["id"], {
|
||||
'action': 'finished'
|
||||
})
|
||||
self.history.completed_count += 1
|
||||
self.history.in_progress_count -= 1
|
||||
self.history.update_completed()
|
||||
self.history.update_in_progress()
|
||||
|
||||
def on_reload_settings(self):
|
||||
"""
|
||||
We should be ok to re-enable the 'Start Receive Mode' button now.
|
||||
"""
|
||||
self.primary_action.show()
|
||||
|
||||
def reset_info_counters(self):
|
||||
"""
|
||||
Set the info counters back to zero.
|
||||
"""
|
||||
self.history.reset()
|
||||
|
||||
def update_primary_action(self):
|
||||
self.common.log('ReceiveMode', 'update_primary_action')
|
@ -26,10 +26,11 @@ from onionshare.common import Common
|
||||
from onionshare.web import Web
|
||||
|
||||
from .file_selection import FileSelection
|
||||
from .downloads import Downloads
|
||||
from .threads import CompressThread
|
||||
from ..mode import Mode
|
||||
from ..widgets import Alert
|
||||
from .. import Mode
|
||||
from ..history import History, ToggleHistory, DownloadHistoryItem
|
||||
from ...widgets import Alert
|
||||
|
||||
|
||||
class ShareMode(Mode):
|
||||
"""
|
||||
@ -70,33 +71,31 @@ class ShareMode(Mode):
|
||||
self.filesize_warning.setStyleSheet(self.common.css['share_filesize_warning'])
|
||||
self.filesize_warning.hide()
|
||||
|
||||
# Downloads
|
||||
self.downloads = Downloads(self.common)
|
||||
self.downloads_in_progress = 0
|
||||
self.downloads_completed = 0
|
||||
# Download history
|
||||
self.history = History(
|
||||
self.common,
|
||||
QtGui.QPixmap.fromImage(QtGui.QImage(self.common.get_resource_path('images/downloads_transparent.png'))),
|
||||
strings._('gui_no_downloads'),
|
||||
strings._('gui_downloads')
|
||||
)
|
||||
self.history.hide()
|
||||
|
||||
# Information about share, and show downloads button
|
||||
# Info label
|
||||
self.info_label = QtWidgets.QLabel()
|
||||
self.info_label.setStyleSheet(self.common.css['mode_info_label'])
|
||||
self.info_label.hide()
|
||||
|
||||
self.info_in_progress_downloads_count = QtWidgets.QLabel()
|
||||
self.info_in_progress_downloads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
# Toggle history
|
||||
self.toggle_history = ToggleHistory(
|
||||
self.common, self, self.history,
|
||||
QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')),
|
||||
QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png'))
|
||||
)
|
||||
|
||||
self.info_completed_downloads_count = QtWidgets.QLabel()
|
||||
self.info_completed_downloads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
self.update_downloads_completed()
|
||||
self.update_downloads_in_progress()
|
||||
|
||||
self.info_layout = QtWidgets.QHBoxLayout()
|
||||
self.info_layout.addWidget(self.info_label)
|
||||
self.info_layout.addStretch()
|
||||
self.info_layout.addWidget(self.info_in_progress_downloads_count)
|
||||
self.info_layout.addWidget(self.info_completed_downloads_count)
|
||||
|
||||
self.info_widget = QtWidgets.QWidget()
|
||||
self.info_widget.setLayout(self.info_layout)
|
||||
self.info_widget.hide()
|
||||
# Top bar
|
||||
top_bar_layout = QtWidgets.QHBoxLayout()
|
||||
top_bar_layout.addWidget(self.info_label)
|
||||
top_bar_layout.addStretch()
|
||||
top_bar_layout.addWidget(self.toggle_history)
|
||||
|
||||
# Primary action layout
|
||||
self.primary_action_layout.addWidget(self.filesize_warning)
|
||||
@ -106,10 +105,18 @@ class ShareMode(Mode):
|
||||
# Status bar, zip progress bar
|
||||
self._zip_progress_bar = None
|
||||
|
||||
# Layout
|
||||
self.layout.insertLayout(0, self.file_selection)
|
||||
self.layout.insertWidget(0, self.info_widget)
|
||||
self.horizontal_layout_wrapper.addWidget(self.downloads)
|
||||
# Main layout
|
||||
self.main_layout = QtWidgets.QVBoxLayout()
|
||||
self.main_layout.addLayout(top_bar_layout)
|
||||
self.main_layout.addLayout(self.file_selection)
|
||||
self.main_layout.addWidget(self.primary_action)
|
||||
self.main_layout.addWidget(self.min_width_widget)
|
||||
|
||||
# Wrapper layout
|
||||
self.wrapper_layout = QtWidgets.QHBoxLayout()
|
||||
self.wrapper_layout.addLayout(self.main_layout)
|
||||
self.wrapper_layout.addWidget(self.history)
|
||||
self.setLayout(self.wrapper_layout)
|
||||
|
||||
# Always start with focus on file selection
|
||||
self.file_selection.setFocus()
|
||||
@ -118,7 +125,7 @@ class ShareMode(Mode):
|
||||
"""
|
||||
Return the string to put on the stop server button, if there's a shutdown timeout
|
||||
"""
|
||||
return strings._('gui_share_stop_server_shutdown_timeout', True)
|
||||
return strings._('gui_share_stop_server_shutdown_timeout')
|
||||
|
||||
def timeout_finished_should_stop_server(self):
|
||||
"""
|
||||
@ -127,11 +134,11 @@ class ShareMode(Mode):
|
||||
# If there were no attempts to download the share, or all downloads are done, we can stop
|
||||
if self.web.share_mode.download_count == 0 or self.web.done:
|
||||
self.server_status.stop_server()
|
||||
self.server_status_label.setText(strings._('close_on_timeout', True))
|
||||
self.server_status_label.setText(strings._('close_on_timeout'))
|
||||
return True
|
||||
# A download is probably still running - hold off on stopping the share
|
||||
else:
|
||||
self.server_status_label.setText(strings._('timeout_download_still_running', True))
|
||||
self.server_status_label.setText(strings._('timeout_download_still_running'))
|
||||
return False
|
||||
|
||||
def start_server_custom(self):
|
||||
@ -178,7 +185,7 @@ class ShareMode(Mode):
|
||||
|
||||
# Warn about sending large files over Tor
|
||||
if self.web.share_mode.download_filesize >= 157286400: # 150mb
|
||||
self.filesize_warning.setText(strings._("large_filesize", True))
|
||||
self.filesize_warning.setText(strings._("large_filesize"))
|
||||
self.filesize_warning.show()
|
||||
|
||||
def start_server_error_custom(self):
|
||||
@ -199,9 +206,9 @@ class ShareMode(Mode):
|
||||
self._zip_progress_bar = None
|
||||
|
||||
self.filesize_warning.hide()
|
||||
self.downloads_in_progress = 0
|
||||
self.downloads_completed = 0
|
||||
self.update_downloads_in_progress()
|
||||
self.history.in_progress_count = 0
|
||||
self.history.completed_count = 0
|
||||
self.history.update_in_progress()
|
||||
self.file_selection.file_list.adjustSize()
|
||||
|
||||
def cancel_server_custom(self):
|
||||
@ -209,7 +216,7 @@ class ShareMode(Mode):
|
||||
Stop the compression thread on cancel
|
||||
"""
|
||||
if self.compress_thread:
|
||||
self.common.log('OnionShareGui', 'cancel_server: quitting compress thread')
|
||||
self.common.log('ShareMode', 'cancel_server: quitting compress thread')
|
||||
self.compress_thread.quit()
|
||||
|
||||
def handle_tor_broke_custom(self):
|
||||
@ -217,13 +224,12 @@ class ShareMode(Mode):
|
||||
Connection to Tor broke.
|
||||
"""
|
||||
self.primary_action.hide()
|
||||
self.info_widget.hide()
|
||||
|
||||
def handle_request_load(self, event):
|
||||
"""
|
||||
Handle REQUEST_LOAD event.
|
||||
"""
|
||||
self.system_tray.showMessage(strings._('systray_page_loaded_title', True), strings._('systray_download_page_loaded_message', True))
|
||||
self.system_tray.showMessage(strings._('systray_page_loaded_title'), strings._('systray_download_page_loaded_message'))
|
||||
|
||||
def handle_request_started(self, event):
|
||||
"""
|
||||
@ -233,50 +239,52 @@ class ShareMode(Mode):
|
||||
filesize = self.web.share_mode.gzip_filesize
|
||||
else:
|
||||
filesize = self.web.share_mode.download_filesize
|
||||
self.downloads.add(event["data"]["id"], filesize)
|
||||
self.downloads_in_progress += 1
|
||||
self.update_downloads_in_progress()
|
||||
|
||||
self.system_tray.showMessage(strings._('systray_download_started_title', True), strings._('systray_download_started_message', True))
|
||||
item = DownloadHistoryItem(self.common, event["data"]["id"], filesize)
|
||||
self.history.add(event["data"]["id"], item)
|
||||
self.toggle_history.update_indicator(True)
|
||||
self.history.in_progress_count += 1
|
||||
self.history.update_in_progress()
|
||||
|
||||
self.system_tray.showMessage(strings._('systray_download_started_title'), strings._('systray_download_started_message'))
|
||||
|
||||
def handle_request_progress(self, event):
|
||||
"""
|
||||
Handle REQUEST_PROGRESS event.
|
||||
"""
|
||||
self.downloads.update(event["data"]["id"], event["data"]["bytes"])
|
||||
self.history.update(event["data"]["id"], event["data"]["bytes"])
|
||||
|
||||
# Is the download complete?
|
||||
if event["data"]["bytes"] == self.web.share_mode.filesize:
|
||||
self.system_tray.showMessage(strings._('systray_download_completed_title', True), strings._('systray_download_completed_message', True))
|
||||
self.system_tray.showMessage(strings._('systray_download_completed_title'), strings._('systray_download_completed_message'))
|
||||
|
||||
# Update the total 'completed downloads' info
|
||||
self.downloads_completed += 1
|
||||
self.update_downloads_completed()
|
||||
# Update the 'in progress downloads' info
|
||||
self.downloads_in_progress -= 1
|
||||
self.update_downloads_in_progress()
|
||||
# Update completed and in progress labels
|
||||
self.history.completed_count += 1
|
||||
self.history.in_progress_count -= 1
|
||||
self.history.update_completed()
|
||||
self.history.update_in_progress()
|
||||
|
||||
# Close on finish?
|
||||
if self.common.settings.get('close_after_first_download'):
|
||||
self.server_status.stop_server()
|
||||
self.status_bar.clearMessage()
|
||||
self.server_status_label.setText(strings._('closing_automatically', True))
|
||||
self.server_status_label.setText(strings._('closing_automatically'))
|
||||
else:
|
||||
if self.server_status.status == self.server_status.STATUS_STOPPED:
|
||||
self.downloads.cancel(event["data"]["id"])
|
||||
self.downloads_in_progress = 0
|
||||
self.update_downloads_in_progress()
|
||||
self.history.cancel(event["data"]["id"])
|
||||
self.history.in_progress_count = 0
|
||||
self.history.update_in_progress()
|
||||
|
||||
def handle_request_canceled(self, event):
|
||||
"""
|
||||
Handle REQUEST_CANCELED event.
|
||||
"""
|
||||
self.downloads.cancel(event["data"]["id"])
|
||||
self.history.cancel(event["data"]["id"])
|
||||
|
||||
# Update the 'in progress downloads' info
|
||||
self.downloads_in_progress -= 1
|
||||
self.update_downloads_in_progress()
|
||||
self.system_tray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True))
|
||||
# Update in progress count
|
||||
self.history.in_progress_count -= 1
|
||||
self.history.update_in_progress()
|
||||
self.system_tray.showMessage(strings._('systray_download_canceled_title'), strings._('systray_download_canceled_message'))
|
||||
|
||||
def on_reload_settings(self):
|
||||
"""
|
||||
@ -285,14 +293,16 @@ class ShareMode(Mode):
|
||||
"""
|
||||
if self.server_status.file_selection.get_num_files() > 0:
|
||||
self.primary_action.show()
|
||||
self.info_widget.show()
|
||||
self.info_label.show()
|
||||
|
||||
def update_primary_action(self):
|
||||
self.common.log('ShareMode', 'update_primary_action')
|
||||
|
||||
# Show or hide primary action layout
|
||||
file_count = self.file_selection.file_list.count()
|
||||
if file_count > 0:
|
||||
self.primary_action.show()
|
||||
self.info_widget.show()
|
||||
self.info_label.show()
|
||||
|
||||
# Update the file count in the info label
|
||||
total_size_bytes = 0
|
||||
@ -302,48 +312,19 @@ class ShareMode(Mode):
|
||||
total_size_readable = self.common.human_readable_filesize(total_size_bytes)
|
||||
|
||||
if file_count > 1:
|
||||
self.info_label.setText(strings._('gui_file_info', True).format(file_count, total_size_readable))
|
||||
self.info_label.setText(strings._('gui_file_info').format(file_count, total_size_readable))
|
||||
else:
|
||||
self.info_label.setText(strings._('gui_file_info_single', True).format(file_count, total_size_readable))
|
||||
self.info_label.setText(strings._('gui_file_info_single').format(file_count, total_size_readable))
|
||||
|
||||
else:
|
||||
self.primary_action.hide()
|
||||
self.info_widget.hide()
|
||||
|
||||
# Resize window
|
||||
self.adjustSize()
|
||||
self.info_label.hide()
|
||||
|
||||
def reset_info_counters(self):
|
||||
"""
|
||||
Set the info counters back to zero.
|
||||
"""
|
||||
self.downloads_completed = 0
|
||||
self.downloads_in_progress = 0
|
||||
self.update_downloads_completed()
|
||||
self.update_downloads_in_progress()
|
||||
self.downloads.reset()
|
||||
|
||||
def update_downloads_completed(self):
|
||||
"""
|
||||
Update the 'Downloads completed' info widget.
|
||||
"""
|
||||
if self.downloads_completed == 0:
|
||||
image = self.common.get_resource_path('images/share_completed_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_completed.png')
|
||||
self.info_completed_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.downloads_completed))
|
||||
self.info_completed_downloads_count.setToolTip(strings._('info_completed_downloads_tooltip', True).format(self.downloads_completed))
|
||||
|
||||
def update_downloads_in_progress(self):
|
||||
"""
|
||||
Update the 'Downloads in progress' info widget.
|
||||
"""
|
||||
if self.downloads_in_progress == 0:
|
||||
image = self.common.get_resource_path('images/share_in_progress_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_in_progress.png')
|
||||
self.info_in_progress_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.downloads_in_progress))
|
||||
self.info_in_progress_downloads_count.setToolTip(strings._('info_in_progress_downloads_tooltip', True).format(self.downloads_in_progress))
|
||||
self.history.reset()
|
||||
|
||||
@staticmethod
|
||||
def _compute_total_size(filenames):
|
@ -22,7 +22,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from onionshare import strings
|
||||
|
||||
from ..widgets import Alert, AddFileDialog
|
||||
from ...widgets import Alert, AddFileDialog
|
||||
|
||||
class DropHereLabel(QtWidgets.QLabel):
|
||||
"""
|
||||
@ -41,7 +41,7 @@ class DropHereLabel(QtWidgets.QLabel):
|
||||
if image:
|
||||
self.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(self.common.get_resource_path('images/logo_transparent.png'))))
|
||||
else:
|
||||
self.setText(strings._('gui_drag_and_drop', True))
|
||||
self.setText(strings._('gui_drag_and_drop'))
|
||||
self.setStyleSheet(self.common.css['share_file_selection_drop_here_label'])
|
||||
|
||||
self.hide()
|
||||
@ -65,7 +65,7 @@ class DropCountLabel(QtWidgets.QLabel):
|
||||
|
||||
self.setAcceptDrops(True)
|
||||
self.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.setText(strings._('gui_drag_and_drop', True))
|
||||
self.setText(strings._('gui_drag_and_drop'))
|
||||
self.setStyleSheet(self.common.css['share_file_selection_drop_count_label'])
|
||||
self.hide()
|
||||
|
||||
@ -89,7 +89,7 @@ class FileList(QtWidgets.QListWidget):
|
||||
self.setAcceptDrops(True)
|
||||
self.setIconSize(QtCore.QSize(32, 32))
|
||||
self.setSortingEnabled(True)
|
||||
self.setMinimumHeight(205)
|
||||
self.setMinimumHeight(160)
|
||||
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
||||
self.drop_here_image = DropHereLabel(self.common, self, True)
|
||||
self.drop_here_text = DropHereLabel(self.common, self, False)
|
||||
@ -216,7 +216,7 @@ class FileList(QtWidgets.QListWidget):
|
||||
|
||||
if filename not in filenames:
|
||||
if not os.access(filename, os.R_OK):
|
||||
Alert(self.common, strings._("not_a_readable_file", True).format(filename))
|
||||
Alert(self.common, strings._("not_a_readable_file").format(filename))
|
||||
return
|
||||
|
||||
fileinfo = QtCore.QFileInfo(filename)
|
||||
@ -261,6 +261,7 @@ class FileList(QtWidgets.QListWidget):
|
||||
|
||||
# Item info widget, with a white background
|
||||
item_info_layout = QtWidgets.QHBoxLayout()
|
||||
item_info_layout.setContentsMargins(0, 0, 0, 0)
|
||||
item_info_layout.addWidget(item_size)
|
||||
item_info_layout.addWidget(item.item_button)
|
||||
item_info = QtWidgets.QWidget()
|
||||
@ -301,9 +302,9 @@ class FileSelection(QtWidgets.QVBoxLayout):
|
||||
self.file_list.files_updated.connect(self.update)
|
||||
|
||||
# Buttons
|
||||
self.add_button = QtWidgets.QPushButton(strings._('gui_add', True))
|
||||
self.add_button = QtWidgets.QPushButton(strings._('gui_add'))
|
||||
self.add_button.clicked.connect(self.add)
|
||||
self.delete_button = QtWidgets.QPushButton(strings._('gui_delete', True))
|
||||
self.delete_button = QtWidgets.QPushButton(strings._('gui_delete'))
|
||||
self.delete_button.clicked.connect(self.delete)
|
||||
button_layout = QtWidgets.QHBoxLayout()
|
||||
button_layout.addStretch()
|
||||
@ -340,7 +341,7 @@ class FileSelection(QtWidgets.QVBoxLayout):
|
||||
"""
|
||||
Add button clicked.
|
||||
"""
|
||||
file_dialog = AddFileDialog(self.common, caption=strings._('gui_choose_items', True))
|
||||
file_dialog = AddFileDialog(self.common, caption=strings._('gui_choose_items'))
|
||||
if file_dialog.exec_() == QtWidgets.QDialog.Accepted:
|
||||
for filename in file_dialog.selectedFiles():
|
||||
self.file_list.add_file(filename)
|
@ -56,5 +56,8 @@ class CompressThread(QtCore.QThread):
|
||||
|
||||
# Let the Web and ZipWriter objects know that we're canceling compression early
|
||||
self.mode.web.cancel_compression = True
|
||||
if self.mode.web.zip_writer:
|
||||
try:
|
||||
self.mode.web.zip_writer.cancel_compression = True
|
||||
except AttributeError:
|
||||
# we never made it as far as creating a ZipWriter object
|
||||
pass
|
@ -23,8 +23,8 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
from onionshare import strings
|
||||
from onionshare.web import Web
|
||||
|
||||
from .share_mode import ShareMode
|
||||
from .receive_mode import ReceiveMode
|
||||
from .mode.share_mode import ShareMode
|
||||
from .mode.receive_mode import ReceiveMode
|
||||
|
||||
from .tor_connection_dialog import TorConnectionDialog
|
||||
from .settings_dialog import SettingsDialog
|
||||
@ -45,6 +45,8 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
|
||||
self.common = common
|
||||
self.common.log('OnionShareGui', '__init__')
|
||||
self.setMinimumWidth(820)
|
||||
self.setMinimumHeight(660)
|
||||
|
||||
self.onion = onion
|
||||
self.qtapp = qtapp
|
||||
@ -55,19 +57,19 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
|
||||
self.setWindowTitle('OnionShare')
|
||||
self.setWindowIcon(QtGui.QIcon(self.common.get_resource_path('images/logo.png')))
|
||||
self.setMinimumWidth(850)
|
||||
|
||||
# Load settings
|
||||
# Load settings, if a custom config was passed in
|
||||
self.config = config
|
||||
self.common.load_settings(self.config)
|
||||
if self.config:
|
||||
self.common.load_settings(self.config)
|
||||
|
||||
# System tray
|
||||
menu = QtWidgets.QMenu()
|
||||
self.settings_action = menu.addAction(strings._('gui_settings_window_title', True))
|
||||
self.settings_action = menu.addAction(strings._('gui_settings_window_title'))
|
||||
self.settings_action.triggered.connect(self.open_settings)
|
||||
help_action = menu.addAction(strings._('gui_settings_button_help', True))
|
||||
help_action = menu.addAction(strings._('gui_settings_button_help'))
|
||||
help_action.triggered.connect(SettingsDialog.help_clicked)
|
||||
exit_action = menu.addAction(strings._('systray_menu_exit', True))
|
||||
exit_action = menu.addAction(strings._('systray_menu_exit'))
|
||||
exit_action.triggered.connect(self.close)
|
||||
|
||||
self.system_tray = QtWidgets.QSystemTrayIcon(self)
|
||||
@ -80,10 +82,10 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
self.system_tray.show()
|
||||
|
||||
# Mode switcher, to switch between share files and receive files
|
||||
self.share_mode_button = QtWidgets.QPushButton(strings._('gui_mode_share_button', True));
|
||||
self.share_mode_button = QtWidgets.QPushButton(strings._('gui_mode_share_button'));
|
||||
self.share_mode_button.setFixedHeight(50)
|
||||
self.share_mode_button.clicked.connect(self.share_mode_clicked)
|
||||
self.receive_mode_button = QtWidgets.QPushButton(strings._('gui_mode_receive_button', True));
|
||||
self.receive_mode_button = QtWidgets.QPushButton(strings._('gui_mode_receive_button'));
|
||||
self.receive_mode_button.setFixedHeight(50)
|
||||
self.receive_mode_button.clicked.connect(self.receive_mode_clicked)
|
||||
self.settings_button = QtWidgets.QPushButton()
|
||||
@ -153,7 +155,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
|
||||
# Layouts
|
||||
contents_layout = QtWidgets.QVBoxLayout()
|
||||
contents_layout.setContentsMargins(10, 10, 10, 10)
|
||||
contents_layout.setContentsMargins(10, 0, 10, 0)
|
||||
contents_layout.addWidget(self.receive_mode)
|
||||
contents_layout.addWidget(self.share_mode)
|
||||
|
||||
@ -194,8 +196,8 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
self.share_mode_button.setStyleSheet(self.common.css['mode_switcher_selected_style'])
|
||||
self.receive_mode_button.setStyleSheet(self.common.css['mode_switcher_unselected_style'])
|
||||
|
||||
self.share_mode.show()
|
||||
self.receive_mode.hide()
|
||||
self.share_mode.show()
|
||||
else:
|
||||
self.share_mode_button.setStyleSheet(self.common.css['mode_switcher_unselected_style'])
|
||||
self.receive_mode_button.setStyleSheet(self.common.css['mode_switcher_selected_style'])
|
||||
@ -223,24 +225,24 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
# Share mode
|
||||
if self.share_mode.server_status.status == ServerStatus.STATUS_STOPPED:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_stopped))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_stopped', True))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_stopped'))
|
||||
elif self.share_mode.server_status.status == ServerStatus.STATUS_WORKING:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_working', True))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_working'))
|
||||
elif self.share_mode.server_status.status == ServerStatus.STATUS_STARTED:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_started))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_started', True))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_started'))
|
||||
else:
|
||||
# Receive mode
|
||||
if self.receive_mode.server_status.status == ServerStatus.STATUS_STOPPED:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_stopped))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped', True))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped'))
|
||||
elif self.receive_mode.server_status.status == ServerStatus.STATUS_WORKING:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_working', True))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_working'))
|
||||
elif self.receive_mode.server_status.status == ServerStatus.STATUS_STARTED:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_started))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_started', True))
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_started'))
|
||||
|
||||
def stop_server_finished(self):
|
||||
# When the server stopped, cleanup the ephemeral onion service
|
||||
@ -254,9 +256,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
self.common.log('OnionShareGui', '_tor_connection_canceled')
|
||||
|
||||
def ask():
|
||||
a = Alert(self.common, strings._('gui_tor_connection_ask', True), QtWidgets.QMessageBox.Question, buttons=QtWidgets.QMessageBox.NoButton, autostart=False)
|
||||
settings_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_open_settings', True))
|
||||
quit_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_quit', True))
|
||||
a = Alert(self.common, strings._('gui_tor_connection_ask'), QtWidgets.QMessageBox.Question, buttons=QtWidgets.QMessageBox.NoButton, autostart=False)
|
||||
settings_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_open_settings'))
|
||||
quit_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_quit'))
|
||||
a.addButton(settings_button, QtWidgets.QMessageBox.AcceptRole)
|
||||
a.addButton(quit_button, QtWidgets.QMessageBox.RejectRole)
|
||||
a.setDefaultButton(settings_button)
|
||||
@ -327,7 +329,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
if self.common.platform == 'Windows' or self.common.platform == 'Darwin':
|
||||
if self.common.settings.get('use_autoupdate'):
|
||||
def update_available(update_url, installed_version, latest_version):
|
||||
Alert(self.common, strings._("update_available", True).format(update_url, installed_version, latest_version))
|
||||
Alert(self.common, strings._("update_available").format(update_url, installed_version, latest_version))
|
||||
|
||||
self.update_thread = UpdateThread(self.common, self.onion, self.config)
|
||||
self.update_thread.update_available.connect(update_available)
|
||||
@ -344,8 +346,8 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
# Have we lost connection to Tor somehow?
|
||||
if not self.onion.is_authenticated():
|
||||
self.timer.stop()
|
||||
self.status_bar.showMessage(strings._('gui_tor_connection_lost', True))
|
||||
self.system_tray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True))
|
||||
self.status_bar.showMessage(strings._('gui_tor_connection_lost'))
|
||||
self.system_tray.showMessage(strings._('gui_tor_connection_lost'), strings._('gui_tor_connection_error_settings'))
|
||||
|
||||
self.share_mode.handle_tor_broke()
|
||||
self.receive_mode.handle_tor_broke()
|
||||
@ -388,18 +390,18 @@ 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):
|
||||
self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(mode.web.error404_count, strings._('other_page_loaded', True), event["path"]))
|
||||
self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(mode.web.error404_count, strings._('other_page_loaded'), event["path"]))
|
||||
|
||||
mode.timer_callback()
|
||||
|
||||
@ -408,14 +410,14 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
When the URL gets copied to the clipboard, display this in the status bar.
|
||||
"""
|
||||
self.common.log('OnionShareGui', 'copy_url')
|
||||
self.system_tray.showMessage(strings._('gui_copied_url_title', True), strings._('gui_copied_url', True))
|
||||
self.system_tray.showMessage(strings._('gui_copied_url_title'), strings._('gui_copied_url'))
|
||||
|
||||
def copy_hidservauth(self):
|
||||
"""
|
||||
When the stealth onion service HidServAuth gets copied to the clipboard, display this in the status bar.
|
||||
"""
|
||||
self.common.log('OnionShareGui', 'copy_hidservauth')
|
||||
self.system_tray.showMessage(strings._('gui_copied_hidservauth_title', True), strings._('gui_copied_hidservauth', True))
|
||||
self.system_tray.showMessage(strings._('gui_copied_hidservauth_title'), strings._('gui_copied_hidservauth'))
|
||||
|
||||
def clear_message(self):
|
||||
"""
|
||||
@ -453,14 +455,14 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
if server_status.status != server_status.STATUS_STOPPED:
|
||||
self.common.log('OnionShareGui', 'closeEvent, opening warning dialog')
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
dialog.setWindowTitle(strings._('gui_quit_title', True))
|
||||
dialog.setWindowTitle(strings._('gui_quit_title'))
|
||||
if self.mode == OnionShareGui.MODE_SHARE:
|
||||
dialog.setText(strings._('gui_share_quit_warning', True))
|
||||
dialog.setText(strings._('gui_share_quit_warning'))
|
||||
else:
|
||||
dialog.setText(strings._('gui_receive_quit_warning', True))
|
||||
dialog.setText(strings._('gui_receive_quit_warning'))
|
||||
dialog.setIcon(QtWidgets.QMessageBox.Critical)
|
||||
quit_button = dialog.addButton(strings._('gui_quit_warning_quit', True), QtWidgets.QMessageBox.YesRole)
|
||||
dont_quit_button = dialog.addButton(strings._('gui_quit_warning_dont_quit', True), QtWidgets.QMessageBox.NoRole)
|
||||
quit_button = dialog.addButton(strings._('gui_quit_warning_quit'), QtWidgets.QMessageBox.YesRole)
|
||||
dont_quit_button = dialog.addButton(strings._('gui_quit_warning_dont_quit'), QtWidgets.QMessageBox.NoRole)
|
||||
dialog.setDefaultButton(dont_quit_button)
|
||||
reply = dialog.exec_()
|
||||
|
||||
|
@ -1,236 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OnionShare | https://onionshare.org/
|
||||
|
||||
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from onionshare import strings
|
||||
from onionshare.web import Web
|
||||
|
||||
from .uploads import Uploads
|
||||
from ..mode import Mode
|
||||
|
||||
class ReceiveMode(Mode):
|
||||
"""
|
||||
Parts of the main window UI for receiving files.
|
||||
"""
|
||||
def init(self):
|
||||
"""
|
||||
Custom initialization for ReceiveMode.
|
||||
"""
|
||||
# Create the Web object
|
||||
self.web = Web(self.common, True, 'receive')
|
||||
|
||||
# Server status
|
||||
self.server_status.set_mode('receive')
|
||||
self.server_status.server_started_finished.connect(self.update_primary_action)
|
||||
self.server_status.server_stopped.connect(self.update_primary_action)
|
||||
self.server_status.server_canceled.connect(self.update_primary_action)
|
||||
|
||||
# Tell server_status about web, then update
|
||||
self.server_status.web = self.web
|
||||
self.server_status.update()
|
||||
|
||||
# Uploads
|
||||
self.uploads = Uploads(self.common)
|
||||
self.uploads_in_progress = 0
|
||||
self.uploads_completed = 0
|
||||
self.new_upload = False # For scrolling to the bottom of the uploads list
|
||||
self.can_stop_server = False # for communicating to the auto-stop timer
|
||||
|
||||
# Information about share, and show uploads button
|
||||
self.info_in_progress_uploads_count = QtWidgets.QLabel()
|
||||
self.info_in_progress_uploads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
self.info_completed_uploads_count = QtWidgets.QLabel()
|
||||
self.info_completed_uploads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
self.update_uploads_completed()
|
||||
self.update_uploads_in_progress()
|
||||
|
||||
self.info_layout = QtWidgets.QHBoxLayout()
|
||||
self.info_layout.addStretch()
|
||||
self.info_layout.addWidget(self.info_in_progress_uploads_count)
|
||||
self.info_layout.addWidget(self.info_completed_uploads_count)
|
||||
|
||||
self.info_widget = QtWidgets.QWidget()
|
||||
self.info_widget.setLayout(self.info_layout)
|
||||
self.info_widget.hide()
|
||||
|
||||
# Receive mode info
|
||||
self.receive_info = QtWidgets.QLabel(strings._('gui_receive_mode_warning', True))
|
||||
self.receive_info.setMinimumHeight(80)
|
||||
self.receive_info.setWordWrap(True)
|
||||
|
||||
# Layout
|
||||
self.layout.insertWidget(0, self.receive_info)
|
||||
self.layout.insertWidget(0, self.info_widget)
|
||||
self.layout.addStretch()
|
||||
self.horizontal_layout_wrapper.addWidget(self.uploads)
|
||||
|
||||
def get_stop_server_shutdown_timeout_text(self):
|
||||
"""
|
||||
Return the string to put on the stop server button, if there's a shutdown timeout
|
||||
"""
|
||||
return strings._('gui_receive_stop_server_shutdown_timeout', True)
|
||||
|
||||
def timeout_finished_should_stop_server(self):
|
||||
"""
|
||||
The shutdown timer expired, should we stop the server? Returns a bool
|
||||
"""
|
||||
# If there were no attempts to upload files, or all uploads are done, we can stop
|
||||
if self.web.receive_mode.upload_count == 0 or self.can_stop_server:
|
||||
self.server_status.stop_server()
|
||||
self.server_status_label.setText(strings._('close_on_timeout', True))
|
||||
return True
|
||||
# An upload is probably still running - hold off on stopping the share, but block new shares.
|
||||
else:
|
||||
self.server_status_label.setText(strings._('timeout_upload_still_running', True))
|
||||
self.web.receive_mode.can_upload = False
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def start_server_custom(self):
|
||||
"""
|
||||
Starting the server.
|
||||
"""
|
||||
# Reset web counters
|
||||
self.can_stop_server = False
|
||||
self.web.receive_mode.upload_count = 0
|
||||
self.web.receive_mode.can_upload = True
|
||||
self.web.error404_count = 0
|
||||
|
||||
# Hide and reset the uploads if we have previously shared
|
||||
self.reset_info_counters()
|
||||
|
||||
def start_server_step2_custom(self):
|
||||
"""
|
||||
Step 2 in starting the server.
|
||||
"""
|
||||
# Continue
|
||||
self.starting_server_step3.emit()
|
||||
self.start_server_finished.emit()
|
||||
|
||||
def handle_tor_broke_custom(self):
|
||||
"""
|
||||
Connection to Tor broke.
|
||||
"""
|
||||
self.primary_action.hide()
|
||||
self.info_widget.hide()
|
||||
|
||||
def handle_request_load(self, event):
|
||||
"""
|
||||
Handle REQUEST_LOAD event.
|
||||
"""
|
||||
self.system_tray.showMessage(strings._('systray_page_loaded_title', True), strings._('systray_upload_page_loaded_message', True))
|
||||
|
||||
def handle_request_started(self, event):
|
||||
"""
|
||||
Handle REQUEST_STARTED event.
|
||||
"""
|
||||
self.uploads.add(event["data"]["id"], event["data"]["content_length"])
|
||||
self.uploads_in_progress += 1
|
||||
self.update_uploads_in_progress()
|
||||
self.can_stop_server = False
|
||||
|
||||
self.system_tray.showMessage(strings._('systray_upload_started_title', True), strings._('systray_upload_started_message', True))
|
||||
|
||||
def handle_request_progress(self, event):
|
||||
"""
|
||||
Handle REQUEST_PROGRESS event.
|
||||
"""
|
||||
self.uploads.update(event["data"]["id"], event["data"]["progress"])
|
||||
|
||||
def handle_request_close_server(self, event):
|
||||
"""
|
||||
Handle REQUEST_CLOSE_SERVER event.
|
||||
"""
|
||||
self.stop_server()
|
||||
self.system_tray.showMessage(strings._('systray_close_server_title', True), strings._('systray_close_server_message', True))
|
||||
|
||||
def handle_request_upload_file_renamed(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_FILE_RENAMED event.
|
||||
"""
|
||||
self.uploads.rename(event["data"]["id"], event["data"]["old_filename"], event["data"]["new_filename"])
|
||||
|
||||
def handle_request_upload_finished(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_FINISHED event.
|
||||
"""
|
||||
self.uploads.finished(event["data"]["id"])
|
||||
# Update the total 'completed uploads' info
|
||||
self.uploads_completed += 1
|
||||
self.update_uploads_completed()
|
||||
# Update the 'in progress uploads' info
|
||||
self.uploads_in_progress -= 1
|
||||
self.update_uploads_in_progress()
|
||||
if self.uploads_in_progress == 0:
|
||||
self.can_stop_server = True
|
||||
|
||||
def on_reload_settings(self):
|
||||
"""
|
||||
We should be ok to re-enable the 'Start Receive Mode' button now.
|
||||
"""
|
||||
self.primary_action.show()
|
||||
self.info_widget.show()
|
||||
|
||||
def reset_info_counters(self):
|
||||
"""
|
||||
Set the info counters back to zero.
|
||||
"""
|
||||
self.uploads_completed = 0
|
||||
self.uploads_in_progress = 0
|
||||
self.update_uploads_completed()
|
||||
self.update_uploads_in_progress()
|
||||
self.uploads.reset()
|
||||
|
||||
def update_uploads_completed(self):
|
||||
"""
|
||||
Update the 'Uploads completed' info widget.
|
||||
"""
|
||||
if self.uploads_completed == 0:
|
||||
image = self.common.get_resource_path('images/share_completed_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_completed.png')
|
||||
self.info_completed_uploads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.uploads_completed))
|
||||
self.info_completed_uploads_count.setToolTip(strings._('info_completed_uploads_tooltip', True).format(self.uploads_completed))
|
||||
|
||||
def update_uploads_in_progress(self):
|
||||
"""
|
||||
Update the 'Uploads in progress' info widget.
|
||||
"""
|
||||
if self.uploads_in_progress == 0:
|
||||
image = self.common.get_resource_path('images/share_in_progress_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_in_progress.png')
|
||||
self.info_in_progress_uploads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.uploads_in_progress))
|
||||
self.info_in_progress_uploads_count.setToolTip(strings._('info_in_progress_uploads_tooltip', True).format(self.uploads_in_progress))
|
||||
|
||||
def update_primary_action(self):
|
||||
self.common.log('ReceiveMode', 'update_primary_action')
|
||||
|
||||
# Show the info widget when the server is active
|
||||
if self.server_status.status == self.server_status.STATUS_STARTED:
|
||||
self.info_widget.show()
|
||||
else:
|
||||
self.info_widget.hide()
|
||||
|
||||
# Resize window
|
||||
self.adjustSize()
|
@ -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':
|
||||
@ -113,7 +120,7 @@ class Upload(QtWidgets.QWidget):
|
||||
self.started = datetime.now()
|
||||
|
||||
# Label
|
||||
self.label = QtWidgets.QLabel(strings._('gui_upload_in_progress', True).format(self.started.strftime("%b %d, %I:%M%p")))
|
||||
self.label = QtWidgets.QLabel(strings._('gui_upload_in_progress').format(self.started.strftime("%b %d, %I:%M%p")))
|
||||
|
||||
# Progress bar
|
||||
self.progress_bar = QtWidgets.QProgressBar()
|
||||
@ -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()
|
||||
@ -190,16 +200,16 @@ class Upload(QtWidgets.QWidget):
|
||||
self.ended = self.started = datetime.now()
|
||||
if self.started.year == self.ended.year and self.started.month == self.ended.month and self.started.day == self.ended.day:
|
||||
if self.started.hour == self.ended.hour and self.started.minute == self.ended.minute:
|
||||
text = strings._('gui_upload_finished', True).format(
|
||||
text = strings._('gui_upload_finished').format(
|
||||
self.started.strftime("%b %d, %I:%M%p")
|
||||
)
|
||||
else:
|
||||
text = strings._('gui_upload_finished_range', True).format(
|
||||
text = strings._('gui_upload_finished_range').format(
|
||||
self.started.strftime("%b %d, %I:%M%p"),
|
||||
self.ended.strftime("%I:%M%p")
|
||||
)
|
||||
else:
|
||||
text = strings._('gui_upload_finished_range', True).format(
|
||||
text = strings._('gui_upload_finished_range').format(
|
||||
self.started.strftime("%b %d, %I:%M%p"),
|
||||
self.ended.strftime("%b %d, %I:%M%p")
|
||||
)
|
||||
@ -220,7 +230,7 @@ class Uploads(QtWidgets.QScrollArea):
|
||||
|
||||
self.uploads = {}
|
||||
|
||||
self.setWindowTitle(strings._('gui_uploads', True))
|
||||
self.setWindowTitle(strings._('gui_uploads'))
|
||||
self.setWidgetResizable(True)
|
||||
self.setMinimumHeight(150)
|
||||
self.setMinimumWidth(350)
|
||||
@ -229,10 +239,10 @@ class Uploads(QtWidgets.QScrollArea):
|
||||
self.vbar = self.verticalScrollBar()
|
||||
self.vbar.rangeChanged.connect(self.resizeScroll)
|
||||
|
||||
uploads_label = QtWidgets.QLabel(strings._('gui_uploads', True))
|
||||
uploads_label = QtWidgets.QLabel(strings._('gui_uploads'))
|
||||
uploads_label.setStyleSheet(self.common.css['downloads_uploads_label'])
|
||||
self.no_uploads_label = QtWidgets.QLabel(strings._('gui_no_uploads', True))
|
||||
self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history', True))
|
||||
self.no_uploads_label = QtWidgets.QLabel(strings._('gui_no_uploads'))
|
||||
self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history'))
|
||||
self.clear_history_button.clicked.connect(self.reset)
|
||||
self.clear_history_button.hide()
|
||||
|
||||
|
@ -61,7 +61,7 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.resizeEvent(None)
|
||||
|
||||
# Shutdown timeout layout
|
||||
self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout', True))
|
||||
self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout'))
|
||||
self.shutdown_timeout = QtWidgets.QDateTimeEdit()
|
||||
self.shutdown_timeout.setDisplayFormat("hh:mm A MMM d, yy")
|
||||
if self.local_only:
|
||||
@ -90,22 +90,22 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.server_button.clicked.connect(self.server_button_clicked)
|
||||
|
||||
# URL layout
|
||||
url_font = QtGui.QFont()
|
||||
url_font = QtGui.QFontDatabase.systemFont(QtGui.QFontDatabase.FixedFont)
|
||||
self.url_description = QtWidgets.QLabel()
|
||||
self.url_description.setWordWrap(True)
|
||||
self.url_description.setMinimumHeight(50)
|
||||
self.url = QtWidgets.QLabel()
|
||||
self.url.setFont(url_font)
|
||||
self.url.setWordWrap(True)
|
||||
self.url.setMinimumHeight(65)
|
||||
self.url.setMinimumSize(self.url.sizeHint())
|
||||
self.url.setStyleSheet(self.common.css['server_status_url'])
|
||||
|
||||
self.copy_url_button = QtWidgets.QPushButton(strings._('gui_copy_url', True))
|
||||
self.copy_url_button = QtWidgets.QPushButton(strings._('gui_copy_url'))
|
||||
self.copy_url_button.setFlat(True)
|
||||
self.copy_url_button.setStyleSheet(self.common.css['server_status_url_buttons'])
|
||||
self.copy_url_button.setMinimumHeight(65)
|
||||
self.copy_url_button.clicked.connect(self.copy_url)
|
||||
self.copy_hidservauth_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth', True))
|
||||
self.copy_hidservauth_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth'))
|
||||
self.copy_hidservauth_button.setFlat(True)
|
||||
self.copy_hidservauth_button.setStyleSheet(self.common.css['server_status_url_buttons'])
|
||||
self.copy_hidservauth_button.clicked.connect(self.copy_hidservauth)
|
||||
@ -142,12 +142,12 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
When the widget is resized, try and adjust the display of a v3 onion URL.
|
||||
"""
|
||||
try:
|
||||
self.get_url()
|
||||
# Wrap the URL label
|
||||
url_length=len(self.get_url())
|
||||
if url_length > 60:
|
||||
width = self.frameGeometry().width()
|
||||
if width < 530:
|
||||
wrapped_onion_url = textwrap.fill(self.get_url(), 50)
|
||||
wrapped_onion_url = textwrap.fill(self.get_url(), 46)
|
||||
self.url.setText(wrapped_onion_url)
|
||||
else:
|
||||
self.url.setText(self.get_url())
|
||||
@ -174,21 +174,21 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
info_image = self.common.get_resource_path('images/info.png')
|
||||
|
||||
if self.mode == ServerStatus.MODE_SHARE:
|
||||
self.url_description.setText(strings._('gui_share_url_description', True).format(info_image))
|
||||
self.url_description.setText(strings._('gui_share_url_description').format(info_image))
|
||||
else:
|
||||
self.url_description.setText(strings._('gui_receive_url_description', True).format(info_image))
|
||||
self.url_description.setText(strings._('gui_receive_url_description').format(info_image))
|
||||
|
||||
# Show a Tool Tip explaining the lifecycle of this URL
|
||||
if self.common.settings.get('save_private_key'):
|
||||
if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get('close_after_first_download'):
|
||||
self.url_description.setToolTip(strings._('gui_url_label_onetime_and_persistent', True))
|
||||
self.url_description.setToolTip(strings._('gui_url_label_onetime_and_persistent'))
|
||||
else:
|
||||
self.url_description.setToolTip(strings._('gui_url_label_persistent', True))
|
||||
self.url_description.setToolTip(strings._('gui_url_label_persistent'))
|
||||
else:
|
||||
if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get('close_after_first_download'):
|
||||
self.url_description.setToolTip(strings._('gui_url_label_onetime', True))
|
||||
self.url_description.setToolTip(strings._('gui_url_label_onetime'))
|
||||
else:
|
||||
self.url_description.setToolTip(strings._('gui_url_label_stay_open', True))
|
||||
self.url_description.setToolTip(strings._('gui_url_label_stay_open'))
|
||||
|
||||
self.url.setText(self.get_url())
|
||||
self.url.show()
|
||||
@ -223,9 +223,9 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.server_button.setStyleSheet(self.common.css['server_status_button_stopped'])
|
||||
self.server_button.setEnabled(True)
|
||||
if self.mode == ServerStatus.MODE_SHARE:
|
||||
self.server_button.setText(strings._('gui_share_start_server', True))
|
||||
self.server_button.setText(strings._('gui_share_start_server'))
|
||||
else:
|
||||
self.server_button.setText(strings._('gui_receive_start_server', True))
|
||||
self.server_button.setText(strings._('gui_receive_start_server'))
|
||||
self.server_button.setToolTip('')
|
||||
if self.common.settings.get('shutdown_timeout'):
|
||||
self.shutdown_timeout_container.show()
|
||||
@ -233,15 +233,15 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.server_button.setStyleSheet(self.common.css['server_status_button_started'])
|
||||
self.server_button.setEnabled(True)
|
||||
if self.mode == ServerStatus.MODE_SHARE:
|
||||
self.server_button.setText(strings._('gui_share_stop_server', True))
|
||||
self.server_button.setText(strings._('gui_share_stop_server'))
|
||||
else:
|
||||
self.server_button.setText(strings._('gui_receive_stop_server', True))
|
||||
self.server_button.setText(strings._('gui_receive_stop_server'))
|
||||
if self.common.settings.get('shutdown_timeout'):
|
||||
self.shutdown_timeout_container.hide()
|
||||
if self.mode == ServerStatus.MODE_SHARE:
|
||||
self.server_button.setToolTip(strings._('gui_share_stop_server_shutdown_timeout_tooltip', True).format(self.timeout))
|
||||
self.server_button.setToolTip(strings._('gui_share_stop_server_shutdown_timeout_tooltip').format(self.timeout))
|
||||
else:
|
||||
self.server_button.setToolTip(strings._('gui_receive_stop_server_shutdown_timeout_tooltip', True).format(self.timeout))
|
||||
self.server_button.setToolTip(strings._('gui_receive_stop_server_shutdown_timeout_tooltip').format(self.timeout))
|
||||
|
||||
elif self.status == self.STATUS_WORKING:
|
||||
self.server_button.setStyleSheet(self.common.css['server_status_button_working'])
|
||||
@ -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:
|
||||
|
@ -47,7 +47,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.local_only = local_only
|
||||
|
||||
self.setModal(True)
|
||||
self.setWindowTitle(strings._('gui_settings_window_title', True))
|
||||
self.setWindowTitle(strings._('gui_settings_window_title'))
|
||||
self.setWindowIcon(QtGui.QIcon(self.common.get_resource_path('images/logo.png')))
|
||||
|
||||
self.system = platform.system()
|
||||
@ -57,8 +57,8 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Use a slug or not ('public mode')
|
||||
self.public_mode_checkbox = QtWidgets.QCheckBox()
|
||||
self.public_mode_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.public_mode_checkbox.setText(strings._("gui_settings_public_mode_checkbox", True))
|
||||
public_mode_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Public-Mode"))
|
||||
self.public_mode_checkbox.setText(strings._("gui_settings_public_mode_checkbox"))
|
||||
public_mode_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Public-Mode"))
|
||||
public_mode_label.setStyleSheet(self.common.css['settings_whats_this'])
|
||||
public_mode_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
public_mode_label.setOpenExternalLinks(True)
|
||||
@ -74,8 +74,8 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Whether or not to use a shutdown ('auto-stop') timer
|
||||
self.shutdown_timeout_checkbox = QtWidgets.QCheckBox()
|
||||
self.shutdown_timeout_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
self.shutdown_timeout_checkbox.setText(strings._("gui_settings_shutdown_timeout_checkbox", True))
|
||||
shutdown_timeout_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Using-the-Auto-Stop-Timer"))
|
||||
self.shutdown_timeout_checkbox.setText(strings._("gui_settings_shutdown_timeout_checkbox"))
|
||||
shutdown_timeout_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-the-Auto-Stop-Timer"))
|
||||
shutdown_timeout_label.setStyleSheet(self.common.css['settings_whats_this'])
|
||||
shutdown_timeout_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
shutdown_timeout_label.setOpenExternalLinks(True)
|
||||
@ -91,9 +91,9 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Whether or not to use legacy v2 onions
|
||||
self.use_legacy_v2_onions_checkbox = QtWidgets.QCheckBox()
|
||||
self.use_legacy_v2_onions_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.use_legacy_v2_onions_checkbox.setText(strings._("gui_use_legacy_v2_onions_checkbox", True))
|
||||
self.use_legacy_v2_onions_checkbox.setText(strings._("gui_use_legacy_v2_onions_checkbox"))
|
||||
self.use_legacy_v2_onions_checkbox.clicked.connect(self.use_legacy_v2_onions_checkbox_clicked)
|
||||
use_legacy_v2_onions_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Legacy-Addresses"))
|
||||
use_legacy_v2_onions_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Legacy-Addresses"))
|
||||
use_legacy_v2_onions_label.setStyleSheet(self.common.css['settings_whats_this'])
|
||||
use_legacy_v2_onions_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
use_legacy_v2_onions_label.setOpenExternalLinks(True)
|
||||
@ -108,9 +108,9 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Whether or not to save the Onion private key for reuse (persistent URL mode)
|
||||
self.save_private_key_checkbox = QtWidgets.QCheckBox()
|
||||
self.save_private_key_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.save_private_key_checkbox.setText(strings._("gui_save_private_key_checkbox", True))
|
||||
self.save_private_key_checkbox.setText(strings._("gui_save_private_key_checkbox"))
|
||||
self.save_private_key_checkbox.clicked.connect(self.save_private_key_checkbox_clicked)
|
||||
save_private_key_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Using-a-Persistent-URL"))
|
||||
save_private_key_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-a-Persistent-URL"))
|
||||
save_private_key_label.setStyleSheet(self.common.css['settings_whats_this'])
|
||||
save_private_key_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
save_private_key_label.setOpenExternalLinks(True)
|
||||
@ -125,9 +125,9 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Stealth
|
||||
self.stealth_checkbox = QtWidgets.QCheckBox()
|
||||
self.stealth_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.stealth_checkbox.setText(strings._("gui_settings_stealth_option", True))
|
||||
self.stealth_checkbox.setText(strings._("gui_settings_stealth_option"))
|
||||
self.stealth_checkbox.clicked.connect(self.stealth_checkbox_clicked_connect)
|
||||
use_stealth_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Stealth-Onion-Services"))
|
||||
use_stealth_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Stealth-Onion-Services"))
|
||||
use_stealth_label.setStyleSheet(self.common.css['settings_whats_this'])
|
||||
use_stealth_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
use_stealth_label.setOpenExternalLinks(True)
|
||||
@ -140,12 +140,12 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.use_stealth_widget = QtWidgets.QWidget()
|
||||
self.use_stealth_widget.setLayout(use_stealth_layout)
|
||||
|
||||
hidservauth_details = QtWidgets.QLabel(strings._('gui_settings_stealth_hidservauth_string', True))
|
||||
hidservauth_details = QtWidgets.QLabel(strings._('gui_settings_stealth_hidservauth_string'))
|
||||
hidservauth_details.setWordWrap(True)
|
||||
hidservauth_details.setMinimumSize(hidservauth_details.sizeHint())
|
||||
hidservauth_details.hide()
|
||||
|
||||
self.hidservauth_copy_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth', True))
|
||||
self.hidservauth_copy_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth'))
|
||||
self.hidservauth_copy_button.clicked.connect(self.hidservauth_copy_button_clicked)
|
||||
self.hidservauth_copy_button.hide()
|
||||
|
||||
@ -159,7 +159,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
general_group_layout.addWidget(hidservauth_details)
|
||||
general_group_layout.addWidget(self.hidservauth_copy_button)
|
||||
|
||||
general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label", True))
|
||||
general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label"))
|
||||
general_group.setLayout(general_group_layout)
|
||||
|
||||
# Sharing options
|
||||
@ -167,19 +167,19 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Close after first download
|
||||
self.close_after_first_download_checkbox = QtWidgets.QCheckBox()
|
||||
self.close_after_first_download_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
self.close_after_first_download_checkbox.setText(strings._("gui_settings_close_after_first_download_option", True))
|
||||
self.close_after_first_download_checkbox.setText(strings._("gui_settings_close_after_first_download_option"))
|
||||
|
||||
# Sharing options layout
|
||||
sharing_group_layout = QtWidgets.QVBoxLayout()
|
||||
sharing_group_layout.addWidget(self.close_after_first_download_checkbox)
|
||||
sharing_group = QtWidgets.QGroupBox(strings._("gui_settings_sharing_label", True))
|
||||
sharing_group = QtWidgets.QGroupBox(strings._("gui_settings_sharing_label"))
|
||||
sharing_group.setLayout(sharing_group_layout)
|
||||
|
||||
# Downloads dir
|
||||
downloads_label = QtWidgets.QLabel(strings._('gui_settings_downloads_label', True));
|
||||
downloads_label = QtWidgets.QLabel(strings._('gui_settings_downloads_label'));
|
||||
self.downloads_dir_lineedit = QtWidgets.QLineEdit()
|
||||
self.downloads_dir_lineedit.setReadOnly(True)
|
||||
downloads_button = QtWidgets.QPushButton(strings._('gui_settings_downloads_button', True))
|
||||
downloads_button = QtWidgets.QPushButton(strings._('gui_settings_downloads_button'))
|
||||
downloads_button.clicked.connect(self.downloads_button_clicked)
|
||||
downloads_layout = QtWidgets.QHBoxLayout()
|
||||
downloads_layout.addWidget(downloads_label)
|
||||
@ -189,7 +189,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Receiving options layout
|
||||
receiving_group_layout = QtWidgets.QVBoxLayout()
|
||||
receiving_group_layout.addLayout(downloads_layout)
|
||||
receiving_group = QtWidgets.QGroupBox(strings._("gui_settings_receiving_label", True))
|
||||
receiving_group = QtWidgets.QGroupBox(strings._("gui_settings_receiving_label"))
|
||||
receiving_group.setLayout(receiving_group_layout)
|
||||
|
||||
# Automatic updates options
|
||||
@ -197,13 +197,13 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Autoupdate
|
||||
self.autoupdate_checkbox = QtWidgets.QCheckBox()
|
||||
self.autoupdate_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.autoupdate_checkbox.setText(strings._("gui_settings_autoupdate_option", True))
|
||||
self.autoupdate_checkbox.setText(strings._("gui_settings_autoupdate_option"))
|
||||
|
||||
# Last update time
|
||||
self.autoupdate_timestamp = QtWidgets.QLabel()
|
||||
|
||||
# Check for updates button
|
||||
self.check_for_updates_button = QtWidgets.QPushButton(strings._('gui_settings_autoupdate_check_button', True))
|
||||
self.check_for_updates_button = QtWidgets.QPushButton(strings._('gui_settings_autoupdate_check_button'))
|
||||
self.check_for_updates_button.clicked.connect(self.check_for_updates)
|
||||
# We can't check for updates if not connected to Tor
|
||||
if not self.onion.connected_to_tor:
|
||||
@ -214,17 +214,32 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
autoupdate_group_layout.addWidget(self.autoupdate_checkbox)
|
||||
autoupdate_group_layout.addWidget(self.autoupdate_timestamp)
|
||||
autoupdate_group_layout.addWidget(self.check_for_updates_button)
|
||||
autoupdate_group = QtWidgets.QGroupBox(strings._("gui_settings_autoupdate_label", True))
|
||||
autoupdate_group = QtWidgets.QGroupBox(strings._("gui_settings_autoupdate_label"))
|
||||
autoupdate_group.setLayout(autoupdate_group_layout)
|
||||
|
||||
# Autoupdate is only available for Windows and Mac (Linux updates using package manager)
|
||||
if self.system != 'Windows' and self.system != 'Darwin':
|
||||
autoupdate_group.hide()
|
||||
|
||||
# Language settings
|
||||
language_label = QtWidgets.QLabel(strings._("gui_settings_language_label"))
|
||||
self.language_combobox = QtWidgets.QComboBox()
|
||||
# Populate the dropdown with all of OnionShare's available languages
|
||||
language_names_to_locales = {v: k for k, v in self.common.settings.available_locales.items()}
|
||||
language_names = list(language_names_to_locales)
|
||||
language_names.sort()
|
||||
for language_name in language_names:
|
||||
locale = language_names_to_locales[language_name]
|
||||
self.language_combobox.addItem(language_name, QtCore.QVariant(locale))
|
||||
language_layout = QtWidgets.QHBoxLayout()
|
||||
language_layout.addWidget(language_label)
|
||||
language_layout.addWidget(self.language_combobox)
|
||||
language_layout.addStretch()
|
||||
|
||||
# Connection type: either automatic, control port, or socket file
|
||||
|
||||
# Bundled Tor
|
||||
self.connection_type_bundled_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_bundled_option', True))
|
||||
self.connection_type_bundled_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_bundled_option'))
|
||||
self.connection_type_bundled_radio.toggled.connect(self.connection_type_bundled_toggled)
|
||||
|
||||
# Bundled Tor doesn't work on dev mode in Windows or Mac
|
||||
@ -234,27 +249,27 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Bridge options for bundled tor
|
||||
|
||||
# No bridges option radio
|
||||
self.tor_bridges_no_bridges_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_no_bridges_radio_option', True))
|
||||
self.tor_bridges_no_bridges_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_no_bridges_radio_option'))
|
||||
self.tor_bridges_no_bridges_radio.toggled.connect(self.tor_bridges_no_bridges_radio_toggled)
|
||||
|
||||
# obfs4 option radio
|
||||
# if the obfs4proxy binary is missing, we can't use obfs4 transports
|
||||
(self.tor_path, self.tor_geo_ip_file_path, self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path) = self.common.get_tor_paths()
|
||||
if not os.path.isfile(self.obfs4proxy_file_path):
|
||||
self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option_no_obfs4proxy', True))
|
||||
self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option_no_obfs4proxy'))
|
||||
self.tor_bridges_use_obfs4_radio.setEnabled(False)
|
||||
else:
|
||||
self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option', True))
|
||||
self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option'))
|
||||
self.tor_bridges_use_obfs4_radio.toggled.connect(self.tor_bridges_use_obfs4_radio_toggled)
|
||||
|
||||
# meek_lite-azure option radio
|
||||
# if the obfs4proxy binary is missing, we can't use meek_lite-azure transports
|
||||
(self.tor_path, self.tor_geo_ip_file_path, self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path) = self.common.get_tor_paths()
|
||||
if not os.path.isfile(self.obfs4proxy_file_path):
|
||||
self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option_no_obfs4proxy', True))
|
||||
self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option_no_obfs4proxy'))
|
||||
self.tor_bridges_use_meek_lite_azure_radio.setEnabled(False)
|
||||
else:
|
||||
self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option', True))
|
||||
self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option'))
|
||||
self.tor_bridges_use_meek_lite_azure_radio.toggled.connect(self.tor_bridges_use_meek_lite_azure_radio_toggled)
|
||||
|
||||
# meek_lite currently not supported on the version of obfs4proxy bundled with TorBrowser
|
||||
@ -262,10 +277,10 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.tor_bridges_use_meek_lite_azure_radio.hide()
|
||||
|
||||
# Custom bridges radio and textbox
|
||||
self.tor_bridges_use_custom_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_custom_radio_option', True))
|
||||
self.tor_bridges_use_custom_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_custom_radio_option'))
|
||||
self.tor_bridges_use_custom_radio.toggled.connect(self.tor_bridges_use_custom_radio_toggled)
|
||||
|
||||
self.tor_bridges_use_custom_label = QtWidgets.QLabel(strings._('gui_settings_tor_bridges_custom_label', True))
|
||||
self.tor_bridges_use_custom_label = QtWidgets.QLabel(strings._('gui_settings_tor_bridges_custom_label'))
|
||||
self.tor_bridges_use_custom_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
self.tor_bridges_use_custom_label.setOpenExternalLinks(True)
|
||||
self.tor_bridges_use_custom_textbox = QtWidgets.QPlainTextEdit()
|
||||
@ -292,14 +307,14 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.bridges.setLayout(bridges_layout)
|
||||
|
||||
# Automatic
|
||||
self.connection_type_automatic_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_automatic_option', True))
|
||||
self.connection_type_automatic_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_automatic_option'))
|
||||
self.connection_type_automatic_radio.toggled.connect(self.connection_type_automatic_toggled)
|
||||
|
||||
# Control port
|
||||
self.connection_type_control_port_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_control_port_option', True))
|
||||
self.connection_type_control_port_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_control_port_option'))
|
||||
self.connection_type_control_port_radio.toggled.connect(self.connection_type_control_port_toggled)
|
||||
|
||||
connection_type_control_port_extras_label = QtWidgets.QLabel(strings._('gui_settings_control_port_label', True))
|
||||
connection_type_control_port_extras_label = QtWidgets.QLabel(strings._('gui_settings_control_port_label'))
|
||||
self.connection_type_control_port_extras_address = QtWidgets.QLineEdit()
|
||||
self.connection_type_control_port_extras_port = QtWidgets.QLineEdit()
|
||||
connection_type_control_port_extras_layout = QtWidgets.QHBoxLayout()
|
||||
@ -312,10 +327,10 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.connection_type_control_port_extras.hide()
|
||||
|
||||
# Socket file
|
||||
self.connection_type_socket_file_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_socket_file_option', True))
|
||||
self.connection_type_socket_file_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_socket_file_option'))
|
||||
self.connection_type_socket_file_radio.toggled.connect(self.connection_type_socket_file_toggled)
|
||||
|
||||
connection_type_socket_file_extras_label = QtWidgets.QLabel(strings._('gui_settings_socket_file_label', True))
|
||||
connection_type_socket_file_extras_label = QtWidgets.QLabel(strings._('gui_settings_socket_file_label'))
|
||||
self.connection_type_socket_file_extras_path = QtWidgets.QLineEdit()
|
||||
connection_type_socket_file_extras_layout = QtWidgets.QHBoxLayout()
|
||||
connection_type_socket_file_extras_layout.addWidget(connection_type_socket_file_extras_label)
|
||||
@ -326,7 +341,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.connection_type_socket_file_extras.hide()
|
||||
|
||||
# Tor SOCKS address and port
|
||||
gui_settings_socks_label = QtWidgets.QLabel(strings._('gui_settings_socks_label', True))
|
||||
gui_settings_socks_label = QtWidgets.QLabel(strings._('gui_settings_socks_label'))
|
||||
self.connection_type_socks_address = QtWidgets.QLineEdit()
|
||||
self.connection_type_socks_port = QtWidgets.QLineEdit()
|
||||
connection_type_socks_layout = QtWidgets.QHBoxLayout()
|
||||
@ -341,14 +356,14 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# Authentication options
|
||||
|
||||
# No authentication
|
||||
self.authenticate_no_auth_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_no_auth_option', True))
|
||||
self.authenticate_no_auth_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_no_auth_option'))
|
||||
self.authenticate_no_auth_radio.toggled.connect(self.authenticate_no_auth_toggled)
|
||||
|
||||
# Password
|
||||
self.authenticate_password_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_password_option', True))
|
||||
self.authenticate_password_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_password_option'))
|
||||
self.authenticate_password_radio.toggled.connect(self.authenticate_password_toggled)
|
||||
|
||||
authenticate_password_extras_label = QtWidgets.QLabel(strings._('gui_settings_password_label', True))
|
||||
authenticate_password_extras_label = QtWidgets.QLabel(strings._('gui_settings_password_label'))
|
||||
self.authenticate_password_extras_password = QtWidgets.QLineEdit('')
|
||||
authenticate_password_extras_layout = QtWidgets.QHBoxLayout()
|
||||
authenticate_password_extras_layout.addWidget(authenticate_password_extras_label)
|
||||
@ -363,7 +378,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
authenticate_group_layout.addWidget(self.authenticate_no_auth_radio)
|
||||
authenticate_group_layout.addWidget(self.authenticate_password_radio)
|
||||
authenticate_group_layout.addWidget(self.authenticate_password_extras)
|
||||
self.authenticate_group = QtWidgets.QGroupBox(strings._("gui_settings_authenticate_label", True))
|
||||
self.authenticate_group = QtWidgets.QGroupBox(strings._("gui_settings_authenticate_label"))
|
||||
self.authenticate_group.setLayout(authenticate_group_layout)
|
||||
|
||||
# Put the radios into their own group so they are exclusive
|
||||
@ -372,18 +387,18 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
connection_type_radio_group_layout.addWidget(self.connection_type_automatic_radio)
|
||||
connection_type_radio_group_layout.addWidget(self.connection_type_control_port_radio)
|
||||
connection_type_radio_group_layout.addWidget(self.connection_type_socket_file_radio)
|
||||
connection_type_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_connection_type_label", True))
|
||||
connection_type_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_connection_type_label"))
|
||||
connection_type_radio_group.setLayout(connection_type_radio_group_layout)
|
||||
|
||||
# The Bridges options are not exclusive (enabling Bridges offers obfs4 or custom bridges)
|
||||
connection_type_bridges_radio_group_layout = QtWidgets.QVBoxLayout()
|
||||
connection_type_bridges_radio_group_layout.addWidget(self.bridges)
|
||||
self.connection_type_bridges_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_tor_bridges", True))
|
||||
self.connection_type_bridges_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_tor_bridges"))
|
||||
self.connection_type_bridges_radio_group.setLayout(connection_type_bridges_radio_group_layout)
|
||||
self.connection_type_bridges_radio_group.hide()
|
||||
|
||||
# Test tor settings button
|
||||
self.connection_type_test_button = QtWidgets.QPushButton(strings._('gui_settings_connection_type_test_button', True))
|
||||
self.connection_type_test_button = QtWidgets.QPushButton(strings._('gui_settings_connection_type_test_button'))
|
||||
self.connection_type_test_button.clicked.connect(self.test_tor_clicked)
|
||||
connection_type_test_button_layout = QtWidgets.QHBoxLayout()
|
||||
connection_type_test_button_layout.addWidget(self.connection_type_test_button)
|
||||
@ -399,13 +414,13 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
connection_type_layout.addLayout(connection_type_test_button_layout)
|
||||
|
||||
# Buttons
|
||||
self.save_button = QtWidgets.QPushButton(strings._('gui_settings_button_save', True))
|
||||
self.save_button = QtWidgets.QPushButton(strings._('gui_settings_button_save'))
|
||||
self.save_button.clicked.connect(self.save_clicked)
|
||||
self.cancel_button = QtWidgets.QPushButton(strings._('gui_settings_button_cancel', True))
|
||||
self.cancel_button = QtWidgets.QPushButton(strings._('gui_settings_button_cancel'))
|
||||
self.cancel_button.clicked.connect(self.cancel_clicked)
|
||||
version_label = QtWidgets.QLabel('OnionShare {0:s}'.format(self.common.version))
|
||||
version_label.setStyleSheet(self.common.css['settings_version'])
|
||||
self.help_button = QtWidgets.QPushButton(strings._('gui_settings_button_help', True))
|
||||
self.help_button = QtWidgets.QPushButton(strings._('gui_settings_button_help'))
|
||||
self.help_button.clicked.connect(self.help_clicked)
|
||||
buttons_layout = QtWidgets.QHBoxLayout()
|
||||
buttons_layout.addWidget(version_label)
|
||||
@ -425,6 +440,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
left_col_layout.addWidget(sharing_group)
|
||||
left_col_layout.addWidget(receiving_group)
|
||||
left_col_layout.addWidget(autoupdate_group)
|
||||
left_col_layout.addLayout(language_layout)
|
||||
left_col_layout.addStretch()
|
||||
|
||||
right_col_layout = QtWidgets.QVBoxLayout()
|
||||
@ -512,6 +528,10 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
autoupdate_timestamp = self.old_settings.get('autoupdate_timestamp')
|
||||
self._update_autoupdate_timestamp(autoupdate_timestamp)
|
||||
|
||||
locale = self.old_settings.get('locale')
|
||||
locale_index = self.language_combobox.findData(QtCore.QVariant(locale))
|
||||
self.language_combobox.setCurrentIndex(locale_index)
|
||||
|
||||
connection_type = self.old_settings.get('connection_type')
|
||||
if connection_type == 'bundled':
|
||||
if self.connection_type_bundled_radio.isEnabled():
|
||||
@ -591,7 +611,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.tor_bridges_use_custom_textbox_options.hide()
|
||||
# Alert the user about meek's costliness if it looks like they're turning it on
|
||||
if not self.old_settings.get('tor_bridges_use_meek_lite_azure'):
|
||||
Alert(self.common, strings._('gui_settings_meek_lite_expensive_warning', True), QtWidgets.QMessageBox.Warning)
|
||||
Alert(self.common, strings._('gui_settings_meek_lite_expensive_warning'), QtWidgets.QMessageBox.Warning)
|
||||
|
||||
def tor_bridges_use_custom_radio_toggled(self, checked):
|
||||
"""
|
||||
@ -704,7 +724,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
"""
|
||||
downloads_dir = self.downloads_dir_lineedit.text()
|
||||
selected_dir = QtWidgets.QFileDialog.getExistingDirectory(self,
|
||||
strings._('gui_settings_downloads_label', True), downloads_dir)
|
||||
strings._('gui_settings_downloads_label'), downloads_dir)
|
||||
|
||||
if selected_dir:
|
||||
self.common.log('SettingsDialog', 'downloads_button_clicked', 'selected dir: {}'.format(selected_dir))
|
||||
@ -734,7 +754,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
onion.connect(custom_settings=settings, config=self.config, tor_status_update_func=tor_status_update_func)
|
||||
|
||||
# If an exception hasn't been raised yet, the Tor settings work
|
||||
Alert(self.common, strings._('settings_test_success', True).format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth, onion.supports_next_gen_onions))
|
||||
Alert(self.common, strings._('settings_test_success').format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth, onion.supports_next_gen_onions))
|
||||
|
||||
# Clean up
|
||||
onion.cleanup()
|
||||
@ -770,19 +790,19 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
|
||||
# Check for updates
|
||||
def update_available(update_url, installed_version, latest_version):
|
||||
Alert(self.common, strings._("update_available", True).format(update_url, installed_version, latest_version))
|
||||
Alert(self.common, strings._("update_available").format(update_url, installed_version, latest_version))
|
||||
close_forced_update_thread()
|
||||
|
||||
def update_not_available():
|
||||
Alert(self.common, strings._('update_not_available', True))
|
||||
Alert(self.common, strings._('update_not_available'))
|
||||
close_forced_update_thread()
|
||||
|
||||
def update_error():
|
||||
Alert(self.common, strings._('update_error_check_error', True), QtWidgets.QMessageBox.Warning)
|
||||
Alert(self.common, strings._('update_error_check_error'), QtWidgets.QMessageBox.Warning)
|
||||
close_forced_update_thread()
|
||||
|
||||
def update_invalid_version(latest_version):
|
||||
Alert(self.common, strings._('update_error_invalid_latest_version', True).format(latest_version), QtWidgets.QMessageBox.Warning)
|
||||
Alert(self.common, strings._('update_error_invalid_latest_version').format(latest_version), QtWidgets.QMessageBox.Warning)
|
||||
close_forced_update_thread()
|
||||
|
||||
forced_update_thread = UpdateThread(self.common, self.onion, self.config, force=True)
|
||||
@ -798,8 +818,29 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
"""
|
||||
self.common.log('SettingsDialog', 'save_clicked')
|
||||
|
||||
def changed(s1, s2, keys):
|
||||
"""
|
||||
Compare the Settings objects s1 and s2 and return true if any values
|
||||
have changed for the given keys.
|
||||
"""
|
||||
for key in keys:
|
||||
if s1.get(key) != s2.get(key):
|
||||
return True
|
||||
return False
|
||||
|
||||
settings = self.settings_from_fields()
|
||||
if settings:
|
||||
# If language changed, inform user they need to restart OnionShare
|
||||
if changed(settings, self.old_settings, ['locale']):
|
||||
# Look up error message in different locale
|
||||
new_locale = settings.get('locale')
|
||||
if new_locale in strings.translations and 'gui_settings_language_changed_notice' in strings.translations[new_locale]:
|
||||
notice = strings.translations[new_locale]['gui_settings_language_changed_notice']
|
||||
else:
|
||||
notice = strings._('gui_settings_language_changed_notice')
|
||||
Alert(self.common, notice, QtWidgets.QMessageBox.Information)
|
||||
|
||||
# Save the new settings
|
||||
settings.save()
|
||||
|
||||
# If Tor isn't connected, or if Tor settings have changed, Reinitialize
|
||||
@ -808,15 +849,6 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
if not self.local_only:
|
||||
if self.onion.is_authenticated():
|
||||
self.common.log('SettingsDialog', 'save_clicked', 'Connected to Tor')
|
||||
def changed(s1, s2, keys):
|
||||
"""
|
||||
Compare the Settings objects s1 and s2 and return true if any values
|
||||
have changed for the given keys.
|
||||
"""
|
||||
for key in keys:
|
||||
if s1.get(key) != s2.get(key):
|
||||
return True
|
||||
return False
|
||||
|
||||
if changed(settings, self.old_settings, [
|
||||
'connection_type', 'control_port_address',
|
||||
@ -861,7 +893,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
"""
|
||||
self.common.log('SettingsDialog', 'cancel_clicked')
|
||||
if not self.local_only and not self.onion.is_authenticated():
|
||||
Alert(self.common, strings._('gui_tor_connection_canceled', True), QtWidgets.QMessageBox.Warning)
|
||||
Alert(self.common, strings._('gui_tor_connection_canceled'), QtWidgets.QMessageBox.Warning)
|
||||
sys.exit()
|
||||
else:
|
||||
self.close()
|
||||
@ -871,8 +903,12 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
Help button clicked.
|
||||
"""
|
||||
self.common.log('SettingsDialog', 'help_clicked')
|
||||
help_site = 'https://github.com/micahflee/onionshare/wiki'
|
||||
QtGui.QDesktopServices.openUrl(QtCore.QUrl(help_site))
|
||||
SettingsDialog.open_help()
|
||||
|
||||
@staticmethod
|
||||
def open_help():
|
||||
help_url = 'https://github.com/micahflee/onionshare/wiki'
|
||||
QtGui.QDesktopServices.openUrl(QtCore.QUrl(help_url))
|
||||
|
||||
def settings_from_fields(self):
|
||||
"""
|
||||
@ -923,6 +959,12 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
if not self.stealth_checkbox.isChecked():
|
||||
settings.set('hidservauth_string', '')
|
||||
|
||||
# Language
|
||||
locale_index = self.language_combobox.currentIndex()
|
||||
locale = self.language_combobox.itemData(locale_index)
|
||||
settings.set('locale', locale)
|
||||
|
||||
# Tor connection
|
||||
if self.connection_type_bundled_radio.isChecked():
|
||||
settings.set('connection_type', 'bundled')
|
||||
if self.connection_type_automatic_radio.isChecked():
|
||||
@ -996,7 +1038,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
new_bridges = ''.join(new_bridges)
|
||||
settings.set('tor_bridges_use_custom_bridges', new_bridges)
|
||||
else:
|
||||
Alert(self.common, strings._('gui_settings_tor_bridges_invalid', True))
|
||||
Alert(self.common, strings._('gui_settings_tor_bridges_invalid'))
|
||||
settings.set('no_bridges', True)
|
||||
return False
|
||||
|
||||
@ -1020,11 +1062,11 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
dt = datetime.datetime.fromtimestamp(autoupdate_timestamp)
|
||||
last_checked = dt.strftime('%B %d, %Y %H:%M')
|
||||
else:
|
||||
last_checked = strings._('gui_settings_autoupdate_timestamp_never', True)
|
||||
self.autoupdate_timestamp.setText(strings._('gui_settings_autoupdate_timestamp', True).format(last_checked))
|
||||
last_checked = strings._('gui_settings_autoupdate_timestamp_never')
|
||||
self.autoupdate_timestamp.setText(strings._('gui_settings_autoupdate_timestamp').format(last_checked))
|
||||
|
||||
def _tor_status_update(self, progress, summary):
|
||||
self.tor_status.setText('<strong>{}</strong><br>{}% {}'.format(strings._('connecting_to_tor', True), progress, summary))
|
||||
self.tor_status.setText('<strong>{}</strong><br>{}% {}'.format(strings._('connecting_to_tor'), progress, summary))
|
||||
self.qtapp.processEvents()
|
||||
if 'Done' in summary:
|
||||
self.tor_status.hide()
|
||||
|
@ -89,7 +89,7 @@ class Downloads(QtWidgets.QScrollArea):
|
||||
|
||||
self.downloads = {}
|
||||
|
||||
self.setWindowTitle(strings._('gui_downloads', True))
|
||||
self.setWindowTitle(strings._('gui_downloads'))
|
||||
self.setWidgetResizable(True)
|
||||
self.setMinimumHeight(150)
|
||||
self.setMinimumWidth(350)
|
||||
@ -98,10 +98,10 @@ class Downloads(QtWidgets.QScrollArea):
|
||||
self.vbar = self.verticalScrollBar()
|
||||
self.vbar.rangeChanged.connect(self.resizeScroll)
|
||||
|
||||
downloads_label = QtWidgets.QLabel(strings._('gui_downloads', True))
|
||||
downloads_label = QtWidgets.QLabel(strings._('gui_downloads'))
|
||||
downloads_label.setStyleSheet(self.common.css['downloads_uploads_label'])
|
||||
self.no_downloads_label = QtWidgets.QLabel(strings._('gui_no_downloads', True))
|
||||
self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history', True))
|
||||
self.no_downloads_label = QtWidgets.QLabel(strings._('gui_no_downloads'))
|
||||
self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history'))
|
||||
self.clear_history_button.clicked.connect(self.reset)
|
||||
self.clear_history_button.hide()
|
||||
|
||||
|
@ -51,7 +51,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
|
||||
self.setFixedSize(400, 150)
|
||||
|
||||
# Label
|
||||
self.setLabelText(strings._('connecting_to_tor', True))
|
||||
self.setLabelText(strings._('connecting_to_tor'))
|
||||
|
||||
# Progress bar ticks from 0 to 100
|
||||
self.setRange(0, 100)
|
||||
@ -81,7 +81,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
|
||||
|
||||
def _tor_status_update(self, progress, summary):
|
||||
self.setValue(int(progress))
|
||||
self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor', True), summary))
|
||||
self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor'), summary))
|
||||
|
||||
def _connected_to_tor(self):
|
||||
self.common.log('TorConnectionDialog', '_connected_to_tor')
|
||||
@ -104,7 +104,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
|
||||
|
||||
def alert_and_open_settings():
|
||||
# Display the exception in an alert box
|
||||
Alert(self.common, "{}\n\n{}".format(msg, strings._('gui_tor_connection_error_settings', True)), QtWidgets.QMessageBox.Warning)
|
||||
Alert(self.common, "{}\n\n{}".format(msg, strings._('gui_tor_connection_error_settings')), QtWidgets.QMessageBox.Warning)
|
||||
|
||||
# Open settings
|
||||
self.open_settings.emit()
|
||||
|
5
setup.py
@ -69,8 +69,9 @@ setup(
|
||||
'onionshare',
|
||||
'onionshare.web',
|
||||
'onionshare_gui',
|
||||
'onionshare_gui.share_mode',
|
||||
'onionshare_gui.receive_mode'
|
||||
'onionshare_gui.mode',
|
||||
'onionshare_gui.mode.share_mode',
|
||||
'onionshare_gui.mode.receive_mode'
|
||||
],
|
||||
include_package_data=True,
|
||||
scripts=['install/scripts/onionshare', 'install/scripts/onionshare-gui'],
|
||||
|
BIN
share/images/downloads.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
share/images/downloads_toggle.png
Normal file
After Width: | Height: | Size: 380 B |
BIN
share/images/downloads_toggle_selected.png
Normal file
After Width: | Height: | Size: 468 B |
BIN
share/images/downloads_transparent.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
share/images/uploads.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
share/images/uploads_toggle.png
Normal file
After Width: | Height: | Size: 389 B |
BIN
share/images/uploads_toggle_selected.png
Normal file
After Width: | Height: | Size: 473 B |
BIN
share/images/uploads_transparent.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
@ -47,7 +47,7 @@
|
||||
"gui_copy_url": "Copy Address",
|
||||
"gui_copy_hidservauth": "Copy HidServAuth",
|
||||
"gui_downloads": "Download History",
|
||||
"gui_no_downloads": "No downloads yet.",
|
||||
"gui_no_downloads": "No Downloads Yet",
|
||||
"gui_canceled": "Canceled",
|
||||
"gui_copied_url_title": "Copied OnionShare Address",
|
||||
"gui_copied_url": "OnionShare address copied to clipboard",
|
||||
@ -63,7 +63,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.",
|
||||
@ -107,7 +107,6 @@
|
||||
"gui_settings_button_help": "Help",
|
||||
"gui_settings_shutdown_timeout_checkbox": "Use auto-stop timer",
|
||||
"gui_settings_shutdown_timeout": "Stop the share at:",
|
||||
"settings_saved": "Settings saved in {}",
|
||||
"settings_error_unknown": "Can't connect to Tor controller because your settings don't make sense.",
|
||||
"settings_error_automatic": "Could not connect to the Tor controller. Is Tor Browser (available from torproject.org) running in the background?",
|
||||
"settings_error_socket_port": "Can't connect to the Tor controller at {}:{}.",
|
||||
@ -152,12 +151,11 @@
|
||||
"gui_status_indicator_receive_started": "Receiving",
|
||||
"gui_file_info": "{} files, {}",
|
||||
"gui_file_info_single": "{} file, {}",
|
||||
"info_in_progress_downloads_tooltip": "{} download(s) in progress",
|
||||
"info_completed_downloads_tooltip": "{} download(s) completed",
|
||||
"history_in_progress_tooltip": "{} in progress",
|
||||
"history_completed_tooltip": "{} completed",
|
||||
"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>",
|
||||
@ -175,10 +173,13 @@
|
||||
"systray_download_page_loaded_message": "A user loaded the download page",
|
||||
"systray_upload_page_loaded_message": "A user loaded the upload page",
|
||||
"gui_uploads": "Upload History",
|
||||
"gui_no_uploads": "No uploads yet.",
|
||||
"gui_clear_history": "Clear history",
|
||||
"gui_no_uploads": "No Uploads Yet",
|
||||
"gui_clear_history": "Clear All",
|
||||
"gui_upload_in_progress": "Upload Started {}",
|
||||
"gui_upload_finished_range": "Uploaded {} to {}",
|
||||
"gui_upload_finished": "Uploaded {}",
|
||||
"gui_open_folder_error_nautilus": "Cannot open folder because nautilus is not available. The file is here: {}"
|
||||
"gui_download_in_progress": "Download Started {}",
|
||||
"gui_open_folder_error_nautilus": "Cannot open folder because nautilus is not available. The file is here: {}",
|
||||
"gui_settings_language_label": "Preferred language",
|
||||
"gui_settings_language_changed_notice": "Restart OnionShare for your change in language to take effect."
|
||||
}
|
||||
|
@ -29,5 +29,6 @@
|
||||
"gui_please_wait": "Attendez-vous...",
|
||||
"gui_quit_warning_quit": "Quitter",
|
||||
"gui_quit_warning_dont_quit": "Ne quitter pas",
|
||||
"gui_settings_autoupdate_timestamp_never": "Jamais"
|
||||
"gui_settings_autoupdate_timestamp_never": "Jamais",
|
||||
"gui_settings_language_changed_notice": "Redémarrez OnionShare pour que votre changement de langue prenne effet"
|
||||
}
|
||||
|
323
tests/GuiBaseTest.py
Normal file
@ -0,0 +1,323 @@
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
import shutil
|
||||
import socket
|
||||
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
|
||||
|
||||
|
||||
class GuiBaseTest(object):
|
||||
@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', '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['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, True, 0)
|
||||
|
||||
web = Web(common, False, True)
|
||||
open('/tmp/settings.json', 'w').write(json.dumps(test_settings))
|
||||
|
||||
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 gui_loaded(self):
|
||||
'''Test that the GUI actually is shown'''
|
||||
self.assertTrue(self.gui.show)
|
||||
|
||||
|
||||
def windowTitle_seen(self):
|
||||
'''Test that the window title is OnionShare'''
|
||||
self.assertEqual(self.gui.windowTitle(), 'OnionShare')
|
||||
|
||||
|
||||
def settings_button_is_visible(self):
|
||||
'''Test that the settings button is visible'''
|
||||
self.assertTrue(self.gui.settings_button.isVisible())
|
||||
|
||||
|
||||
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 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)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_RECEIVE)
|
||||
if type(mode) == ShareMode:
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_SHARE)
|
||||
|
||||
|
||||
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 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())
|
||||
|
||||
if type(mode) == ReceiveMode:
|
||||
# Upload a file
|
||||
files = {'file[]': open('/tmp/test.txt', 'rb')}
|
||||
if not public_mode:
|
||||
path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, 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)
|
||||
|
||||
if type(mode) == ShareMode:
|
||||
# Download files
|
||||
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, mode.web.slug)
|
||||
r = requests.get(url)
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
# 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 history_is_not_visible(self, mode):
|
||||
'''Test that the History section is not visible'''
|
||||
self.assertFalse(mode.history.isVisible())
|
||||
|
||||
|
||||
def history_is_visible(self, mode):
|
||||
'''Test that the History section is visible'''
|
||||
self.assertTrue(mode.history.isVisible())
|
||||
|
||||
|
||||
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 server_status_indicator_says_starting(self, mode):
|
||||
'''Test that the Server Status indicator shows we are Starting'''
|
||||
self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
|
||||
|
||||
|
||||
def server_is_started(self, mode, startup_time=2000):
|
||||
'''Test that the server has started'''
|
||||
QtTest.QTest.qWait(startup_time)
|
||||
# Should now be in SERVER_STARTED state
|
||||
self.assertEqual(mode.server_status.status, 2)
|
||||
|
||||
|
||||
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 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+)')
|
||||
else:
|
||||
self.assertIsNone(mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
|
||||
|
||||
def url_description_shown(self, mode):
|
||||
'''Test that the URL label is showing'''
|
||||
self.assertTrue(mode.server_status.url_description.isVisible())
|
||||
|
||||
|
||||
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://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.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started'))
|
||||
if type(mode) == ShareMode:
|
||||
self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_started'))
|
||||
|
||||
|
||||
def web_page(self, mode, string, public_mode):
|
||||
'''Test that the web page contains a string'''
|
||||
s = socks.socksocket()
|
||||
s.settimeout(60)
|
||||
s.connect(('127.0.0.1', self.gui.app.port))
|
||||
|
||||
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: 127.0.0.1\r\n'
|
||||
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 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 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.assertEqual(mode.server_status.status, 0)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
# We should be closed by now. Fail if not!
|
||||
self.assertNotEqual(sock.connect_ex(('127.0.0.1',self.gui.app.port)), 0)
|
||||
|
||||
|
||||
def server_status_indicator_says_closed(self, mode, stay_open):
|
||||
'''Test that the Server Status indicator shows we closed'''
|
||||
if type(mode) == ReceiveMode:
|
||||
self.assertEqual(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped'))
|
||||
if type(mode) == ShareMode:
|
||||
if stay_open:
|
||||
self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped'))
|
||||
else:
|
||||
self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically'))
|
||||
|
||||
|
||||
# Auto-stop timer tests
|
||||
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 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 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)
|
||||
|
||||
# Hack to close an Alert dialog that would otherwise block tests
|
||||
def accept_dialog(self):
|
||||
window = self.gui.qtapp.activeWindow()
|
||||
if window:
|
||||
window.close()
|
||||
|
||||
# 'Grouped' tests follow from here
|
||||
|
||||
def run_all_common_setup_tests(self):
|
||||
self.gui_loaded()
|
||||
self.windowTitle_seen()
|
||||
self.settings_button_is_visible()
|
||||
self.server_status_bar_is_visible()
|
||||
|
||||
|
124
tests/GuiReceiveTest.py
Normal 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
@ -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)
|
44
tests/SettingsGuiBaseTest.py
Normal 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
@ -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'))
|
59
tests/TorGuiReceiveTest.py
Normal 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
@ -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()
|
||||
|
@ -8,7 +8,23 @@ import tempfile
|
||||
|
||||
import pytest
|
||||
|
||||
from onionshare import common, web, settings
|
||||
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():
|
||||
@ -157,4 +173,5 @@ def common_obj():
|
||||
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)
|
||||
|
@ -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()
|
24
tests/local_onionshare_404_triggers_ratelimit_test.py
Normal 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()
|
@ -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()
|
24
tests/local_onionshare_receive_mode_sender_closed_test.py
Normal 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()
|
24
tests/local_onionshare_receive_mode_timer_test.py
Normal 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()
|
@ -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()
|
@ -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()
|
@ -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()
|
23
tests/local_onionshare_receive_mode_upload_test.py
Normal 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()
|
178
tests/local_onionshare_settings_dialog_test.py
Normal 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()
|
@ -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()
|
23
tests/local_onionshare_share_mode_download_stay_open_test.py
Normal 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()
|
22
tests/local_onionshare_share_mode_download_test.py
Normal 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()
|
22
tests/local_onionshare_share_mode_large_download_test.py
Normal 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()
|
26
tests/local_onionshare_share_mode_slug_persistent_test.py
Normal 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()
|
24
tests/local_onionshare_share_mode_timer_test.py
Normal 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()
|
31
tests/local_onionshare_share_mode_timer_too_short_test.py
Normal 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()
|
22
tests/local_onionshare_share_mode_unreadable_file_test.py
Normal 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()
|
29
tests/onionshare_790_cancel_on_second_share_test.py
Normal 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()
|
26
tests/onionshare_receive_mode_upload_public_mode_test.py
Normal 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()
|
25
tests/onionshare_receive_mode_upload_test.py
Normal 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()
|
25
tests/onionshare_share_mode_cancel_share_test.py
Normal 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()
|
25
tests/onionshare_share_mode_download_public_mode_test.py
Normal 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()
|
25
tests/onionshare_share_mode_download_stay_open_test.py
Normal 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()
|
24
tests/onionshare_share_mode_download_test.py
Normal 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()
|
29
tests/onionshare_share_mode_persistent_test.py
Normal 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()
|
29
tests/onionshare_share_mode_stealth_test.py
Normal 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()
|
26
tests/onionshare_share_mode_timer_test.py
Normal 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()
|
25
tests/onionshare_share_mode_tor_connection_killed_test.py
Normal 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()
|
26
tests/onionshare_share_mode_v2_onion_test.py
Normal 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()
|
@ -40,7 +40,7 @@ def settings_obj(sys_onionshare_dev_mode, platform_linux):
|
||||
|
||||
class TestSettings:
|
||||
def test_init(self, settings_obj):
|
||||
assert settings_obj._settings == settings_obj.default_settings == {
|
||||
expected_settings = {
|
||||
'version': 'DUMMY_VERSION_1.2.3',
|
||||
'connection_type': 'bundled',
|
||||
'control_port_address': '127.0.0.1',
|
||||
@ -67,6 +67,11 @@ class TestSettings:
|
||||
'downloads_dir': os.path.expanduser('~/OnionShare'),
|
||||
'public_mode': False
|
||||
}
|
||||
for key in settings_obj._settings:
|
||||
# Skip locale, it will not always default to the same thing
|
||||
if key != 'locale':
|
||||
assert settings_obj._settings[key] == settings_obj.default_settings[key]
|
||||
assert settings_obj._settings[key] == expected_settings[key]
|
||||
|
||||
def test_fill_in_defaults(self, settings_obj):
|
||||
del settings_obj._settings['version']
|
||||
|
@ -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):
|
||||
@ -32,12 +32,6 @@ from onionshare import strings
|
||||
# return path
|
||||
# common.get_resource_path = get_resource_path
|
||||
|
||||
|
||||
def test_starts_with_empty_strings():
|
||||
""" Creates an empty strings dict by default """
|
||||
assert strings.strings == {}
|
||||
|
||||
|
||||
def test_underscore_is_function():
|
||||
assert callable(strings._) and isinstance(strings._, types.FunctionType)
|
||||
|
||||
@ -46,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."
|
||||
|
||||
@ -53,11 +48,15 @@ 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 """
|
||||
strings.load_strings(common_obj, "fr")
|
||||
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."
|
||||
|
||||
def test_load_invalid_locale(
|
||||
self, common_obj, locale_invalid, sys_onionshare_dev_mode):
|
||||
""" load_strings() raises a KeyError for an invalid locale """
|
||||
with pytest.raises(KeyError):
|
||||
strings.load_strings(common_obj, 'XX')
|
||||
common_obj.settings = Settings(common_obj)
|
||||
common_obj.settings.set('locale', 'XX')
|
||||
strings.load_strings(common_obj)
|
||||
|
@ -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
|
||||
|
@ -1,307 +0,0 @@
|
||||
import os
|
||||
import requests
|
||||
import socket
|
||||
import socks
|
||||
import zipfile
|
||||
|
||||
from PyQt5 import QtCore, QtTest
|
||||
from onionshare import strings
|
||||
|
||||
class CommonTests(object):
|
||||
def test_gui_loaded(self):
|
||||
'''Test that the GUI actually is shown'''
|
||||
self.assertTrue(self.gui.show)
|
||||
|
||||
def test_windowTitle_seen(self):
|
||||
'''Test that the window title is OnionShare'''
|
||||
self.assertEqual(self.gui.windowTitle(), 'OnionShare')
|
||||
|
||||
def test_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):
|
||||
'''Test that the status bar is visible'''
|
||||
self.assertTrue(self.gui.status_bar.isVisible())
|
||||
|
||||
def test_info_widget_is_not_visible(self, mode):
|
||||
'''Test that the info widget along top of screen is not shown'''
|
||||
if mode == 'receive':
|
||||
self.assertFalse(self.gui.receive_mode.info_widget.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertFalse(self.gui.share_mode.info_widget.isVisible())
|
||||
|
||||
def test_info_widget_is_visible(self, mode):
|
||||
'''Test that the info widget along top of screen is shown'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.info_widget.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.info_widget.isVisible())
|
||||
|
||||
def test_click_mode(self, mode):
|
||||
'''Test that we can switch Mode by clicking the button'''
|
||||
if mode == 'receive':
|
||||
QtTest.QTest.mouseClick(self.gui.receive_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_RECEIVE)
|
||||
if mode == 'share':
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_SHARE)
|
||||
|
||||
def test_history_is_visible(self, mode):
|
||||
'''Test that the History section is visible and that the relevant widget is present'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.uploads.isVisible())
|
||||
self.assertTrue(self.gui.receive_mode.uploads.no_uploads_label.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.downloads.isVisible())
|
||||
self.assertTrue(self.gui.share_mode.downloads.no_downloads_label.isVisible())
|
||||
|
||||
def test_server_working_on_start_button_pressed(self, mode):
|
||||
'''Test we can start the service'''
|
||||
# Should be in SERVER_WORKING state
|
||||
if mode == 'receive':
|
||||
QtTest.QTest.mouseClick(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(self.gui.receive_mode.server_status.status, 1)
|
||||
if mode == 'share':
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(self.gui.share_mode.server_status.status, 1)
|
||||
|
||||
def test_server_status_indicator_says_starting(self, mode):
|
||||
'''Test that the Server Status indicator shows we are Starting'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
|
||||
if mode == 'share':
|
||||
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
|
||||
|
||||
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):
|
||||
'''Test that the server has started'''
|
||||
QtTest.QTest.qWait(2000)
|
||||
# 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_a_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):
|
||||
'''Test that we have a valid slug'''
|
||||
if mode == 'receive':
|
||||
if not public_mode:
|
||||
self.assertRegex(self.gui.receive_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
else:
|
||||
self.assertIsNone(self.gui.receive_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
if mode == 'share':
|
||||
if not public_mode:
|
||||
self.assertRegex(self.gui.share_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
else:
|
||||
self.assertIsNone(self.gui.share_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
|
||||
|
||||
def test_url_description_shown(self, mode):
|
||||
'''Test that the URL label is showing'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.server_status.url_description.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.server_status.url_description.isVisible())
|
||||
|
||||
def test_have_copy_url_button(self, mode):
|
||||
'''Test that the Copy URL button is shown'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.server_status.copy_url_button.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.server_status.copy_url_button.isVisible())
|
||||
|
||||
def test_server_status_indicator_says_started(self, mode):
|
||||
'''Test that the Server Status indicator shows we are started'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started', True))
|
||||
if mode == 'share':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started', True))
|
||||
|
||||
def test_web_page(self, mode, string, public_mode):
|
||||
'''Test that the web page contains a string'''
|
||||
s = socks.socksocket()
|
||||
s.settimeout(60)
|
||||
s.connect(('127.0.0.1', self.gui.app.port))
|
||||
|
||||
if not public_mode:
|
||||
if mode == 'receive':
|
||||
path = '/{}'.format(self.gui.receive_mode.server_status.web.slug)
|
||||
if mode == 'share':
|
||||
path = '/{}'.format(self.gui.share_mode.server_status.web.slug)
|
||||
else:
|
||||
path = '/'
|
||||
|
||||
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/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 test_history_widgets_present(self, mode):
|
||||
'''Test that the relevant widgets are present in the history view after activity has taken place'''
|
||||
if mode == 'receive':
|
||||
self.assertFalse(self.gui.receive_mode.uploads.no_uploads_label.isVisible())
|
||||
self.assertTrue(self.gui.receive_mode.uploads.clear_history_button.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertFalse(self.gui.share_mode.downloads.no_downloads_label.isVisible())
|
||||
self.assertTrue(self.gui.share_mode.downloads.clear_history_button.isVisible())
|
||||
|
||||
def test_counter_incremented(self, mode, count):
|
||||
'''Test that the counter has incremented'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.uploads_completed, count)
|
||||
if mode == 'share':
|
||||
self.assertEquals(self.gui.share_mode.downloads_completed, count)
|
||||
|
||||
def test_server_is_stopped(self, mode, stay_open):
|
||||
'''Test that the server stops when we click Stop'''
|
||||
if mode == 'receive':
|
||||
QtTest.QTest.mouseClick(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEquals(self.gui.receive_mode.server_status.status, 0)
|
||||
if mode == 'share':
|
||||
if stay_open:
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEquals(self.gui.share_mode.server_status.status, 0)
|
||||
|
||||
def test_web_service_is_stopped(self):
|
||||
'''Test that the web server also stopped'''
|
||||
QtTest.QTest.qWait(2000)
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
# 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):
|
||||
'''Test that the Server Status indicator shows we closed'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped', True))
|
||||
if mode == 'share':
|
||||
if stay_open:
|
||||
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped', True))
|
||||
else:
|
||||
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically', True))
|
||||
|
||||
# Auto-stop timer tests
|
||||
def test_set_timeout(self, mode, timeout):
|
||||
'''Test that the timeout can be set'''
|
||||
timer = QtCore.QDateTime.currentDateTime().addSecs(timeout)
|
||||
if mode == 'receive':
|
||||
self.gui.receive_mode.server_status.shutdown_timeout.setDateTime(timer)
|
||||
self.assertTrue(self.gui.receive_mode.server_status.shutdown_timeout.dateTime(), timer)
|
||||
if mode == 'share':
|
||||
self.gui.share_mode.server_status.shutdown_timeout.setDateTime(timer)
|
||||
self.assertTrue(self.gui.share_mode.server_status.shutdown_timeout.dateTime(), timer)
|
||||
|
||||
def test_timeout_widget_hidden(self, mode):
|
||||
'''Test that the timeout widget is hidden when share has started'''
|
||||
if mode == 'receive':
|
||||
self.assertFalse(self.gui.receive_mode.server_status.shutdown_timeout_container.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertFalse(self.gui.share_mode.server_status.shutdown_timeout_container.isVisible())
|
||||
|
||||
def test_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
|
||||
if mode == 'receive':
|
||||
self.assertEqual(self.gui.receive_mode.server_status.status, 0)
|
||||
if mode == 'share':
|
||||
self.assertEqual(self.gui.share_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))
|
||||
|
||||
# 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)
|
||||
|
||||
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 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.assertEquals(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.assertEquals('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())
|
||||
|
@ -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)
|
@ -1,182 +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, True, 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, True)
|
||||
|
||||
@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_info_widget_is_not_visible(self):
|
||||
CommonTests.test_info_widget_is_not_visible(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=6)
|
||||
def test_click_mode(self):
|
||||
CommonTests.test_click_mode(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=7)
|
||||
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_url_description_shown(self):
|
||||
CommonTests.test_url_description_shown(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=16)
|
||||
def test_have_copy_url_button(self):
|
||||
CommonTests.test_have_copy_url_button(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=17)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=18)
|
||||
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=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, 'receive')
|
||||
|
||||
@pytest.mark.run(order=21)
|
||||
def test_counter_incremented(self):
|
||||
CommonTests.test_counter_incremented(self, 'receive', 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, 'receive', 2)
|
||||
|
||||
@pytest.mark.run(order=24)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'receive', False)
|
||||
|
||||
@pytest.mark.run(order=25)
|
||||
def test_web_service_is_stopped(self):
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
@pytest.mark.run(order=26)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'receive', False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,182 +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, True, 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, True)
|
||||
|
||||
@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_info_widget_is_not_visible(self):
|
||||
CommonTests.test_info_widget_is_not_visible(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=6)
|
||||
def test_click_mode(self):
|
||||
CommonTests.test_click_mode(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=7)
|
||||
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', True)
|
||||
|
||||
@pytest.mark.run(order=15)
|
||||
def test_url_description_shown(self):
|
||||
CommonTests.test_url_description_shown(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=16)
|
||||
def test_have_copy_url_button(self):
|
||||
CommonTests.test_have_copy_url_button(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=17)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=18)
|
||||
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=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, 'receive')
|
||||
|
||||
@pytest.mark.run(order=21)
|
||||
def test_counter_incremented(self):
|
||||
CommonTests.test_counter_incremented(self, 'receive', 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, 'receive', 2)
|
||||
|
||||
@pytest.mark.run(order=24)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'receive', False)
|
||||
|
||||
@pytest.mark.run(order=25)
|
||||
def test_web_service_is_stopped(self):
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
@pytest.mark.run(order=26)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'receive', False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,189 +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, True, 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, True)
|
||||
|
||||
@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_url_description_shown(self):
|
||||
CommonTests.test_url_description_shown(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=19)
|
||||
def test_have_copy_url_button(self):
|
||||
CommonTests.test_have_copy_url_button(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=20)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=21)
|
||||
def test_web_page(self):
|
||||
CommonTests.test_web_page(self, 'share', 'Total size', False)
|
||||
|
||||
@pytest.mark.run(order=22)
|
||||
def test_download_share(self):
|
||||
CommonTests.test_download_share(self, False)
|
||||
|
||||
@pytest.mark.run(order=23)
|
||||
def test_history_widgets_present(self):
|
||||
CommonTests.test_history_widgets_present(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=24)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'share', False)
|
||||
|
||||
@pytest.mark.run(order=25)
|
||||
def test_web_service_is_stopped(self):
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
@pytest.mark.run(order=26)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'share', False)
|
||||
|
||||
@pytest.mark.run(order=27)
|
||||
def test_add_button_visible(self):
|
||||
CommonTests.test_add_button_visible(self)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,189 +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, True, 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, True)
|
||||
|
||||
@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', True)
|
||||
|
||||
@pytest.mark.run(order=18)
|
||||
def test_url_description_shown(self):
|
||||
CommonTests.test_url_description_shown(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=19)
|
||||
def test_have_copy_url_button(self):
|
||||
CommonTests.test_have_copy_url_button(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=20)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=21)
|
||||
def test_web_page(self):
|
||||
CommonTests.test_web_page(self, 'share', 'Total size', True)
|
||||
|
||||
@pytest.mark.run(order=22)
|
||||
def test_download_share(self):
|
||||
CommonTests.test_download_share(self, True)
|
||||
|
||||
@pytest.mark.run(order=23)
|
||||
def test_history_widgets_present(self):
|
||||
CommonTests.test_history_widgets_present(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=24)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'share', False)
|
||||
|
||||
@pytest.mark.run(order=25)
|
||||
def test_web_service_is_stopped(self):
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
@pytest.mark.run(order=26)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'share', False)
|
||||
|
||||
@pytest.mark.run(order=27)
|
||||
def test_add_button_visible(self):
|
||||
CommonTests.test_add_button_visible(self)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -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, True, 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, True)
|
||||
|
||||
@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', True)
|
||||
|
||||
@pytest.mark.run(order=18)
|
||||
def test_url_description_shown(self):
|
||||
CommonTests.test_url_description_shown(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=19)
|
||||
def test_have_copy_url_button(self):
|
||||
CommonTests.test_have_copy_url_button(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=20)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=21)
|
||||
def test_web_page(self):
|
||||
CommonTests.test_web_page(self, 'share', 'Total size', True)
|
||||
|
||||
@pytest.mark.run(order=22)
|
||||
def test_download_share(self):
|
||||
CommonTests.test_download_share(self, True)
|
||||
|
||||
@pytest.mark.run(order=23)
|
||||
def test_history_widgets_present(self):
|
||||
CommonTests.test_history_widgets_present(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=24)
|
||||
def test_counter_incremented(self):
|
||||
CommonTests.test_counter_incremented(self, 'share', 1)
|
||||
|
||||
@pytest.mark.run(order=25)
|
||||
def test_download_share_again(self):
|
||||
CommonTests.test_download_share(self, True)
|
||||
|
||||
@pytest.mark.run(order=26)
|
||||
def test_counter_incremented_again(self):
|
||||
CommonTests.test_counter_incremented(self, 'share', 2)
|
||||
|
||||
@pytest.mark.run(order=27)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'share', True)
|
||||
|
||||
@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', True)
|
||||
|
||||
@pytest.mark.run(order=30)
|
||||
def test_add_button_visible(self):
|
||||
CommonTests.test_add_button_visible(self)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,165 +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 = ''
|
||||
|
||||
@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, True, 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, True)
|
||||
|
||||
@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_info_widget_is_visible(self):
|
||||
CommonTests.test_info_widget_is_visible(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=6)
|
||||
def test_history_is_visible(self):
|
||||
CommonTests.test_history_is_visible(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=7)
|
||||
def test_server_working_on_start_button_pressed(self):
|
||||
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=8)
|
||||
def test_server_status_indicator_says_starting(self):
|
||||
CommonTests.test_server_status_indicator_says_starting(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=9)
|
||||
def test_settings_button_is_hidden(self):
|
||||
CommonTests.test_settings_button_is_hidden(self)
|
||||
|
||||
@pytest.mark.run(order=10)
|
||||
def test_a_server_is_started(self):
|
||||
CommonTests.test_a_server_is_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=11)
|
||||
def test_a_web_server_is_running(self):
|
||||
CommonTests.test_a_web_server_is_running(self)
|
||||
|
||||
@pytest.mark.run(order=12)
|
||||
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=13)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=14)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=15)
|
||||
def test_web_service_is_stopped(self):
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
@pytest.mark.run(order=16)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=17)
|
||||
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=18)
|
||||
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=19)
|
||||
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()
|
@ -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.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, True, 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, True)
|
||||
|
||||
@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_set_timeout(self):
|
||||
CommonTests.test_set_timeout(self, 'share', 5)
|
||||
|
||||
@pytest.mark.run(order=9)
|
||||
def test_server_working_on_start_button_pressed(self):
|
||||
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=10)
|
||||
def test_server_status_indicator_says_starting(self):
|
||||
CommonTests.test_server_status_indicator_says_starting(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=11)
|
||||
def test_a_server_is_started(self):
|
||||
CommonTests.test_a_server_is_started(self, 'share')
|
||||
|
||||
@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, 'share')
|
||||
|
||||
@pytest.mark.run(order=14)
|
||||
def test_timeout(self):
|
||||
CommonTests.test_server_timed_out(self, 'share', 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()
|
@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
for test in `ls -1 | egrep ^onionshare_`; do
|
||||
pytest $test -vvv || exit 1
|
||||
done
|
@ -1,359 +0,0 @@
|
||||
import os
|
||||
import requests
|
||||
import socket
|
||||
import socks
|
||||
import zipfile
|
||||
|
||||
from PyQt5 import QtCore, QtTest
|
||||
from onionshare import strings
|
||||
|
||||
class CommonTests(object):
|
||||
def test_gui_loaded(self):
|
||||
'''Test that the GUI actually is shown'''
|
||||
self.assertTrue(self.gui.show)
|
||||
|
||||
def test_windowTitle_seen(self):
|
||||
'''Test that the window title is OnionShare'''
|
||||
self.assertEqual(self.gui.windowTitle(), 'OnionShare')
|
||||
|
||||
def test_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):
|
||||
'''Test that the status bar is visible'''
|
||||
self.assertTrue(self.gui.status_bar.isVisible())
|
||||
|
||||
def test_info_widget_is_not_visible(self, mode):
|
||||
'''Test that the info widget along top of screen is not shown'''
|
||||
if mode == 'receive':
|
||||
self.assertFalse(self.gui.receive_mode.info_widget.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertFalse(self.gui.share_mode.info_widget.isVisible())
|
||||
|
||||
def test_info_widget_is_visible(self, mode):
|
||||
'''Test that the info widget along top of screen is shown'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.info_widget.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.info_widget.isVisible())
|
||||
|
||||
def test_click_mode(self, mode):
|
||||
'''Test that we can switch Mode by clicking the button'''
|
||||
if mode == 'receive':
|
||||
QtTest.QTest.mouseClick(self.gui.receive_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_RECEIVE)
|
||||
if mode == 'share':
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_SHARE)
|
||||
|
||||
def test_history_is_visible(self, mode):
|
||||
'''Test that the History section is visible and that the relevant widget is present'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.uploads.isVisible())
|
||||
self.assertTrue(self.gui.receive_mode.uploads.no_uploads_label.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.downloads.isVisible())
|
||||
self.assertTrue(self.gui.share_mode.downloads.no_downloads_label.isVisible())
|
||||
|
||||
def test_server_working_on_start_button_pressed(self, mode):
|
||||
'''Test we can start the service'''
|
||||
# Should be in SERVER_WORKING state
|
||||
if mode == 'receive':
|
||||
QtTest.QTest.mouseClick(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(self.gui.receive_mode.server_status.status, 1)
|
||||
if mode == 'share':
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(self.gui.share_mode.server_status.status, 1)
|
||||
|
||||
def test_server_status_indicator_says_starting(self, mode):
|
||||
'''Test that the Server Status indicator shows we are Starting'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
|
||||
if mode == 'share':
|
||||
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True))
|
||||
|
||||
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):
|
||||
'''Test that the server has started'''
|
||||
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_a_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):
|
||||
'''Test that we have a valid slug'''
|
||||
if mode == 'receive':
|
||||
if not public_mode:
|
||||
self.assertRegex(self.gui.receive_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
else:
|
||||
self.assertIsNone(self.gui.receive_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
if mode == 'share':
|
||||
if not public_mode:
|
||||
self.assertRegex(self.gui.share_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
else:
|
||||
self.assertIsNone(self.gui.share_mode.server_status.web.slug, r'(\w+)-(\w+)')
|
||||
|
||||
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_url_description_shown(self, mode):
|
||||
'''Test that the URL label is showing'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.server_status.url_description.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.server_status.url_description.isVisible())
|
||||
|
||||
def test_have_copy_url_button(self, mode):
|
||||
'''Test that the Copy URL button is shown'''
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.server_status.copy_url_button.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertTrue(self.gui.share_mode.server_status.copy_url_button.isVisible())
|
||||
|
||||
def test_server_status_indicator_says_started(self, mode):
|
||||
'''Test that the Server Status indicator shows we are started'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started', True))
|
||||
if mode == 'share':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started', True))
|
||||
|
||||
def test_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:
|
||||
if mode == 'receive':
|
||||
path = '/{}'.format(self.gui.receive_mode.server_status.web.slug)
|
||||
if mode == 'share':
|
||||
path = '/{}'.format(self.gui.share_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 test_history_widgets_present(self, mode):
|
||||
'''Test that the relevant widgets are present in the history view after activity has taken place'''
|
||||
if mode == 'receive':
|
||||
self.assertFalse(self.gui.receive_mode.uploads.no_uploads_label.isVisible())
|
||||
self.assertTrue(self.gui.receive_mode.uploads.clear_history_button.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertFalse(self.gui.share_mode.downloads.no_downloads_label.isVisible())
|
||||
self.assertTrue(self.gui.share_mode.downloads.clear_history_button.isVisible())
|
||||
|
||||
def test_counter_incremented(self, mode, count):
|
||||
'''Test that the counter has incremented'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.uploads_completed, count)
|
||||
if mode == 'share':
|
||||
self.assertEquals(self.gui.share_mode.downloads_completed, count)
|
||||
|
||||
def test_server_is_stopped(self, mode, stay_open):
|
||||
'''Test that the server stops when we click Stop'''
|
||||
if mode == 'receive':
|
||||
QtTest.QTest.mouseClick(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEquals(self.gui.receive_mode.server_status.status, 0)
|
||||
if mode == 'share':
|
||||
if stay_open:
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEquals(self.gui.share_mode.server_status.status, 0)
|
||||
|
||||
def test_web_service_is_stopped(self):
|
||||
'''Test that the web server also stopped'''
|
||||
QtTest.QTest.qWait(2000)
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
# 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):
|
||||
'''Test that the Server Status indicator shows we closed'''
|
||||
if mode == 'receive':
|
||||
self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped', True))
|
||||
if mode == 'share':
|
||||
if stay_open:
|
||||
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped', True))
|
||||
else:
|
||||
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically', True))
|
||||
|
||||
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)
|
||||
|
||||
|
||||
# Auto-stop timer tests
|
||||
def test_set_timeout(self, mode, timeout):
|
||||
'''Test that the timeout can be set'''
|
||||
timer = QtCore.QDateTime.currentDateTime().addSecs(timeout)
|
||||
if mode == 'receive':
|
||||
self.gui.receive_mode.server_status.shutdown_timeout.setDateTime(timer)
|
||||
self.assertTrue(self.gui.receive_mode.server_status.shutdown_timeout.dateTime(), timer)
|
||||
if mode == 'share':
|
||||
self.gui.share_mode.server_status.shutdown_timeout.setDateTime(timer)
|
||||
self.assertTrue(self.gui.share_mode.server_status.shutdown_timeout.dateTime(), timer)
|
||||
|
||||
def test_timeout_widget_hidden(self, mode):
|
||||
'''Test that the timeout widget is hidden when share has started'''
|
||||
if mode == 'receive':
|
||||
self.assertFalse(self.gui.receive_mode.server_status.shutdown_timeout_container.isVisible())
|
||||
if mode == 'share':
|
||||
self.assertFalse(self.gui.share_mode.server_status.shutdown_timeout_container.isVisible())
|
||||
|
||||
def test_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
|
||||
if mode == 'receive':
|
||||
self.assertEqual(self.gui.receive_mode.server_status.status, 0)
|
||||
if mode == 'share':
|
||||
self.assertEqual(self.gui.share_mode.server_status.status, 0)
|
||||
|
||||
# Receive-specific tests
|
||||
def test_upload_file(self, public_mode, 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('/tmp/test.txt', '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))
|
||||
|
||||
# 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)
|
||||
|
||||
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 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.assertEquals(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'''
|
||||
(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 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: {}\r\n'.format(self.gui.app.onion_host)
|
||||
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(4000)
|
||||
self.assertEquals('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())
|
||||
|
||||
|
||||
# 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', True))
|
||||
if mode == 'receive':
|
||||
self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost', True))
|
@ -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)
|
@ -1,186 +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=5)
|
||||
def test_info_widget_is_not_visible(self):
|
||||
CommonTests.test_info_widget_is_not_visible(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=6)
|
||||
def test_click_mode(self):
|
||||
CommonTests.test_click_mode(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=7)
|
||||
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=16)
|
||||
def test_url_description_shown(self):
|
||||
CommonTests.test_url_description_shown(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=17)
|
||||
def test_have_copy_url_button(self):
|
||||
CommonTests.test_have_copy_url_button(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=18)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=19)
|
||||
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=20)
|
||||
def test_upload_file(self):
|
||||
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test.txt')
|
||||
|
||||
@pytest.mark.run(order=21)
|
||||
def test_history_widgets_present(self):
|
||||
CommonTests.test_history_widgets_present(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=22)
|
||||
def test_counter_incremented(self):
|
||||
CommonTests.test_counter_incremented(self, 'receive', 1)
|
||||
|
||||
@pytest.mark.run(order=23)
|
||||
def test_upload_same_file_is_renamed(self):
|
||||
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test-2.txt')
|
||||
|
||||
@pytest.mark.run(order=24)
|
||||
def test_upload_count_incremented_again(self):
|
||||
CommonTests.test_counter_incremented(self, 'receive', 2)
|
||||
|
||||
@pytest.mark.run(order=25)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'receive', 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, 'receive', False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,186 +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_info_widget_is_not_visible(self):
|
||||
CommonTests.test_info_widget_is_not_visible(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=6)
|
||||
def test_click_mode(self):
|
||||
CommonTests.test_click_mode(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=7)
|
||||
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', True)
|
||||
|
||||
@pytest.mark.run(order=15)
|
||||
def test_have_an_onion(self):
|
||||
CommonTests.test_have_an_onion_service(self)
|
||||
|
||||
@pytest.mark.run(order=16)
|
||||
def test_url_description_shown(self):
|
||||
CommonTests.test_url_description_shown(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=17)
|
||||
def test_have_copy_url_button(self):
|
||||
CommonTests.test_have_copy_url_button(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=18)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=19)
|
||||
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=20)
|
||||
def test_upload_file(self):
|
||||
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test.txt')
|
||||
|
||||
@pytest.mark.run(order=21)
|
||||
def test_history_widgets_present(self):
|
||||
CommonTests.test_history_widgets_present(self, 'receive')
|
||||
|
||||
@pytest.mark.run(order=22)
|
||||
def test_counter_incremented(self):
|
||||
CommonTests.test_counter_incremented(self, 'receive', 1)
|
||||
|
||||
@pytest.mark.run(order=23)
|
||||
def test_upload_same_file_is_renamed(self):
|
||||
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test-2.txt')
|
||||
|
||||
@pytest.mark.run(order=24)
|
||||
def test_upload_count_incremented_again(self):
|
||||
CommonTests.test_counter_incremented(self, 'receive', 2)
|
||||
|
||||
@pytest.mark.run(order=25)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'receive', 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, 'receive', False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,157 +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=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()
|
@ -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_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_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()
|
@ -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": 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_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', True)
|
||||
|
||||
@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', True)
|
||||
|
||||
@pytest.mark.run(order=23)
|
||||
def test_download_share(self):
|
||||
CommonTests.test_download_share(self, True)
|
||||
|
||||
@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()
|
@ -1,205 +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_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', True)
|
||||
|
||||
@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', True)
|
||||
|
||||
@pytest.mark.run(order=23)
|
||||
def test_download_share(self):
|
||||
CommonTests.test_download_share(self, True)
|
||||
|
||||
@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_counter_incremented(self):
|
||||
CommonTests.test_counter_incremented(self, 'share', 1)
|
||||
|
||||
@pytest.mark.run(order=26)
|
||||
def test_download_share_again(self):
|
||||
CommonTests.test_download_share(self, True)
|
||||
|
||||
@pytest.mark.run(order=27)
|
||||
def test_counter_incremented_again(self):
|
||||
CommonTests.test_counter_incremented(self, 'share', 2)
|
||||
|
||||
@pytest.mark.run(order=28)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=29)
|
||||
def test_web_service_is_stopped(self):
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
@pytest.mark.run(order=30)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=31)
|
||||
def test_add_button_visible(self):
|
||||
CommonTests.test_add_button_visible(self)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,177 +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=5)
|
||||
def test_info_widget_is_visible(self):
|
||||
CommonTests.test_info_widget_is_visible(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=6)
|
||||
def test_history_is_visible(self):
|
||||
CommonTests.test_history_is_visible(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=7)
|
||||
def test_server_working_on_start_button_pressed(self):
|
||||
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=8)
|
||||
def test_server_status_indicator_says_starting(self):
|
||||
CommonTests.test_server_status_indicator_says_starting(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=9)
|
||||
def test_settings_button_is_hidden(self):
|
||||
CommonTests.test_settings_button_is_hidden(self)
|
||||
|
||||
@pytest.mark.run(order=10)
|
||||
def test_a_server_is_started(self):
|
||||
CommonTests.test_a_server_is_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=11)
|
||||
def test_a_web_server_is_running(self):
|
||||
CommonTests.test_a_web_server_is_running(self)
|
||||
|
||||
@pytest.mark.run(order=12)
|
||||
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=13)
|
||||
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=14)
|
||||
def test_server_status_indicator_says_started(self):
|
||||
CommonTests.test_server_status_indicator_says_started(self, 'share')
|
||||
|
||||
@pytest.mark.run(order=15)
|
||||
def test_server_is_stopped(self):
|
||||
CommonTests.test_server_is_stopped(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=16)
|
||||
def test_web_service_is_stopped(self):
|
||||
CommonTests.test_web_service_is_stopped(self)
|
||||
|
||||
@pytest.mark.run(order=17)
|
||||
def test_server_status_indicator_says_closed(self):
|
||||
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
|
||||
|
||||
@pytest.mark.run(order=18)
|
||||
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=19)
|
||||
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=20)
|
||||
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=21)
|
||||
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()
|