Remove outermost keccack digest for map id construction, Restore a blockchain-alice node discovery test.

pull/1040/head
Kieran R. Prasch 2019-05-31 13:32:12 -07:00 committed by Kieran Prasch
parent d2ff928f9d
commit 65f7b119bc
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
3 changed files with 19 additions and 20 deletions

View File

@ -62,13 +62,13 @@ class Character(Learner):
A base-class for any character in our cryptography protocol narrative. A base-class for any character in our cryptography protocol narrative.
""" """
_display_name_template = "({})⇀{}↽ ({})" _display_name_template = "({})⇀{}↽ ({})" # Used in __repr__ and in cls.from_bytes
_default_crypto_powerups = None _default_crypto_powerups = None
_stamp = None _stamp = None
_crashed = False _crashed = False
from nucypher.network.protocols import SuspiciousActivity # Ship this exception with every Character. from nucypher.network.protocols import SuspiciousActivity # Ship this exception with every Character.
from nucypher.crypto.signing import InvalidSignature from nucypher.crypto.signing import InvalidSignature # TODO: Restore nucypher Signing exceptions
def __init__(self, def __init__(self,
domains: Set = None, domains: Set = None,

View File

@ -359,9 +359,7 @@ def make_rest_app(
from nucypher.policy.models import TreasureMap from nucypher.policy.models import TreasureMap
try: try:
treasure_map = TreasureMap.from_bytes( treasure_map = TreasureMap.from_bytes(bytes_representation=request.data, verify=True)
bytes_representation=request.data,
verify=True)
except TreasureMap.InvalidSignature: except TreasureMap.InvalidSignature:
do_store = False do_store = False
else: else:

View File

@ -26,6 +26,7 @@ from nucypher.characters.unlawful import Vladimir
from nucypher.crypto.api import keccak_digest from nucypher.crypto.api import keccak_digest
from nucypher.crypto.powers import SigningPower from nucypher.crypto.powers import SigningPower
from nucypher.network.nicknames import nickname_from_seed from nucypher.network.nicknames import nickname_from_seed
from nucypher.network.nodes import FleetStateTracker
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
from nucypher.utilities.sandbox.middleware import MockRestMiddleware from nucypher.utilities.sandbox.middleware import MockRestMiddleware
@ -46,17 +47,17 @@ def test_all_blockchain_ursulas_know_about_all_other_ursulas(blockchain_ursulas,
@pytest.mark.slow() @pytest.mark.slow()
@pytest.mark.skip("What do we want this test to do now?")
def test_blockchain_alice_finds_ursula_via_rest(blockchain_alice, blockchain_ursulas): def test_blockchain_alice_finds_ursula_via_rest(blockchain_alice, blockchain_ursulas):
# Imagine alice knows of nobody. # Imagine alice knows of nobody.
blockchain_alice.known_nodes = {} blockchain_alice._Learner__known_nodes = FleetStateTracker()
new_nodes = blockchain_alice.learn_from_teacher_node() blockchain_alice.remember_node(blockchain_ursulas[0])
blockchain_alice.learn_from_teacher_node()
assert len(blockchain_alice.known_nodes) == len(blockchain_ursulas[:-1]) # TODO: #1035
assert len(new_nodes) == len(blockchain_ursulas) for ursula in blockchain_ursulas[:-1]: # TODO: #1035
assert ursula in blockchain_alice.known_nodes
for ursula in blockchain_ursulas:
assert ursula.stamp.as_umbral_pubkey() in new_nodes
def test_alice_creates_policy_with_correct_hrac(idle_federated_policy): def test_alice_creates_policy_with_correct_hrac(idle_federated_policy):
@ -66,19 +67,18 @@ def test_alice_creates_policy_with_correct_hrac(idle_federated_policy):
alice = idle_federated_policy.alice alice = idle_federated_policy.alice
bob = idle_federated_policy.bob bob = idle_federated_policy.bob
assert idle_federated_policy.hrac() == keccak_digest( assert idle_federated_policy.hrac() == keccak_digest(bytes(alice.stamp)
bytes(alice.stamp) + bytes(bob.stamp) + idle_federated_policy.label) + bytes(bob.stamp)
+ idle_federated_policy.label)
def test_alice_sets_treasure_map(enacted_federated_policy, federated_ursulas): def test_alice_sets_treasure_map(enacted_federated_policy, federated_ursulas):
""" """
Having enacted all the policies of a PolicyGroup, Alice creates a TreasureMap and ...... TODO Having enacted all the policies of a PolicyGroup, Alice creates a TreasureMap and ...... TODO
""" """
enacted_federated_policy.publish_treasure_map(network_middleware=MockRestMiddleware()) enacted_federated_policy.publish_treasure_map(network_middleware=MockRestMiddleware())
treasure_map_index = bytes.fromhex(enacted_federated_policy.treasure_map.public_id())
treasure_map_as_set_on_network = list(federated_ursulas)[0].treasure_maps[ treasure_map_as_set_on_network = list(federated_ursulas)[0].treasure_maps[treasure_map_index]
keccak_digest(unhexlify(enacted_federated_policy.treasure_map.public_id()))]
assert treasure_map_as_set_on_network == enacted_federated_policy.treasure_map assert treasure_map_as_set_on_network == enacted_federated_policy.treasure_map
@ -87,8 +87,9 @@ def test_treasure_map_stored_by_ursula_is_the_correct_one_for_bob(federated_alic
""" """
The TreasureMap given by Alice to Ursula is the correct one for Bob; he can decrypt and read it. The TreasureMap given by Alice to Ursula is the correct one for Bob; he can decrypt and read it.
""" """
treasure_map_as_set_on_network = list(federated_ursulas)[0].treasure_maps[
keccak_digest(unhexlify(enacted_federated_policy.treasure_map.public_id()))] treasure_map_index = bytes.fromhex(enacted_federated_policy.treasure_map.public_id())
treasure_map_as_set_on_network = list(federated_ursulas)[0].treasure_maps[treasure_map_index]
hrac_by_bob = federated_bob.construct_policy_hrac(federated_alice.stamp, enacted_federated_policy.label) hrac_by_bob = federated_bob.construct_policy_hrac(federated_alice.stamp, enacted_federated_policy.label)
assert enacted_federated_policy.hrac() == hrac_by_bob assert enacted_federated_policy.hrac() == hrac_by_bob