"""Identity unit tests.""" import os from . import constants def test_create_one_identity_succeed(ctx_init): # It has to be imported here to get the management db initialized, import pEp alice = pEp.Identity() alice.address = constants.ALICE_ADDRESS alice.username = constants.ALICE_NAME alice.fpr = constants.ALICE_FP expected_alice = pEp.Identity( constants.ALICE_ADDRESS, constants.ALICE_NAME, '', constants.ALICE_FP, 0, '' ) # XXX: Can't compare objects # assert alice == expected_alice assert str(alice) == constants.ALICE_NAME_ADDR assert alice.address == expected_alice.address assert alice.username == expected_alice.username # Cause the key is created by pEp assert alice.fpr == expected_alice.fpr assert alice.user_id == expected_alice.user_id assert alice.comm_type == expected_alice.comm_type assert alice.flags == expected_alice.flags # Test that data after updating. # If the db has not been initialized this would return PEP_GET_KEY_FAILED alice.update() assert str(alice) == constants.ALICE_NAME_ADDR assert alice.address == expected_alice.address assert alice.username == expected_alice.username # XXX: shouldn't this be he fpr of the key generated by pEp? assert alice.fpr == '' # After updating this changed assert alice.user_id == "TOFU_alice@openpgp.example" # After updating this changed assert alice.comm_type == 3 assert alice.flags == expected_alice.flags def test_two_identities_succeed(ctx_init, bob_pub_key_data): import pEp alice = pEp.Identity( constants.ALICE_ADDRESS, constants.ALICE_NAME, '', constants.ALICE_FP, 0, '' ) assert alice.address == constants.ALICE_ADDRESS assert alice.username == constants.ALICE_NAME assert alice.fpr == constants.ALICE_FP assert alice.user_id == "" assert alice.comm_type == 0 assert alice.flags == 0 pEp.import_key(bob_pub_key_data) bob = pEp.Identity() bob.address = constants.BOB_ADDRESS bob.username = constants.BOB_NAME bob.fpr = constants.BOB_FP expected_bob = pEp.Identity( constants.BOB_ADDRESS, constants.BOB_NAME, '', constants.BOB_FP, 56, '' ) assert str(bob) == constants.BOB_NAME_ADDR assert bob.address == expected_bob.address assert bob.username == expected_bob.username assert bob.fpr == expected_bob.fpr assert bob.user_id == "" assert bob.comm_type == 0 assert bob.flags == 0 # Test that data after updating. bob.update() assert str(bob) == constants.BOB_NAME_ADDR assert bob.address == expected_bob.address assert bob.username == expected_bob.username assert bob.fpr == expected_bob.fpr assert bob.user_id == "TOFU_bob@openpgp.example" assert bob.comm_type == 56 assert bob.flags == 0 def test_set_own_key(ctx_init, alice_sec_key_data): import pEp pEp.import_key(alice_sec_key_data) alice = pEp.Identity() alice.address = constants.ALICE_ADDRESS alice.username = constants.ALICE_NAME alice.fpr = constants.ALICE_FP alice.user_id = constants.ALICE_NAME_ADDR expected_alice = pEp.Identity( constants.ALICE_ADDRESS, constants.ALICE_NAME, '', constants.ALICE_FP, 0, '' ) pEp.set_own_key(alice, alice.fpr) # assert str(alice) == constants.ALICE_NAME_ADDR assert str(alice) == str(expected_alice) assert alice.address == expected_alice.address assert alice.username == expected_alice.username # assert alice.user_id == constants.ALICE_NAME_ADDR assert alice.user_id == str(expected_alice) assert alice.fpr == expected_alice.fpr assert alice.comm_type == 255 assert alice.flags == 0 # After setting own key this would give ValueError: illegal value # alice.update()