def fleet_of_highperf_mocked_ursulas(ursula_federated_test_config, request): # good_serials = _determine_good_serials(10000, 50000) try: quantity = request.param except AttributeError: quantity = 5000 # Bigass fleet by default; that's kinda the point. with GlobalLoggerSettings.pause_all_logging_while(): with mock_secret_source(): with mock_cert_storage, mock_cert_loading, mock_rest_app_creation, mock_cert_generation, mock_remember_node, mock_message_verification: _ursulas = make_federated_ursulas( ursula_config=ursula_federated_test_config, quantity=quantity, know_each_other=False) all_ursulas = {u.checksum_address: u for u in _ursulas} for ursula in _ursulas: # FIXME #2588: FleetSensor should not own fully-functional Ursulas. # It only needs to see whatever public info we can normally get via REST. # Also sharing mutable Ursulas like that can lead to unpredictable results. ursula.known_nodes.current_state._nodes = all_ursulas ursula.known_nodes.current_state.checksum = b"This is a fleet state checksum..".hex( ) yield _ursulas for ursula in _ursulas: del MOCK_KNOWN_URSULAS_CACHE[ursula.rest_interface.port]
def test_alice_verifies_ursula_just_in_time(fleet_of_highperf_mocked_ursulas, highperf_mocked_alice, highperf_mocked_bob): mocks = ( mock_secret_source(), mock_cert_loading, mock_metadata_validation, mock_message_verification, ) with contextlib.ExitStack() as stack: for mock in mocks: stack.enter_context(mock) policy = highperf_mocked_alice.grant(highperf_mocked_bob, b"any label", threshold=20, shares=30, expiration=maya.when('next week')) # TODO: Make some assertions about policy. total_verified = sum(node.verified_node for node in highperf_mocked_alice.known_nodes) # Alice may be able to verify more than `n`, but certainly not less, # otherwise `grant()` would fail. assert total_verified >= 30 _POLICY_PRESERVER.append(policy)
def test_alice_verifies_ursula_just_in_time(fleet_of_highperf_mocked_ursulas, highperf_mocked_alice, highperf_mocked_bob): # Patch the Datastore PolicyArrangement model with the highperf # NotAPublicKey not_public_key_record_field = RecordField(NotAPublicKey, encode=bytes, decode=NotAPublicKey.from_bytes) _umbral_pubkey_from_bytes = UmbralPublicKey.from_bytes def actual_random_key_instead(*args, **kwargs): _previous_bytes = args[0] serial = _previous_bytes[-5:] pubkey = NotAPublicKey(serial=serial) return pubkey def mock_set_policy(id_as_hex): return "" def mock_receive_treasure_map(): return Response(bytes(), status=201) with NotARestApp.replace_route("receive_treasure_map", mock_receive_treasure_map): with NotARestApp.replace_route("set_policy", mock_set_policy): with patch('umbral.keys.UmbralPublicKey.__eq__', lambda *args, **kwargs: True): with patch('umbral.keys.UmbralPublicKey.from_bytes', new=actual_random_key_instead): with patch( "nucypher.datastore.models.PolicyArrangement._alice_verifying_key", new=not_public_key_record_field): with mock_cert_loading, mock_metadata_validation, mock_message_verification: with mock_secret_source(): policy = highperf_mocked_alice.grant( highperf_mocked_bob, b"any label", m=20, n=30, expiration=maya.when('next week'), publish_treasure_map=False) # TODO: Make some assertions about policy. total_verified = sum(node.verified_node for node in highperf_mocked_alice.known_nodes) # Alice may be able to verify more than `n`, but certainly not less, # otherwise `grant()` would fail. assert total_verified >= 30 _POLICY_PRESERVER.append(policy)
def fleet_of_highperf_mocked_ursulas(ursula_federated_test_config, request): try: quantity = request.param except AttributeError: quantity = 5000 # Bigass fleet by default; that's kinda the point. with GlobalLoggerSettings.pause_all_logging_while(): with mock_secret_source(): with mock_cert_storage, mock_cert_loading, mock_rest_app_creation, mock_cert_generation, mock_remember_node, mock_message_verification: _ursulas = make_federated_ursulas(ursula_config=ursula_federated_test_config, quantity=quantity, know_each_other=False) all_ursulas = {u.checksum_address: u for u in _ursulas} for ursula in _ursulas: ursula.known_nodes._nodes = all_ursulas ursula.known_nodes.checksum = b"This is a fleet state checksum..".hex() return _ursulas
def fleet_of_highperf_mocked_ursulas(ursula_federated_test_config, request): # good_serials = _determine_good_serials(10000, 50000) try: quantity = request.param except AttributeError: quantity = 5000 # Bigass fleet by default; that's kinda the point. with GlobalLoggerSettings.pause_all_logging_while(): with mock_secret_source(): with mock_cert_storage, mock_cert_loading, mock_rest_app_creation, mock_cert_generation, mock_remember_node, mock_message_verification: _ursulas = make_federated_ursulas( ursula_config=ursula_federated_test_config, quantity=quantity, know_each_other=False) all_ursulas = {u.checksum_address: u for u in _ursulas} for ursula in _ursulas: ursula.known_nodes.current_state._nodes = all_ursulas ursula.known_nodes.current_state.checksum = b"This is a fleet state checksum..".hex( ) yield _ursulas for ursula in _ursulas: del MOCK_KNOWN_URSULAS_CACHE[ursula.rest_interface.port]
def test_alice_verifies_ursula_just_in_time(fleet_of_highperf_mocked_ursulas, highperf_mocked_alice, highperf_mocked_bob): _umbral_pubkey_from_bytes = UmbralPublicKey.from_bytes def actual_random_key_instead(*args, **kwargs): _previous_bytes = args[0] serial = _previous_bytes[-5:] pubkey = NotAPublicKey(serial=serial) return pubkey def mock_set_policy(id_as_hex): return "" def mock_receive_treasure_map(treasure_map_id): return Response(bytes(), status=202) with NotARestApp.replace_route("receive_treasure_map", mock_receive_treasure_map): with NotARestApp.replace_route("set_policy", mock_set_policy): with patch('umbral.keys.UmbralPublicKey.__eq__', lambda *args, **kwargs: True): with patch('umbral.keys.UmbralPublicKey.from_bytes', new=actual_random_key_instead): with mock_cert_loading, mock_metadata_validation, mock_message_verification: with mock_secret_source(): policy = highperf_mocked_alice.grant( highperf_mocked_bob, b"any label", m=20, n=30, expiration=maya.when('next week'), publish_treasure_map=False) # TODO: Make some assertions about policy. total_verified = sum(node.verified_node for node in highperf_mocked_alice.known_nodes) assert total_verified == 30