Skip to content

Commit

Permalink
add missing python test case for store copy
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
  • Loading branch information
andrewwhitehead committed Sep 6, 2023
1 parent 2741afb commit 487c988
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/store_copy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use aries_askar::{
future::block_on,
kms::{KeyAlg, LocalKey},
Store, StoreKeyMethod,
};

const ERR_RAW_KEY: &str = "Error creating raw store key";
const ERR_SESSION: &str = "Error creating store session";
const ERR_OPEN: &str = "Error opening test store instance";
const ERR_REQ_ROW: &str = "Row required";
const ERR_CLOSE: &str = "Error closing test store instance";

#[test]
fn store_copy() {
block_on(async {
let pass_key = Store::new_raw_key(None).expect(ERR_RAW_KEY);
let db = Store::provision(
"sqlite://:memory:",
StoreKeyMethod::RawKey,
pass_key,
None,
true,
)
.await
.expect(ERR_OPEN);

let keypair = LocalKey::generate(KeyAlg::Ed25519, false).expect("Error creating keypair");

let mut conn = db.session(None).await.expect(ERR_SESSION);

let key_name = "testkey";
let metadata = "meta";
conn.insert_key(key_name, &keypair, Some(metadata), None, None)
.await
.expect("Error inserting key");

let row_cat = "testcat";
let row_name = "testrow";
let row_value = "testval";
conn.insert(row_cat, row_name, row_value.as_bytes(), None, None)
.await
.expect("Error inserting row");

drop(conn);

let pass_key_copy = Store::new_raw_key(None).expect(ERR_RAW_KEY);
let copied = db
.copy_to(
"sqlite://:memory:",
StoreKeyMethod::RawKey,
pass_key_copy,
true,
)
.await
.expect("Error copying store");

let mut conn = copied.session(None).await.expect(ERR_SESSION);
let found = conn
.fetch_key(key_name, false)
.await
.expect("Error fetching key")
.expect(ERR_REQ_ROW);
assert_eq!(found.algorithm(), Some(KeyAlg::Ed25519.as_str()));
assert_eq!(found.name(), key_name);
assert_eq!(found.metadata(), Some(metadata));
assert!(found.is_local());
found.load_local_key().expect("Error loading key");

let found = conn
.fetch(row_cat, row_name, false)
.await
.expect("Error loading row");
assert!(found.is_some());

db.close().await.expect(ERR_CLOSE);
})
}

0 comments on commit 487c988

Please sign in to comment.