Removing "random" Ursulas from tests; selecting by rest_port instead.

pull/242/head
jMyles 2018-04-17 02:44:10 -07:00
parent 4e6a0409ce
commit 50915fc1f2
3 changed files with 40 additions and 56 deletions

View File

@ -420,7 +420,7 @@ class Bob(Character):
raise self.NotEnoughUrsulas(
"Unable to follow the TreasureMap; we just don't know enough nodes to ask about this. Maybe try using the DHT instead.")
new_nodes = self.learn_about_nodes(node_to_check.rest_address,
new_nodes = self.learn_about_nodes(node_to_check.ip_address,
node_to_check.rest_port)
for new_node_pubkey in new_nodes.keys():
if new_node_pubkey in treasure_map:
@ -540,8 +540,8 @@ class Bob(Character):
return generated_work_orders
def get_reencrypted_c_frags(self, networky_stuff, work_order):
cfrags = networky_stuff.reencrypt(work_order)
def get_reencrypted_c_frags(self, work_order):
cfrags = self.network_middleware.reencrypt(work_order)
if not len(work_order) == len(cfrags):
raise ValueError("Ursula gave back the wrong number of cfrags. She's up to something.")
for counter, capsule in enumerate(work_order.capsules):

View File

@ -49,7 +49,7 @@ def test_bob_can_follow_treasure_map(enacted_policy, ursulas, bob, alice):
assert total_known == len(enacted_policy.treasure_map)
def test_bob_can_follow_treasure_map_even_if_he_only_knows_of_one_node(enacted_policy, ursulas, bob):
def test_bob_can_follow_treasure_map_even_if_he_only_knows_of_one_node(enacted_policy, bob):
# Again, let's assume that he received the TreasureMap via a side channel.
hrac, treasure_map = enacted_policy.hrac(), enacted_policy.treasure_map
bob.treasure_maps[hrac] = treasure_map
@ -69,7 +69,7 @@ def test_bob_can_follow_treasure_map_even_if_he_only_knows_of_one_node(enacted_p
assert total_known == len(treasure_map)
def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_policy, alice, bob, ursulas,
def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_policy, bob, ursulas,
capsule_side_channel):
"""
Now that Bob has his list of Ursulas, he can issue a WorkOrder to one. Upon receiving the WorkOrder, Ursula
@ -102,14 +102,10 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_policy, alice,
# And the Ursula.
assert len(bob._saved_work_orders.ursulas) == 1
networky_stuff = MockNetworkyStuff(ursulas)
ursula_dht_key, work_order = list(work_orders.items())[0]
# In the real world, we'll have a full Ursula node here. But in this case, we need to fake it.
work_order.ursula = ursulas[0]
# **** RE-ENCRYPTION HAPPENS HERE! ****
cfrags = bob.get_reencrypted_c_frags(networky_stuff, work_order)
cfrags = bob.get_reencrypted_c_frags(work_order)
# We only gave one Capsule, so we only got one cFrag.
assert len(cfrags) == 1
@ -123,7 +119,13 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_policy, alice,
# OK, so cool - Bob has his cFrag! Let's make sure everything went properly. First, we'll show that it is in fact
# the correct cFrag (ie, that Ursula performed reencryption properly).
ursula = work_order.ursula
for u in ursulas:
if u.rest_port == work_order.ursula.rest_port:
ursula = u
break
else:
raise RuntimeError("Somehow we don't know about this Ursula. Major malfunction.")
kfrag_bytes = ursula.datastore.get_policy_arrangement(
work_order.kfrag_hrac.hex().encode()).k_frag
the_kfrag = KFrag.from_bytes(kfrag_bytes)
@ -136,7 +138,7 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_policy, alice,
assert work_orders_from_bob[0] == work_order
def test_bob_remembers_that_he_has_cfrags_for_a_particular_capsule(enacted_policy, alice, bob,
def test_bob_remembers_that_he_has_cfrags_for_a_particular_capsule(enacted_policy, bob,
ursulas, capsule_side_channel):
# In our last episode, Bob made a WorkOrder for the capsule...
assert len(bob._saved_work_orders.by_capsule(capsule_side_channel[0].capsule)) == 1
@ -167,11 +169,7 @@ def test_bob_remembers_that_he_has_cfrags_for_a_particular_capsule(enacted_polic
assert new_work_order != saved_work_order
# We can get a new CFrag, just like last time.
networky_stuff = MockNetworkyStuff(ursulas)
# In the real world, we'll have a full Ursula node here. But in this case, we need to fake it.
new_work_order.ursula = ursulas[1]
cfrags = bob.get_reencrypted_c_frags(networky_stuff, new_work_order)
cfrags = bob.get_reencrypted_c_frags(new_work_order)
# Again: one Capsule, one cFrag.
assert len(cfrags) == 1
@ -202,10 +200,7 @@ def test_bob_gathers_and_combines(enacted_policy, bob, ursulas, capsule_side_cha
num_ursulas=number_left_to_collect)
_id_of_yet_another_ursula, new_work_order = list(new_work_orders.items())[0]
networky_stuff = MockNetworkyStuff(ursulas)
# In the real world, we'll have a full Ursula node here. But in this case, we need to fake it.
new_work_order.ursula = ursulas[2]
cfrags = bob.get_reencrypted_c_frags(networky_stuff, new_work_order)
cfrags = bob.get_reencrypted_c_frags(new_work_order)
the_message_kit.capsule.attach_cfrag(cfrags[0])
# Now.

View File

@ -68,64 +68,53 @@ class MockNetworkyStuff(NetworkyStuff):
raise self.NotEnoughQualifiedUrsulas
mock_client = TestClient(ursula.rest_app)
response = mock_client.post("http://localhost/consider_arrangement", bytes(arrangement))
assert response.status_code == 200
return ursula, MockArrangementResponse()
def enact_policy(self, ursula, hrac, payload):
mock_client = TestClient(ursula.rest_app)
rest_app = self._get_rest_app_by_port(ursula.rest_port)
mock_client = TestClient(rest_app)
response = mock_client.post('http://localhost/kFrag/{}'.format(hrac.hex()), payload)
assert response.status_code == 200
return True, ursula.stamp.as_umbral_pubkey()
def _get_rest_app_by_port(self, port):
for ursula in self._ursulas.values():
if ursula.rest_port == port:
rest_app = ursula.rest_app
break
else:
raise RuntimeError(
"Can't find an Ursula with port {} - did you spin up the right test ursulas?".format(port))
return rest_app
def send_work_order_payload_to_ursula(self, work_order):
mock_client = TestClient(work_order.ursula.rest_app)
rest_app = self._get_rest_app_by_port(work_order.ursula.rest_port)
mock_client = TestClient(rest_app)
payload = work_order.payload()
hrac_as_hex = work_order.kfrag_hrac.hex()
return mock_client.post('http://localhost/kFrag/{}/reencrypt'.format(hrac_as_hex), payload)
def get_treasure_map_from_node(self, node, map_id):
for ursula in self._ursulas.values():
if ursula.rest_port == node.rest_port:
rest_app = ursula.rest_app
break
else:
raise RuntimeError(
"Can't find an Ursula with port {} - did you spin up the right test ursulas?".format(port))
mock_client = TestClient(ursula.rest_app)
rest_app = self._get_rest_app_by_port(node.rest_port)
mock_client = TestClient(rest_app)
return mock_client.get("http://localhost/treasure_map/{}".format(map_id.hex()))
def ursula_from_rest_interface(self, address, port):
for ursula in self._ursulas.values():
if ursula.rest_port == port:
rest_app = ursula.rest_app
break
else:
raise RuntimeError(
"Can't find an Ursula with port {} - did you spin up the right test ursulas?".format(port))
mock_client = TestClient(ursula.rest_app)
rest_app = self._get_rest_app_by_port(port)
mock_client = TestClient(rest_app)
response = mock_client.get("http://localhost/public_keys")
return response
def get_nodes_via_rest(self, address, port):
for ursula in self._ursulas.values():
if ursula.rest_port == port:
rest_app = ursula.rest_app
break
else:
raise RuntimeError("Can't find an Ursula with port {} - did you spin up the right test ursulas?".format(port))
mock_client = TestClient(ursula.rest_app)
rest_app = self._get_rest_app_by_port(port)
mock_client = TestClient(rest_app)
response = mock_client.get("http://localhost/list_nodes")
return response
def push_treasure_map_to_node(self, node, map_id, map_payload):
port = node.rest_port
for ursula in self._ursulas.values():
if ursula.rest_port == port:
rest_app = ursula.rest_app
break
else:
raise RuntimeError(
"Can't find an Ursula with port {} - did you spin up the right test ursulas?".format(port))
mock_client = TestClient(ursula.rest_app)
rest_app = self._get_rest_app_by_port(node.rest_port)
mock_client = TestClient(rest_app)
response = mock_client.post("http://localhost/treasure_map/{}".format(map_id.hex()),
data=map_payload, verify=False)
return response