fixed vanity not working and added integration test for it

This commit is contained in:
Kevin Froman 2020-02-22 05:44:21 -06:00
parent 6b5e6a9ad0
commit 34a55f63f9
5 changed files with 49 additions and 3 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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()

View File

@ -1 +1 @@
1581492045
1582370175