Initial tests for authcert storage

This commit is contained in:
Nick Mathewson 2020-11-30 11:59:41 -05:00
parent baba0773c3
commit c3c3d24973
2 changed files with 31 additions and 4 deletions

View File

@ -91,6 +91,7 @@ fn sha3_dual(signed_part: impl AsRef<[u8]>, remainder: impl AsRef<[u8]>) -> ([u8
///
/// This information is ordinarily derived from the authority cert, but it
/// doesn't have to be.
#[derive(Clone, Debug)]
pub struct AuthCertMeta {
/// Key IDs (identity and signing) for the certificate.
ids: AuthCertKeyIds,

View File

@ -571,27 +571,27 @@ const FIND_EXPIRED_EXTDOCS: &str = "
/// Query: Add a new entry to ExtDocs.
const INSERT_EXTDOC: &str = "
INSERT INTO ExtDocs ( digest, created, expires, type, filename )
INSERT OR REPLACE INTO ExtDocs ( digest, created, expires, type, filename )
VALUES ( ?, datetime('now'), ?, ?, ? );
";
/// Qury: Add a new consensus.
const INSERT_CONSENSUS: &str = "
INSERT INTO Consensuses
INSERT OR REPLACE INTO Consensuses
( valid_after, fresh_until, valid_until, flavor, pending, sha3_of_signed_part, digest )
VALUES ( ?, ?, ?, ?, ?, ?, ? );
";
/// Query: Add a new AuthCert
const INSERT_AUTHCERT: &str = "
INSERT INTO Authcerts
INSERT OR REPLACE INTO Authcerts
( id_digest, sk_digest, published, expires, contents)
VALUES ( ?, ?, ?, ?, ? );
";
/// Query: Add a new microdescriptor
const INSERT_MD: &str = "
INSERT INTO Microdescs ( sha256_digest, last_listed, contents )
INSERT OR REPLACE INTO Microdescs ( sha256_digest, last_listed, contents )
VALUES ( ?, ?, ? );
";
@ -768,4 +768,30 @@ mod test {
}
Ok(())
}
#[test]
fn authcerts() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
let now = Utc::now();
let one_hour = CDuration::hours(1);
let keyids = AuthCertKeyIds {
id_fingerprint: [3; 20].into(),
sk_fingerprint: [4; 20].into(),
};
let keyids2 = AuthCertKeyIds {
id_fingerprint: [4; 20].into(),
sk_fingerprint: [3; 20].into(),
};
let m1 = AuthCertMeta::new(keyids.clone(), now.into(), (now + one_hour * 24).into());
store.store_authcerts(&[(m1, "Pretend this is a cert")])?;
let certs = store.authcerts(&[keyids.clone(), keyids2])?;
assert_eq!(certs.len(), 1);
assert_eq!(certs.get(&keyids).unwrap(), "Pretend this is a cert");
Ok(())
}
}