2014-09-02 15:10:42 -04:00
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
2018-04-24 13:07:59 -04:00
|
|
|
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
2014-09-02 15:10:42 -04:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
"""
|
2017-07-08 13:30:26 -04:00
|
|
|
|
2017-07-08 01:14:47 -04:00
|
|
|
import os
|
2017-07-05 16:44:27 -04:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2017-07-08 13:30:26 -04:00
|
|
|
from onionshare import OnionShare
|
2018-03-13 05:22:26 -04:00
|
|
|
from onionshare.common import Common
|
2019-11-02 20:01:47 -04:00
|
|
|
from onionshare.mode_settings import ModeSettings
|
2017-07-05 16:44:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
class MyOnion:
|
2019-11-02 20:01:47 -04:00
|
|
|
def __init__(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
self.auth_string = "TestHidServAuth"
|
|
|
|
self.private_key = ""
|
2019-03-04 18:28:27 -05:00
|
|
|
self.scheduled_key = None
|
2017-07-05 16:44:27 -04:00
|
|
|
|
|
|
|
@staticmethod
|
2019-03-04 18:28:27 -05:00
|
|
|
def start_onion_service(self, await_publication=True, save_scheduled_key=False):
|
2019-10-13 00:01:25 -04:00
|
|
|
return "test_service_id.onion"
|
2017-07-05 16:44:27 -04:00
|
|
|
|
|
|
|
|
2017-07-08 13:30:26 -04:00
|
|
|
@pytest.fixture
|
2017-07-05 16:44:27 -04:00
|
|
|
def onionshare_obj():
|
2018-03-13 05:22:26 -04:00
|
|
|
common = Common()
|
|
|
|
return OnionShare(common, MyOnion())
|
2017-07-05 16:44:27 -04:00
|
|
|
|
|
|
|
|
2019-11-02 20:01:47 -04:00
|
|
|
@pytest.fixture
|
|
|
|
def mode_settings_obj():
|
|
|
|
common = Common()
|
|
|
|
return ModeSettings(common)
|
|
|
|
|
|
|
|
|
2017-07-05 16:44:27 -04:00
|
|
|
class TestOnionShare:
|
|
|
|
def test_init(self, onionshare_obj):
|
|
|
|
assert onionshare_obj.hidserv_dir is None
|
|
|
|
assert onionshare_obj.onion_host is None
|
|
|
|
assert onionshare_obj.cleanup_filenames == []
|
|
|
|
assert onionshare_obj.local_only is False
|
|
|
|
|
2019-11-02 20:01:47 -04:00
|
|
|
def test_start_onion_service(self, onionshare_obj, mode_settings_obj):
|
|
|
|
onionshare_obj.start_onion_service(mode_settings_obj)
|
2017-07-05 16:44:27 -04:00
|
|
|
assert 17600 <= onionshare_obj.port <= 17650
|
2019-10-13 00:01:25 -04:00
|
|
|
assert onionshare_obj.onion_host == "test_service_id.onion"
|
2017-07-05 16:44:27 -04:00
|
|
|
|
2019-11-02 20:01:47 -04:00
|
|
|
def test_start_onion_service_local_only(self, onionshare_obj, mode_settings_obj):
|
2017-07-05 16:44:27 -04:00
|
|
|
onionshare_obj.local_only = True
|
2019-11-02 20:01:47 -04:00
|
|
|
onionshare_obj.start_onion_service(mode_settings_obj)
|
2019-10-13 00:01:25 -04:00
|
|
|
assert onionshare_obj.onion_host == "127.0.0.1:{}".format(onionshare_obj.port)
|
2017-07-05 16:44:27 -04:00
|
|
|
|
2017-07-08 01:14:47 -04:00
|
|
|
def test_cleanup(self, onionshare_obj, temp_dir_1024, temp_file_1024):
|
|
|
|
onionshare_obj.cleanup_filenames = [temp_dir_1024, temp_file_1024]
|
|
|
|
onionshare_obj.cleanup()
|
|
|
|
|
|
|
|
assert os.path.exists(temp_dir_1024) is False
|
|
|
|
assert os.path.exists(temp_dir_1024) is False
|
2017-07-05 16:44:27 -04:00
|
|
|
assert onionshare_obj.cleanup_filenames == []
|