mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-17 21:04:07 -05:00
Add a few receive mode web tests, to test the receive_allow_receiver_shutdown and receive_public_mode settings
This commit is contained in:
parent
7ec993d2e0
commit
86f1fb223e
@ -495,10 +495,13 @@ class Web(object):
|
|||||||
Stop the flask web server, from the context of the flask app.
|
Stop the flask web server, from the context of the flask app.
|
||||||
"""
|
"""
|
||||||
# Shutdown the flask service
|
# Shutdown the flask service
|
||||||
func = request.environ.get('werkzeug.server.shutdown')
|
try:
|
||||||
if func is None:
|
func = request.environ.get('werkzeug.server.shutdown')
|
||||||
raise RuntimeError('Not running with the Werkzeug Server')
|
if func is None:
|
||||||
func()
|
raise RuntimeError('Not running with the Werkzeug Server')
|
||||||
|
func()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
def start(self, port, stay_open=False, persistent_slug=None):
|
def start(self, port, stay_open=False, persistent_slug=None):
|
||||||
|
@ -152,3 +152,9 @@ def time_strftime(monkeypatch):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def common_obj():
|
def common_obj():
|
||||||
return common.Common()
|
return common.Common()
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def settings_obj(sys_onionshare_dev_mode, platform_linux):
|
||||||
|
_common = common.Common()
|
||||||
|
_common.version = 'DUMMY_VERSION_1.2.3'
|
||||||
|
return settings.Settings(_common)
|
||||||
|
@ -32,6 +32,7 @@ import pytest
|
|||||||
|
|
||||||
from onionshare.common import Common
|
from onionshare.common import Common
|
||||||
from onionshare.web import Web
|
from onionshare.web import Web
|
||||||
|
from onionshare.settings import Settings
|
||||||
|
|
||||||
DEFAULT_ZW_FILENAME_REGEX = re.compile(r'^onionshare_[a-z2-7]{6}.zip$')
|
DEFAULT_ZW_FILENAME_REGEX = re.compile(r'^onionshare_[a-z2-7]{6}.zip$')
|
||||||
RANDOM_STR_REGEX = re.compile(r'^[a-z2-7]+$')
|
RANDOM_STR_REGEX = re.compile(r'^[a-z2-7]+$')
|
||||||
@ -39,6 +40,8 @@ RANDOM_STR_REGEX = re.compile(r'^[a-z2-7]+$')
|
|||||||
|
|
||||||
def web_obj(common_obj, recieve_mode, num_files=0):
|
def web_obj(common_obj, recieve_mode, num_files=0):
|
||||||
""" Creates a Web object, in either share mode or receive mode, ready for testing """
|
""" Creates a Web object, in either share mode or receive mode, ready for testing """
|
||||||
|
common_obj.load_settings()
|
||||||
|
|
||||||
web = Web(common_obj, False, recieve_mode)
|
web = Web(common_obj, False, recieve_mode)
|
||||||
web.generate_slug()
|
web.generate_slug()
|
||||||
web.stay_open = True
|
web.stay_open = True
|
||||||
@ -87,7 +90,7 @@ class TestWeb:
|
|||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
assert res.mimetype == 'application/zip'
|
assert res.mimetype == 'application/zip'
|
||||||
|
|
||||||
def test_share_mode_close_after_first_download(self, common_obj, temp_file_1024):
|
def test_share_mode_close_after_first_download_on(self, common_obj, temp_file_1024):
|
||||||
web = web_obj(common_obj, False, 3)
|
web = web_obj(common_obj, False, 3)
|
||||||
web.stay_open = False
|
web.stay_open = False
|
||||||
|
|
||||||
@ -102,6 +105,98 @@ class TestWeb:
|
|||||||
|
|
||||||
assert web.running == False
|
assert web.running == False
|
||||||
|
|
||||||
|
def test_share_mode_close_after_first_download_off(self, common_obj, temp_file_1024):
|
||||||
|
web = web_obj(common_obj, False, 3)
|
||||||
|
web.stay_open = True
|
||||||
|
|
||||||
|
assert web.running == True
|
||||||
|
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
# Download the first time
|
||||||
|
res = c.get('/{}/download'.format(web.slug))
|
||||||
|
res.get_data()
|
||||||
|
assert res.status_code == 200
|
||||||
|
assert res.mimetype == 'application/zip'
|
||||||
|
assert web.running == True
|
||||||
|
|
||||||
|
def test_receive_mode(self, common_obj):
|
||||||
|
web = web_obj(common_obj, True)
|
||||||
|
assert web.receive_mode is True
|
||||||
|
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
# Load 404 pages
|
||||||
|
res = c.get('/')
|
||||||
|
res.get_data()
|
||||||
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
res = c.get('/invalidslug'.format(web.slug))
|
||||||
|
res.get_data()
|
||||||
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
# Load upload page
|
||||||
|
res = c.get('/{}'.format(web.slug))
|
||||||
|
res.get_data()
|
||||||
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
def test_receive_mode_allow_receiver_shutdown_on(self, common_obj):
|
||||||
|
web = web_obj(common_obj, True)
|
||||||
|
|
||||||
|
common_obj.settings.set('receive_allow_receiver_shutdown', True)
|
||||||
|
|
||||||
|
assert web.running == True
|
||||||
|
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
# Load close page
|
||||||
|
res = c.post('/{}/close'.format(web.slug))
|
||||||
|
res.get_data()
|
||||||
|
# Should return ok, and server should stop
|
||||||
|
assert res.status_code == 200
|
||||||
|
assert web.running == False
|
||||||
|
|
||||||
|
def test_receive_mode_allow_receiver_shutdown_off(self, common_obj):
|
||||||
|
web = web_obj(common_obj, True)
|
||||||
|
|
||||||
|
common_obj.settings.set('receive_allow_receiver_shutdown', False)
|
||||||
|
|
||||||
|
assert web.running == True
|
||||||
|
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
# Load close page
|
||||||
|
res = c.post('/{}/close'.format(web.slug))
|
||||||
|
res.get_data()
|
||||||
|
# Should redirect to index, and server should still be running
|
||||||
|
assert res.status_code == 302
|
||||||
|
assert web.running == True
|
||||||
|
|
||||||
|
def test_receive_mode_receive_public_mode_on(self, common_obj):
|
||||||
|
web = web_obj(common_obj, True)
|
||||||
|
common_obj.settings.set('receive_public_mode', True)
|
||||||
|
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
# Upload page should be accessible from both / and /[slug]
|
||||||
|
res = c.get('/')
|
||||||
|
data1 = res.get_data()
|
||||||
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
res = c.get('/{}'.format(web.slug))
|
||||||
|
data2 = res.get_data()
|
||||||
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
def test_receive_mode_receive_public_mode_off(self, common_obj):
|
||||||
|
web = web_obj(common_obj, True)
|
||||||
|
common_obj.settings.set('receive_public_mode', False)
|
||||||
|
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
# / should be a 404
|
||||||
|
res = c.get('/')
|
||||||
|
data1 = res.get_data()
|
||||||
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
# Upload page should be accessible from both /[slug]
|
||||||
|
res = c.get('/{}'.format(web.slug))
|
||||||
|
data2 = res.get_data()
|
||||||
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
class TestZipWriterDefault:
|
class TestZipWriterDefault:
|
||||||
@pytest.mark.parametrize('test_input', (
|
@pytest.mark.parametrize('test_input', (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user