added integration test for persistent setting of the payment key, fixed bugs that it surfaced

This commit is contained in:
Aaron Blankstein
2017-08-17 17:39:31 -04:00
parent 5c0e4f2606
commit 17d6043731
4 changed files with 331 additions and 16 deletions

View File

@@ -2283,13 +2283,13 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
if privkey_info is None or 'error' in privkey_info:
return self._reply_json({'error': 'Failed to validate private key'}, status_code=401)
wallet = backend.registrar.get_wallet(config_path=self.server.config_path)
if 'error' in wallet:
return self._reply_json({'error': wallet['error']}, status_code=500)
new_wallet = backend.registrar.get_wallet(config_path=self.server.config_path)
if 'error' in new_wallet:
return self._reply_json({'error': new_wallet['error']}, status_code=500)
payment_privkey_info = wallet['payment_privkey']
owner_privkey_info = wallet['owner_privkey']
data_privkey_info = wallet['data_privkey']
payment_privkey_info = new_wallet['payment_privkey']
owner_privkey_info = new_wallet['owner_privkey']
data_privkey_info = new_wallet['data_privkey']
if key_id == 'owner':
owner_privkey_info = privkey_info
@@ -2304,27 +2304,27 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
return self._reply_json({'error': 'Failed to set private key info'}, status_code=401)
# convert...
wallet = make_wallet(None, payment_privkey_info=payment_privkey_info, owner_privkey_info=owner_privkey_info,
data_privkey_info=data_privkey_info, encrypt=False)
new_wallet = make_wallet(None, payment_privkey_info=payment_privkey_info, owner_privkey_info=owner_privkey_info,
data_privkey_info=data_privkey_info, encrypt=False)
if persist:
password = get_secret('BLOCKSTACK_CLIENT_WALLET_PASSWORD')
if not password:
return self._reply_json(
{'error' : 'Failed to load encryption password for wallet, refusing to persist key change.'}, 500)
status = save_modified_wallet(wallet, password, config_path = self.server.config_path)
status = wallet.save_modified_wallet(new_wallet, password, config_path = self.server.config_path)
if 'error' in status:
return self._reply_json(status, 500)
if 'error' in wallet:
if 'error' in new_wallet:
return self._reply_json({'error': 'Failed to reinstantiate wallet'}, status_code=500)
res = backend.registrar.set_wallet( (wallet['payment_addresses'][0], wallet['payment_privkey']),
(wallet['owner_addresses'][0], wallet['owner_privkey']),
(wallet['data_pubkeys'][0], wallet['data_privkey']), config_path=self.server.config_path )
res = backend.registrar.set_wallet( (new_wallet['payment_addresses'][0], new_wallet['payment_privkey']),
(new_wallet['owner_addresses'][0], new_wallet['owner_privkey']),
(new_wallet['data_pubkeys'][0], new_wallet['data_privkey']), config_path=self.server.config_path )
if 'error' in res:
return self._reply_json({'error': 'Failed to set wallet: {}'.format(res['error'])}, status_code=500)
self.server.wallet_keys = wallet
self.server.wallet_keys = new_wallet
return self._reply_json({'status': True})

View File

@@ -161,7 +161,7 @@ def encrypt_wallet(decrypted_wallet, password, test_legacy=False):
return wallet
def save_modified_wallet(decrypted_wallet, password, config_dir = CONFIG_DIR):
def save_modified_wallet(decrypted_wallet, password, config_path = CONFIG_PATH):
"""
Encrypt and save a given @decrypted_wallet using @password at the
wallet path specified by the @config_dir (or default)
@@ -169,6 +169,7 @@ def save_modified_wallet(decrypted_wallet, password, config_dir = CONFIG_DIR):
Return {'status' : True} on success
Return {'error' : ...} on failure
"""
config_dir = os.path.dirname(config_path)
wallet_path = os.path.join(config_dir, WALLET_FILENAME)
@@ -184,7 +185,7 @@ def save_modified_wallet(decrypted_wallet, password, config_dir = CONFIG_DIR):
return {'error' :
'Could not persist new wallet, failed to backup previous wallet at {}'.format(wallet_path)}
write_wallet(encrypted_wallet, path=wallet_path)
return write_wallet(encrypted_wallet, path=wallet_path)
def make_wallet(password, payment_privkey_info=None, owner_privkey_info=None, data_privkey_info=None, test_legacy=False, encrypt=True):
"""