@ -0,0 +1,61 @@ | |||
"""Onionr - Private P2P Communication. | |||
Ensure that clearnet cannot be reached | |||
""" | |||
from threading import Thread | |||
from onionrutils.basicrequests import do_get_request | |||
from onionrutils import localcommand | |||
import logger | |||
import config | |||
""" | |||
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 <https://www.gnu.org/licenses/>. | |||
""" | |||
def test_clearnet_tor_request(testmanager): | |||
"""Ensure that Tor cannot request clearnet address. | |||
Does not run if Tor is being reused | |||
""" | |||
config.reload() | |||
leak_result = "" | |||
if config.get('tor.use_existing_tor', False): | |||
logger.warn( | |||
"Can't ensure Tor reqs to clearnet won't happen when reusing Tor") | |||
return | |||
socks_port = localcommand.local_command('/gettorsocks') | |||
# Don't worry, this request isn't meant to go through, | |||
# but if it did it would be through Tor | |||
try: | |||
leak_result: str = do_get_request( | |||
'https://onionr.net/404', | |||
port=socks_port, ignoreAPI=True).lower() | |||
except AttributeError: | |||
leak_result = "" | |||
except Exception as e: | |||
logger.warn(str(e)) | |||
try: | |||
if 'not found' in leak_result: | |||
logger.error('Tor was able to request a clearnet site') | |||
raise ValueError('Tor was able to request a clearnet site') | |||
except TypeError: | |||
pass |
@ -1,4 +1,4 @@ | |||
{ "name": "flow", | |||
"version": "0.0.1", | |||
"version": "0.1.0", | |||
"author": "onionr" | |||
} |
@ -0,0 +1,18 @@ | |||
import sys | |||
import os | |||
from subprocess import Popen, PIPE | |||
import uuid | |||
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' | |||
os.environ["ONIONR_HOME"] = TEST_DIR | |||
print(f'running integration test for {__file__}') | |||
with Popen(['./onionr.sh', 'details'], stdout=PIPE) as onionr_proc: | |||
output = onionr_proc.stdout.read().decode() | |||
if onionr_proc.returncode != 0: | |||
raise ValueError('Raised non zero exit ' + str(onionr_proc.returncode)) | |||
for word in ['Node', 'Human-readable']: | |||
if word not in output: | |||
raise ValueError(word + " not in " + output) |
@ -0,0 +1,40 @@ | |||
from unittest.mock import patch | |||
import sys, os | |||
sys.path.append(".") | |||
sys.path.append("src/") | |||
import unittest, uuid | |||
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' | |||
print("Test directory:", TEST_DIR) | |||
os.environ["ONIONR_HOME"] = TEST_DIR | |||
from utils import createdirs | |||
from onionrcommands import parser | |||
import onionrsetup as setup | |||
from netcontroller.torcontrol import customtorrc | |||
from utils import createdirs | |||
from onionrsetup import setup_config, setup_default_plugins | |||
from coredb import blockmetadb | |||
from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT | |||
createdirs.create_dirs() | |||
setup_config() | |||
setup_default_plugins() | |||
import config | |||
from filepaths import export_location | |||
class OnionrTests(unittest.TestCase): | |||
def test_export(self): | |||
testargs = ["onionr.py", "flowsend", "tests", "hello"] | |||
with patch.object(sys, 'argv', testargs): | |||
parser.register() | |||
bl = blockmetadb.get_block_list()[0] | |||
testargs = ["onionr.py", "export-block", bl] | |||
with patch.object(sys, 'argv', testargs): | |||
parser.register() | |||
with open(export_location + '/' + bl + BLOCK_EXPORT_FILE_EXT, 'rb') as f: | |||
if b'hello' not in f.read(): | |||
raise ValueError('No exported block') | |||
unittest.main() |
@ -0,0 +1,16 @@ | |||
import sys | |||
import os | |||
from subprocess import Popen, PIPE | |||
import uuid | |||
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' | |||
os.environ["ONIONR_HOME"] = TEST_DIR | |||
print(f'running integration test for {__file__}') | |||
with Popen(['./onionr.sh'], stdout=PIPE) as onionr_proc: | |||
output = onionr_proc.stdout.read().decode() | |||
if onionr_proc.returncode != 0: | |||
raise ValueError('Raised non zero exit ' + str(onionr_proc.returncode)) | |||
if output != '': | |||
raise ValueError('No command run returned non-blank output') |
@ -1 +1 @@ | |||
1580971981 | |||
1581152327 |