def test_their_vk_and_recipients_raises_error(my_test_info, their_test_info): """Test specifying both their_vk and recipients raises an error.""" with pytest.raises(ValueError): Connection.from_parts( my_test_info.keys, their_vk=their_test_info.keys.verkey, recipients=[their_test_info.keys.verkey], )
def test_byte_inputs_without_their_info(my_test_info): """Test that valid byte inputs yield expected values.""" conn = Connection.from_parts(my_test_info.keys) assert conn.verkey == my_test_info.keys.verkey assert conn.sigkey == my_test_info.keys.sigkey assert conn.verkey_b58 == my_test_info.keys.verkey_b58 assert conn.did == my_test_info.did
def test_give_recipients_b58(my_test_info, their_test_info): """Test recipients set when specified.""" conn = Connection.from_parts( my_test_info.keys, recipients=[their_test_info.keys.verkey_b58], ) assert conn.target.recipients == [their_test_info.keys.verkey]
def _gen(send=None, dispatcher=None): return Connection.from_parts( bob_keys, their_vk=alice_keys.verkey, endpoint="asdf", send=send, dispatcher=dispatcher, )
def test_b58_inputs_with_their_info(my_test_info, their_test_info): """Test that valid b58 inputs yield expected values.""" conn = Connection.from_parts(my_test_info.keys, their_vk=their_test_info.keys.verkey_b58) assert conn.verkey == my_test_info.keys.verkey assert conn.sigkey == my_test_info.keys.sigkey assert conn.verkey_b58 == my_test_info.keys.verkey_b58 assert conn.did == my_test_info.did assert conn.target.recipients == [their_test_info.keys.verkey]
def test_give_routing_keys(my_test_info, their_test_info): """Test routing_keys set when specified.""" conn = Connection.from_parts( my_test_info.keys, their_vk=their_test_info.keys.verkey, routing_keys=[their_test_info.keys.verkey], ) assert conn.target.recipients == [their_test_info.keys.verkey] assert conn.target.routing_keys == [their_test_info.keys.verkey]
def test_pack_unpack_with_routing_keys(alice, bob): """Test packing for a connection with routing keys.""" route1 = Connection.from_parts(crypto.create_keypair()) route2 = Connection.from_parts(crypto.create_keypair()) alice.target.update(routing_keys=[route1.verkey, route2.verkey]) packed_message = alice.pack({"@type": "doc;protocol/1.0/name"}) route2_msg = route2.unpack(packed_message) assert route2_msg.type == utils.FORWARD assert route2_msg["to"] == route1.verkey_b58 assert route2_msg.mtc.is_anoncrypted() assert route2_msg.mtc.sender is None route1_msg = route1.unpack(route2_msg["msg"]) assert route1_msg.type == utils.FORWARD assert route1_msg["to"] == bob.verkey_b58 assert route1_msg.mtc.is_anoncrypted() assert route1_msg.mtc.sender is None bob_msg = bob.unpack(route1_msg["msg"]) assert bob_msg.type == "doc;protocol/1.0/name" assert bob_msg.mtc.is_authcrypted() assert bob_msg.mtc.sender == alice.verkey_b58 assert bob_msg.mtc.recipient == bob.verkey_b58
def test_update(my_test_info, their_test_info): their_new_info = generate_test_info() conn = Connection.from_parts( my_test_info.keys, their_vk=their_test_info.keys.verkey, routing_keys=[their_test_info.keys.verkey], endpoint="endpoint1", ) assert conn.verkey == my_test_info.keys.verkey assert conn.sigkey == my_test_info.keys.sigkey assert conn.verkey_b58 == my_test_info.keys.verkey_b58 assert conn.did == my_test_info.did assert conn.target.recipients == [their_test_info.keys.verkey] assert conn.target.routing_keys == [their_test_info.keys.verkey] assert conn.target.endpoint == "endpoint1" with pytest.raises(ValueError): conn.target.update(their_vk=their_new_info.keys.verkey, recipients=[their_new_info.keys.verkey]) conn.target.update( their_vk=their_new_info.keys.verkey, routing_keys=[their_new_info.keys.verkey], endpoint="endpoint2", ) assert conn.target.recipients == [their_new_info.keys.verkey] assert conn.target.routing_keys == [their_new_info.keys.verkey] assert conn.target.endpoint == "endpoint2" conn.target.update( their_vk=their_test_info.keys.verkey, routing_keys=[their_test_info.keys.verkey], ) assert conn.target.recipients == [their_test_info.keys.verkey] assert conn.target.routing_keys == [their_test_info.keys.verkey] assert conn.target.endpoint == "endpoint2" conn.target.update(recipients=[their_new_info.keys.verkey]) assert conn.target.recipients == [their_new_info.keys.verkey] conn.target.update(recipients=[their_test_info.keys.verkey_b58]) assert conn.target.recipients == [their_test_info.keys.verkey]
def connection_ws(example_keys, test_keys): """Connection fixture with ws send.""" return Connection.from_parts(test_keys, their_vk=example_keys.verkey, send=utils.ws_send)
def connection(example_keys, test_keys): """Connection fixture.""" return Connection.from_parts(test_keys, their_vk=example_keys.verkey)
def bob(bob_keys, alice_keys): """Create Bob's Connection.""" yield Connection.from_parts(bob_keys, their_vk=alice_keys.verkey)
def alice(alice_keys, bob_keys): """Create Alice's Connection.""" yield Connection.from_parts(alice_keys, their_vk=bob_keys.verkey)
def conn(dispatcher): """Function scoped static connection fixture. This connection isn't actually connected to anything. """ yield Connection.from_parts((b"", b""), dispatcher=dispatcher)
def test_bad_inputs(args): """Test that bad inputs raise an error.""" with pytest.raises(TypeError): Connection.from_parts(*args)