Make the test helper function Sq::key_adopt more consistent.
- Make `Sq::key_adopt` more consistent with other functions by providing an `Sq::key_adopt_maybe` version, which panics on failure.
This commit is contained in:
parent
ce59c45165
commit
726dedc553
@ -711,16 +711,23 @@ impl Sq {
|
||||
}
|
||||
}
|
||||
|
||||
/// Target is a certificate.
|
||||
/// Calls `sq key adopt`.
|
||||
///
|
||||
/// `keyrings` are a list of files to pass to `--keyring`. They
|
||||
/// usually contain the key to adopt.
|
||||
///
|
||||
/// `target` is the certificate that will adopt the key.
|
||||
///
|
||||
/// `keys` is the set of keys to adopt.
|
||||
pub fn key_adopt<P, T, K, Q>(&self,
|
||||
extra_args: &[&str],
|
||||
keyrings: Vec<P>,
|
||||
target: T,
|
||||
keys: Vec<K>,
|
||||
output_file: Q,
|
||||
success: bool)
|
||||
///
|
||||
/// The resulting certificate is NOT imported into the key store
|
||||
/// or the cert store.
|
||||
pub fn key_adopt_maybe<P, T, K, Q>(&self,
|
||||
extra_args: &[&str],
|
||||
keyrings: Vec<P>,
|
||||
target: T,
|
||||
keys: Vec<K>,
|
||||
output_file: Q)
|
||||
-> Result<Cert>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
@ -756,7 +763,7 @@ impl Sq {
|
||||
|
||||
cmd.arg("--output").arg(&output_file);
|
||||
|
||||
let output = self.run(cmd, Some(success));
|
||||
let output = self.run(cmd, None);
|
||||
if output.status.success() {
|
||||
let cert = if output_file == PathBuf::from("-") {
|
||||
Cert::from_bytes(&output.stdout)
|
||||
@ -769,11 +776,41 @@ impl Sq {
|
||||
Ok(cert)
|
||||
} else {
|
||||
Err(anyhow::anyhow!(format!(
|
||||
"Failed (expected):\n{}",
|
||||
"Failed:\n{}",
|
||||
String::from_utf8_lossy(&output.stderr))))
|
||||
}
|
||||
}
|
||||
|
||||
/// Calls `sq key adopt`.
|
||||
///
|
||||
/// `keyrings` are a list of files to pass to `--keyring`. They
|
||||
/// usually contain the key to adopt.
|
||||
///
|
||||
/// `target` is the certificate that will adopt the key.
|
||||
///
|
||||
/// `keys` is the set of keys to adopt.
|
||||
///
|
||||
/// The resulting certificate is NOT imported into the key store
|
||||
/// or the cert store.
|
||||
///
|
||||
/// This version panics if `sq key adopt` fails.
|
||||
pub fn key_adopt<P, T, K, Q>(&self,
|
||||
extra_args: &[&str],
|
||||
keyrings: Vec<P>,
|
||||
target: T,
|
||||
keys: Vec<K>,
|
||||
output_file: Q)
|
||||
-> Cert
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
T: Into<FileOrKeyHandle>,
|
||||
K: Into<KeyHandle>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
self.key_adopt_maybe(extra_args, keyrings, target, keys, output_file)
|
||||
.expect("sq key adopt succeeds")
|
||||
}
|
||||
|
||||
pub fn key_approvals_update<'a, H, Q>(&self,
|
||||
cert: H,
|
||||
args: &[&str],
|
||||
|
@ -175,9 +175,7 @@ fn adopt_encryption() -> Result<()> {
|
||||
keyrings.to_vec(),
|
||||
handle,
|
||||
[ alice_encryption().0.clone() ].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 2, (bob_primary(), &[alice_encryption()])).is_ok());
|
||||
@ -226,9 +224,7 @@ fn adopt_signing() -> Result<()> {
|
||||
keyrings.to_vec(),
|
||||
handle,
|
||||
[ alice_signing().0.clone() ].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 2, (bob_primary(), &[alice_signing()])).is_ok());
|
||||
@ -278,9 +274,7 @@ fn adopt_certification() -> Result<()> {
|
||||
keyrings.to_vec(),
|
||||
handle,
|
||||
[ alice_primary().0.clone() ].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(check(&cert, 4, (carol_primary(), &[alice_primary()])).is_ok());
|
||||
}
|
||||
@ -330,9 +324,7 @@ fn adopt_encryption_and_signing() -> Result<()> {
|
||||
alice_signing().0.clone(),
|
||||
alice_encryption().0.clone(),
|
||||
].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 3,
|
||||
@ -387,9 +379,7 @@ fn adopt_twice() -> Result<()> {
|
||||
alice_encryption().0.clone(),
|
||||
alice_encryption().0.clone(),
|
||||
].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 2, (bob_primary(), &[alice_encryption()])).is_ok());
|
||||
@ -410,9 +400,7 @@ fn adopt_key_appears_twice() -> Result<()> {
|
||||
[
|
||||
alice_encryption().0.clone(),
|
||||
].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 2, (bob_primary(), &[alice_encryption()])).is_ok());
|
||||
@ -462,9 +450,7 @@ fn adopt_own_encryption() -> Result<()> {
|
||||
[
|
||||
alice_encryption().0.clone(),
|
||||
].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 3, (alice_primary(), &[alice_encryption()])).is_ok());
|
||||
@ -515,9 +501,7 @@ fn adopt_own_primary() -> Result<()> {
|
||||
[
|
||||
bob_primary().0.clone(),
|
||||
].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 2, (bob_primary(), &[bob_primary()])).is_ok());
|
||||
@ -569,7 +553,7 @@ fn adopt_missing() -> Result<()> {
|
||||
}
|
||||
|
||||
// Adopt a key that is not present.
|
||||
let r = sq.key_adopt(
|
||||
let r = sq.key_adopt_maybe(
|
||||
&[],
|
||||
keyrings.to_vec(),
|
||||
handle,
|
||||
@ -578,8 +562,7 @@ fn adopt_missing() -> Result<()> {
|
||||
.parse::<KeyHandle>()
|
||||
.expect("valid fingerprint")
|
||||
].to_vec(),
|
||||
"-",
|
||||
false);
|
||||
"-");
|
||||
|
||||
assert!(r.is_err());
|
||||
}
|
||||
@ -632,9 +615,7 @@ fn adopt_from_multiple() -> Result<()> {
|
||||
carol_signing().0.clone(),
|
||||
carol_encryption().0.clone(),
|
||||
].to_vec(),
|
||||
"-",
|
||||
true)
|
||||
.unwrap();
|
||||
"-");
|
||||
|
||||
assert!(
|
||||
check(&cert, 5,
|
||||
|
Loading…
Reference in New Issue
Block a user