Listing an empty certificate store should not be an error.

- `sq cert list` on an empty certificate store should not be an
    error.
This commit is contained in:
Neal H. Walfield 2024-12-04 10:30:06 +01:00
parent 500447b804
commit fde96e5790
No known key found for this signature in database
GPG Key ID: 6863C9AD5B4D22D3
2 changed files with 29 additions and 0 deletions

View File

@ -419,6 +419,10 @@ pub fn authenticate<'store, 'rstore>(
.sq().arg("network").arg("search")
.arg("some-mail-address")
.done();
// We're listing everything and we have nothing. That's
// not actually an error.
return Ok(());
}
} else if bindings.len() - bindings_shown > 0 {
// Some of the matching bindings were not shown. Tell the

View File

@ -39,3 +39,28 @@ fn list() {
// When we use --email, then we don't do substring matching.
assert!(sq.cert_list_maybe(&["--email", &email[1..]]).is_err());
}
#[test]
fn list_empty() {
let sq = Sq::new();
// Listing an empty certificate store should not be an error.
sq.cert_list(&[]);
// Listing an empty certificate store with a pattern (that doesn't
// match anything) should be.
assert!(sq.cert_list_maybe(&["not found"]).is_err());
let (cert, cert_path, _rev_path)
= sq.key_generate(&[], &[ "alice" ]);
sq.key_import(cert_path);
// Not linked => error.
assert!(sq.cert_list_maybe(&["alice"]).is_err());
// Not found => error.
assert!(sq.cert_list_maybe(&["not found"]).is_err());
// Linked and found => ok.
sq.pki_link_add(&[], cert.key_handle(), &["alice"]);
sq.cert_list(&["alice"]);
}