Add tests for sq key list.
- Add tests that check that `sq key list` returns an appropriate error code.
This commit is contained in:
parent
fde96e5790
commit
0cc2aba0be
@ -8,15 +8,16 @@ mod integration {
|
||||
mod sq_cli_version;
|
||||
mod sq_decrypt;
|
||||
mod sq_encrypt;
|
||||
mod sq_key_subkey_bind;
|
||||
mod sq_key_approvals_update;
|
||||
mod sq_key_delete;
|
||||
mod sq_key_expire;
|
||||
mod sq_key_generate;
|
||||
mod sq_key_import_export;
|
||||
mod sq_key_list;
|
||||
mod sq_key_password;
|
||||
mod sq_key_revoke;
|
||||
mod sq_key_subkey;
|
||||
mod sq_key_subkey_bind;
|
||||
mod sq_key_subkey_delete;
|
||||
mod sq_key_subkey_expire;
|
||||
mod sq_key_subkey_export;
|
||||
|
@ -933,6 +933,26 @@ impl Sq {
|
||||
self.run(cmd, Some(true));
|
||||
}
|
||||
|
||||
/// Runs `sq key list` with the supplied arguments.
|
||||
pub fn try_key_list(&self, args: &[&str]) -> Result<Vec<u8>> {
|
||||
let mut cmd = self.command();
|
||||
cmd.arg("key").arg("list");
|
||||
for arg in args {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
let output = self.run(cmd, None);
|
||||
if output.status.success() {
|
||||
Ok(output.stdout)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("sq cert list returned an error"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs `sq key list` with the supplied arguments.
|
||||
pub fn key_list(&self, args: &[&str]) -> Vec<u8> {
|
||||
self.try_key_list(args).expect("success")
|
||||
}
|
||||
|
||||
/// Exports the specified key.
|
||||
pub fn key_export(&self, kh: KeyHandle) -> Cert {
|
||||
self.key_export_maybe(kh)
|
||||
|
29
tests/integration/sq_key_list.rs
Normal file
29
tests/integration/sq_key_list.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use crate::integration::common::Sq;
|
||||
|
||||
#[test]
|
||||
fn list_empty() {
|
||||
let sq = Sq::new();
|
||||
|
||||
// Listing an empty key store should not be an error.
|
||||
sq.key_list(&[]);
|
||||
|
||||
// Listing an empty key store with a pattern (that doesn't
|
||||
// match anything) should be.
|
||||
assert!(sq.try_key_list(&["not found"]).is_err());
|
||||
|
||||
let (cert, cert_path, _rev_path)
|
||||
= sq.key_generate(&[], &[ "alice" ]);
|
||||
sq.key_import(cert_path);
|
||||
|
||||
// Not linked => ok.
|
||||
sq.key_list(&["alice"]);
|
||||
// Not found => error.
|
||||
assert!(sq.try_key_list(&["not found"]).is_err());
|
||||
|
||||
// Linked and found => ok.
|
||||
sq.pki_link_add(&[], cert.key_handle(), &["alice"]);
|
||||
sq.key_list(&["alice"]);
|
||||
|
||||
// Not found => error.
|
||||
assert!(sq.try_key_list(&["not found"]).is_err());
|
||||
}
|
Loading…
Reference in New Issue
Block a user