fix: batch signed log sync imports
This commit is contained in:
parent
6fc1410e65
commit
02969ac7af
3 changed files with 185 additions and 55 deletions
|
|
@ -1052,25 +1052,18 @@ impl Store {
|
|||
signatures: &[StoredAuthSignature],
|
||||
) -> Result<(), StoreError> {
|
||||
let tx = self.conn.unchecked_transaction()?;
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO auth_ops(op_id, resource_id, op_json, created_at_ms)
|
||||
VALUES (?1, ?2, ?3, ?4)"#,
|
||||
params![op.op_id, op.resource_id, op.op_json, op.created_at_ms],
|
||||
)?;
|
||||
for signature in signatures {
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO auth_signatures(
|
||||
op_id, signer, signer_public_key, namespace, signature, created_at_ms
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"#,
|
||||
params![
|
||||
signature.op_id,
|
||||
signature.signer,
|
||||
signature.signer_public_key,
|
||||
signature.namespace,
|
||||
signature.signature,
|
||||
signature.created_at_ms
|
||||
],
|
||||
)?;
|
||||
Self::insert_auth_op_with_signatures_tx(&tx, op, signatures)?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert_auth_ops_with_signatures(
|
||||
&self,
|
||||
ops: &[(StoredAuthOp, Vec<StoredAuthSignature>)],
|
||||
) -> Result<(), StoreError> {
|
||||
let tx = self.conn.unchecked_transaction()?;
|
||||
for (op, signatures) in ops {
|
||||
Self::insert_auth_op_with_signatures_tx(&tx, op, signatures)?;
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
|
|
@ -1165,25 +1158,18 @@ impl Store {
|
|||
signatures: &[StoredKeychainSignature],
|
||||
) -> Result<(), StoreError> {
|
||||
let tx = self.conn.unchecked_transaction()?;
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO keychain_ops(op_id, op_json, created_at_ms)
|
||||
VALUES (?1, ?2, ?3)"#,
|
||||
params![op.op_id, op.op_json, op.created_at_ms],
|
||||
)?;
|
||||
for signature in signatures {
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO keychain_signatures(
|
||||
op_id, signer, signer_public_key, namespace, signature, created_at_ms
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"#,
|
||||
params![
|
||||
signature.op_id,
|
||||
signature.signer,
|
||||
signature.signer_public_key,
|
||||
signature.namespace,
|
||||
signature.signature,
|
||||
signature.created_at_ms
|
||||
],
|
||||
)?;
|
||||
Self::insert_keychain_op_with_signatures_tx(&tx, op, signatures)?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert_keychain_ops_with_signatures(
|
||||
&self,
|
||||
ops: &[(StoredKeychainOp, Vec<StoredKeychainSignature>)],
|
||||
) -> Result<(), StoreError> {
|
||||
let tx = self.conn.unchecked_transaction()?;
|
||||
for (op, signatures) in ops {
|
||||
Self::insert_keychain_op_with_signatures_tx(&tx, op, signatures)?;
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
|
|
@ -1245,6 +1231,62 @@ impl Store {
|
|||
.map_err(StoreError::from)
|
||||
}
|
||||
|
||||
fn insert_auth_op_with_signatures_tx(
|
||||
tx: &Transaction<'_>,
|
||||
op: &StoredAuthOp,
|
||||
signatures: &[StoredAuthSignature],
|
||||
) -> Result<(), StoreError> {
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO auth_ops(op_id, resource_id, op_json, created_at_ms)
|
||||
VALUES (?1, ?2, ?3, ?4)"#,
|
||||
params![op.op_id, op.resource_id, op.op_json, op.created_at_ms],
|
||||
)?;
|
||||
for signature in signatures {
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO auth_signatures(
|
||||
op_id, signer, signer_public_key, namespace, signature, created_at_ms
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"#,
|
||||
params![
|
||||
signature.op_id,
|
||||
signature.signer,
|
||||
signature.signer_public_key,
|
||||
signature.namespace,
|
||||
signature.signature,
|
||||
signature.created_at_ms
|
||||
],
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_keychain_op_with_signatures_tx(
|
||||
tx: &Transaction<'_>,
|
||||
op: &StoredKeychainOp,
|
||||
signatures: &[StoredKeychainSignature],
|
||||
) -> Result<(), StoreError> {
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO keychain_ops(op_id, op_json, created_at_ms)
|
||||
VALUES (?1, ?2, ?3)"#,
|
||||
params![op.op_id, op.op_json, op.created_at_ms],
|
||||
)?;
|
||||
for signature in signatures {
|
||||
tx.execute(
|
||||
r#"INSERT OR REPLACE INTO keychain_signatures(
|
||||
op_id, signer, signer_public_key, namespace, signature, created_at_ms
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"#,
|
||||
params![
|
||||
signature.op_id,
|
||||
signature.signer,
|
||||
signature.signer_public_key,
|
||||
signature.namespace,
|
||||
signature.signature,
|
||||
signature.created_at_ms
|
||||
],
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert_node_enrollment_request(
|
||||
&self,
|
||||
request: &StoredNodeEnrollmentRequest,
|
||||
|
|
@ -2120,6 +2162,52 @@ mod tests {
|
|||
assert_eq!(count, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auth_ops_with_signatures_batch_commits_multiple_ops() {
|
||||
let store = Store::open_memory().expect("open");
|
||||
let first = StoredAuthOp {
|
||||
op_id: "auth-op:batch:1".to_owned(),
|
||||
resource_id: "resource:test".to_owned(),
|
||||
op_json: r#"{"id":"auth-op:batch:1"}"#.to_owned(),
|
||||
created_at_ms: 1,
|
||||
};
|
||||
let second = StoredAuthOp {
|
||||
op_id: "auth-op:batch:2".to_owned(),
|
||||
resource_id: "resource:test".to_owned(),
|
||||
op_json: r#"{"id":"auth-op:batch:2"}"#.to_owned(),
|
||||
created_at_ms: 2,
|
||||
};
|
||||
let signature = |op: &StoredAuthOp| StoredAuthSignature {
|
||||
op_id: op.op_id.clone(),
|
||||
signer: "key:admin".to_owned(),
|
||||
signer_public_key: "ssh-ed25519 AAAA test".to_owned(),
|
||||
namespace: "geth.auth.v1@geth.local".to_owned(),
|
||||
signature: b"sig".to_vec(),
|
||||
created_at_ms: op.created_at_ms,
|
||||
};
|
||||
|
||||
store
|
||||
.insert_auth_ops_with_signatures(&[
|
||||
(first.clone(), vec![signature(&first)]),
|
||||
(second.clone(), vec![signature(&second)]),
|
||||
])
|
||||
.expect("batch insert auth ops");
|
||||
|
||||
assert_eq!(
|
||||
store
|
||||
.list_auth_ops_for_resource("resource:test")
|
||||
.expect("list auth ops"),
|
||||
vec![first, second]
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.list_auth_signatures()
|
||||
.expect("list auth signatures")
|
||||
.len(),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keychain_ops_roundtrip() {
|
||||
let store = Store::open_memory().expect("open");
|
||||
|
|
@ -2143,6 +2231,48 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keychain_ops_with_signatures_batch_commits_multiple_ops() {
|
||||
let store = Store::open_memory().expect("open");
|
||||
let first = StoredKeychainOp {
|
||||
op_id: "keychain-op:batch:1".to_owned(),
|
||||
op_json: r#"{"id":"keychain-op:batch:1"}"#.to_owned(),
|
||||
created_at_ms: 1,
|
||||
};
|
||||
let second = StoredKeychainOp {
|
||||
op_id: "keychain-op:batch:2".to_owned(),
|
||||
op_json: r#"{"id":"keychain-op:batch:2"}"#.to_owned(),
|
||||
created_at_ms: 2,
|
||||
};
|
||||
let signature = |op: &StoredKeychainOp| StoredKeychainSignature {
|
||||
op_id: op.op_id.clone(),
|
||||
signer: "key:admin".to_owned(),
|
||||
signer_public_key: "ssh-ed25519 AAAA test".to_owned(),
|
||||
namespace: "geth.keychain.v1@geth.local".to_owned(),
|
||||
signature: b"sig".to_vec(),
|
||||
created_at_ms: op.created_at_ms,
|
||||
};
|
||||
|
||||
store
|
||||
.insert_keychain_ops_with_signatures(&[
|
||||
(first.clone(), vec![signature(&first)]),
|
||||
(second.clone(), vec![signature(&second)]),
|
||||
])
|
||||
.expect("batch insert keychain ops");
|
||||
|
||||
assert_eq!(
|
||||
store.list_keychain_ops().expect("list keychain ops"),
|
||||
vec![first, second]
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.list_keychain_signatures()
|
||||
.expect("list keychain signatures")
|
||||
.len(),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keychain_signatures_roundtrip() {
|
||||
let store = Store::open_memory().expect("open");
|
||||
|
|
|
|||
Loading…
Reference in a new issue