From 34a55f63f9da4d3cdabb4a1418920c86df18d2a3 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 22 Feb 2020 05:44:21 -0600 Subject: [PATCH] fixed vanity not working and added integration test for it --- src/bigbrother/ministry/ofexec.py | 5 ++++ src/notifier/__init__.py | 2 +- src/onionrcommands/pubkeymanager.py | 2 +- tests/integration-tests/vanity-test.py | 41 ++++++++++++++++++++++++++ tests/runtime-result.txt | 2 +- 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tests/integration-tests/vanity-test.py diff --git a/src/bigbrother/ministry/ofexec.py b/src/bigbrother/ministry/ofexec.py index 9df6460f..613b0fef 100644 --- a/src/bigbrother/ministry/ofexec.py +++ b/src/bigbrother/ministry/ofexec.py @@ -55,6 +55,8 @@ def block_exec(event, info): 'multiprocessing/popen_fork.py', 'multiprocessing/util.py', 'multiprocessing/connection.py', + 'multiprocessing/queues.py', + 'multiprocessing/synchronize.py', 'onionrutils/escapeansi.py', 'stem/connection.py', 'stem/response/add_onion.py', @@ -64,9 +66,12 @@ def block_exec(event, info): 'stem/response/mapaddress.py', 'stem/response/protocolinfo.py' ] + whitelisted_source = [] home = identifyhome.identify_home() code_b64 = base64.b64encode(info[0].co_code).decode() + if code_b64 in whitelisted_source: + return for source in whitelisted_code: if info[0].co_filename.endswith(source): diff --git a/src/notifier/__init__.py b/src/notifier/__init__.py index bceb9c1a..ed3d0206 100644 --- a/src/notifier/__init__.py +++ b/src/notifier/__init__.py @@ -43,7 +43,7 @@ def notify(title: str = "Onionr", message: str = ""): simplenotify.notify(title, message) -def notification_with_sound(sound = '', **kwargs): +def notification_with_sound(sound='', **kwargs): if not notifications_enabled: return if not sound: diff --git a/src/onionrcommands/pubkeymanager.py b/src/onionrcommands/pubkeymanager.py index 4b45d357..77011b78 100755 --- a/src/onionrcommands/pubkeymanager.py +++ b/src/onionrcommands/pubkeymanager.py @@ -148,7 +148,7 @@ def add_vanity(): else: b32_pub = unpaddedbase32.b32encode(vanity[0]) tell('Found vanity address:\n' + - niceware.bytes_to_passphrase(vanity[0])) + '-'.join(niceware.bytes_to_passphrase(vanity[0]))) tell('Base32 Public key: %s' % (b32_pub.decode(),)) key_manager.addKey(b32_pub, unpaddedbase32.b32encode(vanity[1])) except KeyboardInterrupt: diff --git a/tests/integration-tests/vanity-test.py b/tests/integration-tests/vanity-test.py new file mode 100644 index 00000000..40d4856f --- /dev/null +++ b/tests/integration-tests/vanity-test.py @@ -0,0 +1,41 @@ +from unittest.mock import patch +import sys, os +sys.path.append(".") +sys.path.append("src/") +import unittest, uuid +import base64 +import niceware +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 utils import createdirs +from onionrsetup import setup_config, setup_default_plugins +import unpaddedbase32 + +createdirs.create_dirs() +setup_config() +setup_default_plugins() +import config +from filepaths import keys_file + +class OnionrTests(unittest.TestCase): + def test_vanity(self): + testargs = ["onionr.py"] + with patch.object(sys, 'argv', testargs): + parser.register() + testargs = ["onionr.py", "add-vanity", "jolt"] + with patch.object(sys, 'argv', testargs): + parser.register() + with open(keys_file, 'r') as keys: + key_list = keys.read().split('\n') + print('vanity key list test key database contents:', key_list) + if not niceware.bytes_to_passphrase(unpaddedbase32.b32decode(key_list[1].split(',')[0]))[0].startswith('jolt'): + raise ValueError('Vanity generation failed') + + + + +unittest.main() diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt index ff30a763..d38cab30 100644 --- a/tests/runtime-result.txt +++ b/tests/runtime-result.txt @@ -1 +1 @@ -1581492045 +1582370175 \ No newline at end of file