def test_eidas_sign_credential(credential): # to keep sure that exists a key loaded in the issuer DB path_to_p12_file = "./demo/data/ECDSAcertificate.p12" p12_password = b"passphrase" did = "did:example:21tDAKCERh95uGgKbJNHYp" with open(path_to_p12_file, "rb") as p12_file: p12_data = p12_file.read() eidas_load_qec(did, p12_data, p12_password) out_vc_json = eidas_sign_credential(credential[0]) out_vc_dict = json.loads(out_vc_json) # removes created key because it is dynamically created every time del out_vc_dict['proof']['created'] del out_vc_dict['proof']['jws'] # !!! To be deleted out_vc_json = json.dumps(out_vc_dict, indent=4) del credential[1]['proof']['created'] del credential[1]['proof']['jws'] # !!! To be deleted expected_vc_json = json.dumps(credential[1], indent=4) #deletes last entry dbmanager = DBManager() dbmanager._delete_last() # besides comparing the output value, it is needed to perform a verify signature assert out_vc_json == expected_vc_json
def test_get_did_data_error(did): new_path_file = "./demo/data/storage/eidas_data_error.csv" dbmanager = DBManager(new_path_file) with pytest.raises(EIDASNotDataCreated): dbmanager._get_did_data(did) os.remove(new_path_file)
def test_get_qec(eidas_data): new_path_file = "./demo/data/storage/eidas_data_test2.csv" dbmanager = DBManager(new_path_file) dbmanager.store_qec(eidas_data[0], eidas_data[1], eidas_data[2], eidas_data[3]) qec = dbmanager.get_qec(eidas_data[0]) assert qec == eidas_data[1] os.remove(new_path_file)
def test_get_key(eidas_data): new_path_file = "./demo/data/storage/eidas_data_test3.csv" dbmanager = DBManager(new_path_file) dbmanager.store_qec(eidas_data[0], eidas_data[1], eidas_data[2], eidas_data[3]) privkey, password = dbmanager.get_key(eidas_data[0]) assert privkey == eidas_data[2] assert password == eidas_data[3] os.remove(new_path_file)
def test_store_qec(eidas_data): new_path_file = "./demo/data/storage/eidas_data_test4.csv" dbmanager = DBManager(new_path_file) dbmanager.store_qec(eidas_data[0], eidas_data[1], eidas_data[2], eidas_data[3]) row = dbmanager._get_did_data(eidas_data[0]) assert row['did'] == eidas_data[0] assert row['certificate'] == eidas_data[1] assert row['private_key'] == eidas_data[2] assert row['password'] == eidas_data[3] os.remove(new_path_file)
def test_store_qec_pass(eidas_data): new_path_file = "./demo/data/storage/eidas_data_test6.csv" new_password = b'this is a byte password' decoded_new_password = '******' dbmanager = DBManager(new_path_file) dbmanager.store_qec(eidas_data[0], eidas_data[1], eidas_data[2], new_password) row = dbmanager._get_did_data(eidas_data[0]) assert row['did'] == eidas_data[0] assert row['certificate'] == eidas_data[1] assert row['private_key'] == eidas_data[2] assert row['password'] == decoded_new_password os.remove(new_path_file)
def test_get_pubkey(eidas_data): path_to_p12_file = "./demo/data/ECDSAcertificate.p12" p12_password = b"passphrase" with open(path_to_p12_file, "rb") as p12_file: p12_data = p12_file.read() eidas_load_qec(eidas_data[0], p12_data, p12_password) out_pub_key_json = eidas_get_pubkey(eidas_data[0]) out_pub_key = json.loads(out_pub_key_json) #deletes last entry dbmanager = DBManager() dbmanager._delete_last() assert out_pub_key["publicKeyPem"] == eidas_data[4]
def test_DBManager_path(): new_path_file = "./demo/data/storage/eidas_data_new.csv" dbmanager = DBManager(new_path_file) assert dbmanager._file_path == new_path_file assert os.path.exists(dbmanager._file_path) os.remove(new_path_file)
def test_delete_last(eidas_data): new_path_file = "./demo/data/storage/eidas_data_test5.csv" dbmanager = DBManager(new_path_file) # store an entry dbmanager.store_qec(eidas_data[0], eidas_data[1], eidas_data[2], eidas_data[3]) assert count_lines(new_path_file) == 1 # delete last entry dbmanager._delete_last() assert count_lines(new_path_file) == 0 os.remove(new_path_file)
def _check_data_stored(p12_data: bytes, p12_password: bytes, did: str): # reads the stored data in disk dbmanager = DBManager() qec = dbmanager.get_qec(did) privkey, password = dbmanager.get_key(did) # deletes last entry dbmanager._delete_last() encoded_password = password.encode("utf-8") assert encoded_password == p12_password # loads key and cert from p12 data expected_priv_key, expected_cert = eidas_load_pkcs12( p12_data, encoded_password) assert qec == expected_cert assert _compare_private_keys(privkey, p12_password, expected_priv_key, encoded_password)
def test_get_pubkey_bad_did(did): dbmanager = DBManager() with pytest.raises(EIDASNotDataCreated): dbmanager._get_did_data(did)
def test_DBManager_class(): dbmanager = DBManager() assert dbmanager._file_path == "./demo/data/storage/eidas_data.csv" assert os.path.exists(dbmanager._file_path)