New Bob CLI test to show retrieve().

pull/2712/head
jMyles 2019-08-22 10:33:21 +02:00
parent b9bc66d2ff
commit 1a34a2a60a
2 changed files with 87 additions and 2 deletions

View File

@ -158,6 +158,7 @@ class TreasureMap:
Ursula will refuse to propagate this if it she can't prove the payload is signed by Alice's public key,
which is included in it,
"""
# TODO: No reason to keccak this over and over again. Turn into set-once property pattern.
_id = keccak_digest(bytes(self._verifying_key) + bytes(self._hrac)).hex()
return _id

View File

@ -1,10 +1,12 @@
import json
import os
from base64 import b64encode
from unittest import mock
from nucypher.characters.control.emitters import JSONRPCStdoutEmitter
from nucypher.characters.lawful import Ursula
from nucypher.cli.main import nucypher_cli
from nucypher.config.characters import BobConfiguration
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD, \
MOCK_IP_ADDRESS, MOCK_CUSTOM_INSTALLATION_PATH, TEMPORARY_DOMAIN
from nucypher.cli.actions import SUCCESSFUL_DESTRUCTION
@ -26,6 +28,10 @@ def test_bob_public_keys(click_runner):
assert result.exit_code == 0
assert "bob_encrypting_key" in result.output
assert "bob_verifying_key" in result.output
from nucypher.crypto.kits import UmbralMessageKit
from nucypher.crypto.powers import SigningPower
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD, TEMPORARY_DOMAIN
from nucypher.utilities.sandbox.constants import MOCK_IP_ADDRESS, MOCK_CUSTOM_INSTALLATION_PATH
def test_initialize_bob_with_custom_configuration_root(custom_filepath, click_runner):
@ -87,6 +93,16 @@ def test_bob_view_with_preexisting_configuration(click_runner, custom_filepath):
assert custom_filepath in result.output
def test_bob_public_keys(click_runner):
derive_key_args = ('bob', 'public-keys', '--dev')
result = click_runner.invoke(nucypher_cli, derive_key_args, catch_exceptions=False)
assert result.exit_code == 0
assert "bob_encrypting_key" in result.output
assert "bob_verifying_key" in result.output
# Should be the last test since it deletes the configuration file
def test_bob_destroy(click_runner, custom_filepath):
custom_config_filepath = os.path.join(custom_filepath, BobConfiguration.generate_filename())
@ -98,3 +114,71 @@ def test_bob_destroy(click_runner, custom_filepath):
assert result.exit_code == 0
assert SUCCESSFUL_DESTRUCTION in result.output
assert not os.path.exists(custom_config_filepath), "Bob config file was deleted"
result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False)
assert result.exit_code == 2
assert 'Cannot create a persistent development character' in result.output, 'Missing or invalid error message was produced.'
def test_bob_retrieve_args(click_runner,
capsule_side_channel,
enacted_federated_policy,
federated_ursulas,
custom_filepath_2,
federated_alice
):
teacher = list(federated_ursulas)[0]
first_message = capsule_side_channel.reset(plaintext_passthrough=True)
three_message_kits = [capsule_side_channel(), capsule_side_channel(), capsule_side_channel()]
bob_config_root = custom_filepath_2
bob_configuration_file_location = os.path.join(bob_config_root, BobConfiguration.generate_filename())
label = enacted_federated_policy.label
# I already have a Bob.
# Need to init so that the config file is made, even though we won't use this Bob.
bob_init_args = ('bob', 'init',
'--network', TEMPORARY_DOMAIN,
'--config-root', bob_config_root,
'--federated-only')
envvars = {'NUCYPHER_KEYRING_PASSWORD': INSECURE_DEVELOPMENT_PASSWORD}
bob_init_response = click_runner.invoke(nucypher_cli, bob_init_args, catch_exceptions=False, env=envvars)
message_kit_bytes = bytes(three_message_kits[0])
message_kit_b64_bytes = b64encode(message_kit_bytes)
UmbralMessageKit.from_bytes(message_kit_bytes)
retrieve_args = ('bob', 'retrieve',
'--mock-networking',
'--json-ipc',
'--teacher', teacher.seed_node_metadata(as_teacher_uri=True),
'--config-file', bob_configuration_file_location,
'--message-kit', message_kit_b64_bytes,
'--label', label,
'--policy-encrypting-key', federated_alice.get_policy_encrypting_key_from_label(label).hex(),
'--alice-verifying-key', federated_alice.public_keys(SigningPower).hex()
)
from nucypher.cli import actions
def substitue_bob(*args, **kwargs):
this_fuckin_guy = enacted_federated_policy.bob
somebody_else = Ursula.from_teacher_uri(teacher_uri=kwargs['teacher_uri'],
min_stake=0,
federated_only=True,
network_middleware=this_fuckin_guy.network_middleware)
this_fuckin_guy.remember_node(somebody_else)
this_fuckin_guy.controller.emitter = JSONRPCStdoutEmitter()
return this_fuckin_guy
actions.make_cli_character = substitue_bob
retrieve_response = click_runner.invoke(nucypher_cli, retrieve_args, catch_exceptions=False, env=envvars)
assert retrieve_response.exit_code == 0
retrieve_response = json.loads(retrieve_response.output)
for cleartext in retrieve_response['result']['cleartexts']:
assert cleartext.encode() == capsule_side_channel.plaintexts[1]