def test_datastore_workorder_model():
    temp_path = tempfile.mkdtemp()
    storage = datastore.Datastore(temp_path)
    bob_keypair = keypairs.SigningKeypair(generate_keys_if_needed=True)

    arrangement_id_hex = 'beef'
    bob_verifying_key = bob_keypair.pubkey
    bob_signature = bob_keypair.sign(b'test')

    # Test create
    with storage.describe(Workorder, arrangement_id_hex,
                          writeable=True) as work_order:
        work_order.arrangement_id = bytes.fromhex(arrangement_id_hex)
        work_order.bob_verifying_key = bob_verifying_key
        work_order.bob_signature = bob_signature

    with storage.describe(Workorder, arrangement_id_hex) as work_order:
        assert work_order.arrangement_id == bytes.fromhex(arrangement_id_hex)
        assert work_order.bob_verifying_key == bob_verifying_key
        assert work_order.bob_signature == bob_signature

    # Test delete
    with storage.describe(Workorder, arrangement_id_hex,
                          writeable=True) as work_order:
        work_order.delete()

        # Should be deleted now.
        with pytest.raises(AttributeError):
            should_error = work_order.arrangement_id
def test_datastore_policy_arrangement_model():
    temp_path = tempfile.mkdtemp()
    storage = datastore.Datastore(temp_path)

    arrangement_id_hex = 'beef'
    expiration = maya.now()
    alice_verifying_key = keypairs.SigningKeypair(
        generate_keys_if_needed=True).pubkey

    # TODO: Leaving out KFrag for now since I don't have an easy way to grab one.
    with storage.describe(PolicyArrangement,
                          arrangement_id_hex,
                          writeable=True) as policy_arrangement:
        policy_arrangement.arrangement_id = bytes.fromhex(arrangement_id_hex)
        policy_arrangement.expiration = expiration
        policy_arrangement.alice_verifying_key = alice_verifying_key

    with storage.describe(PolicyArrangement,
                          arrangement_id_hex) as policy_arrangement:
        assert policy_arrangement.arrangement_id == bytes.fromhex(
            arrangement_id_hex)
        assert policy_arrangement.expiration == expiration
        assert policy_arrangement.alice_verifying_key == alice_verifying_key

    # Now let's `delete` it
    with storage.describe(PolicyArrangement,
                          arrangement_id_hex,
                          writeable=True) as policy_arrangement:
        policy_arrangement.delete()

        # Should be deleted now.
        with pytest.raises(AttributeError):
            should_error = policy_arrangement.arrangement_id
Beispiel #3
0
def test_workorder_sqlite_datastore(test_datastore):
    bob_keypair_sig1 = keypairs.SigningKeypair(generate_keys_if_needed=True)
    bob_keypair_sig2 = keypairs.SigningKeypair(generate_keys_if_needed=True)

    arrangement_id = b'test'

    # Test add workorder
    new_workorder1 = test_datastore.save_workorder(bob_keypair_sig1.pubkey, b'test0', arrangement_id)
    new_workorder2 = test_datastore.save_workorder(bob_keypair_sig2.pubkey, b'test1', arrangement_id)

    # Test get workorder
    query_workorders = test_datastore.get_workorders(arrangement_id)
    assert {new_workorder1, new_workorder2}.issubset(query_workorders)

    # Test del workorder
    deleted = test_datastore.del_workorders(arrangement_id)
    assert deleted > 0
    assert len(test_datastore.get_workorders(arrangement_id)) == 0
Beispiel #4
0
def test_signing():
    umbral_privkey = UmbralPrivateKey.gen_key()
    sig_keypair = keypairs.SigningKeypair(umbral_privkey)

    msg = b'peace at dawn'
    signature = sig_keypair.sign(msg)
    assert signature.verify(msg, sig_keypair.pubkey)

    bad_msg = b'bad message'
    assert not signature.verify(bad_msg, sig_keypair.pubkey)
Beispiel #5
0
def test_gen_keypair_if_needed():
    new_dec_keypair = keypairs.DecryptingKeypair()
    assert new_dec_keypair._privkey is not None
    assert new_dec_keypair.pubkey is not None
    assert new_dec_keypair.pubkey == new_dec_keypair._privkey.get_pubkey()

    new_sig_keypair = keypairs.SigningKeypair()
    assert new_sig_keypair._privkey is not None
    assert new_sig_keypair.pubkey is not None
    assert new_sig_keypair.pubkey == new_sig_keypair._privkey.get_pubkey()
Beispiel #6
0
def test_policy_arrangement_sqlite_datastore(test_datastore):
    alice_keypair_sig = keypairs.SigningKeypair(generate_keys_if_needed=True)

    arrangement_id = b'test'

    # Test add PolicyArrangement
    new_arrangement = test_datastore.add_policy_arrangement(
            datetime.utcnow(), b'test', arrangement_id, alice_verifying_key=alice_keypair_sig.pubkey,
            alice_signature=b'test'
    )

    # Test get PolicyArrangement
    query_arrangement = test_datastore.get_policy_arrangement(arrangement_id)
    assert new_arrangement == query_arrangement

    # Test del PolicyArrangement
    test_datastore.del_policy_arrangement(arrangement_id)
    with pytest.raises(datastore.NotFound):
        del_key = test_datastore.get_policy_arrangement(arrangement_id)