Add tests for sq key approvals update.

- Test that the user ID designators behave correctly.
This commit is contained in:
Neal H. Walfield 2024-12-12 10:16:00 +01:00
parent 29329e5dec
commit 5079c8ee66
No known key found for this signature in database
GPG Key ID: 6863C9AD5B4D22D3

View File

@ -1,7 +1,7 @@
use std::ffi::OsStr;
use std::path::Path;
use super::common::{artifact, NO_USERIDS, Sq, STANDARD_POLICY};
use super::common::{artifact, NO_USERIDS, Sq, STANDARD_POLICY, UserIDArg};
use sequoia_openpgp as openpgp;
use openpgp::{
@ -314,3 +314,40 @@ fn ignore_unexportable_certifications() {
assert_eq!(approval_ua.with_policy(STANDARD_POLICY, None).unwrap()
.attested_certifications().count(), 0);
}
#[test]
fn userid_designators() {
let self_signed_email = "alice@example.org";
let self_signed_userid
= &format!("Alice <{}>", self_signed_email);
let other_email = "alice@other.org";
let other_userid = &format!("Alice <{}>", other_email);
let mut sq = Sq::new();
let (cert, cert_path, _rev_path)
= sq.key_generate(&[], &[ self_signed_userid ]);
sq.key_import(cert_path);
// 1. --userid: use the specified self-signed user ID.
sq.tick(10);
sq.key_approvals_update(
&["--add-all"], cert.key_handle(),
&[ UserIDArg::UserID(self_signed_userid) ], None);
sq.tick(10);
assert!(sq.try_key_approvals_update(
&["--add-all"], cert.key_handle(),
&[ UserIDArg::UserID(other_userid) ], None).is_err());
// 2. --email: use the self-signed user ID with the specified
// email address.
sq.tick(10);
sq.key_approvals_update(
&["--add-all"], cert.key_handle(),
&[ UserIDArg::Email(self_signed_email) ], None);
sq.tick(10);
assert!(sq.try_key_approvals_update(
&["--add-all"], cert.key_handle(),
&[ UserIDArg::Email(other_email) ], None).is_err());
}