def test_uid_export_single(): # This key contains only one UID data = read_fixture_file("pubkey-1.asc") try: uid1_data = UIDExport(data, 1) except KeyboardInterrupt as e: log.exception("Meh.") raise RuntimeError() # The original key c = TempContext() c.op_import(data) result = c.op_import_result() logging.info("Result: %r", result) fpr = result.imports[0].fpr uids = c.get_key(fpr).uids assert_equals(1, len(uids)) # The first exported UID c = TempContext() logging.info("uid1: %r", uid1_data) c.op_import(uid1_data) result = c.op_import_result() imports = result.imports assert_equals(1, len(imports)) uids1_key = c.get_key(fpr).uids assert_equals(1, len(uids1_key)) uid1 = uids1_key[0] # assert_equals(uid1, uids[0]) assert_equals(uid1.uid, uids[0].uid)
def test_export_alpha_uids(): """When UIDs get deleted, their index shrinks, of course We didn't, however, take that into account so a key with three UIDs would break. """ data = read_fixture_file("alpha.asc") # The original key c = TempContext() c.op_import(data) result = c.op_import_result() logging.info("Result: %r", result) fpr = result.imports[0].fpr uids = c.get_key(fpr).uids logging.info("UIDs: %r", uids) assert_equals(3, len(uids)) for i, uid in enumerate(uids, start=1): exported_uid = UIDExport(data, i) tmp = TempContext() tmp.op_import(exported_uid) result = tmp.op_import_result() logging.debug("UID %d %r import result: %r", i, uid, result) uid_key = tmp.get_key(result.imports[0].fpr) assert_equals(1, len(uid_key.uids)) key_uid = uid_key.uids[0] # FIXME: Enable __eq__ # assert_equal(uids[i-1], key_uid) assert_equal(uids[i - 1].name, key_uid.name) assert_equal(uids[i - 1].email, key_uid.email)
def test_uid_export_double(): # This key contains two UIDs data = read_fixture_file("pubkey-2-uids.asc") try: uid1_data = UIDExport(data, 1) logging.info("uid1: %r", uid1_data) uid2_data = UIDExport(data, 2) except KeyboardInterrupt as e: log.exception("Meh.") raise RuntimeError() assert_not_equals(uid1_data, uid2_data) # The original key c = TempContext() c.op_import(data) result = c.op_import_result() logging.info("Result: %r", result) fpr = result.imports[0].fpr uids = c.get_key(fpr).uids assert_equals(2, len(uids)) # The first exported UID c = TempContext() logging.info("uid1: %r", uid1_data) c.op_import(uid1_data) result = c.op_import_result() imports = result.imports assert_equals(1, len(imports)) uids1_key = c.get_key(fpr).uids assert_equals(1, len(uids1_key)) uid1 = uids1_key[0] # assert_equals(uid1, uids[0]) assert_equals(uid1.uid, uids[0].uid) # The second exported UID c = TempContext() c.op_import(uid2_data) result = c.op_import_result() imports = result.imports assert_equals(1, len(imports)) uids2_key = c.get_key(fpr).uids assert_equals(1, len(uids2_key)) uid2 = uids2_key[0] # FIXME: The objects don't implement __eq__ it seems :-/ # assert_equals(uid2, uids[1]) assert_equals(uid2.uid, uids[1].uid)
def test_uid_export_0(): "You should not be able to export uid < 1" data = read_fixture_file("pubkey-1.asc") uid_data = UIDExport(data, 0) assert False