コード例 #1
0
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],
        )
コード例 #2
0
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
コード例 #3
0
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]
コード例 #4
0
 def _gen(send=None, dispatcher=None):
     return Connection.from_parts(
         bob_keys,
         their_vk=alice_keys.verkey,
         endpoint="asdf",
         send=send,
         dispatcher=dispatcher,
     )
コード例 #5
0
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]
コード例 #6
0
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]
コード例 #7
0
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
コード例 #8
0
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]
コード例 #9
0
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)
コード例 #10
0
def connection(example_keys, test_keys):
    """Connection fixture."""
    return Connection.from_parts(test_keys, their_vk=example_keys.verkey)
コード例 #11
0
def bob(bob_keys, alice_keys):
    """Create Bob's Connection."""
    yield Connection.from_parts(bob_keys, their_vk=alice_keys.verkey)
コード例 #12
0
def alice(alice_keys, bob_keys):
    """Create Alice's Connection."""
    yield Connection.from_parts(alice_keys, their_vk=bob_keys.verkey)
コード例 #13
0
def conn(dispatcher):
    """Function scoped static connection fixture. This connection isn't
    actually connected to anything.
    """
    yield Connection.from_parts((b"", b""), dispatcher=dispatcher)
コード例 #14
0
def test_bad_inputs(args):
    """Test that bad inputs raise an error."""
    with pytest.raises(TypeError):
        Connection.from_parts(*args)