From fde96e57909261ae45b25a8c150f09e38de7abec Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Wed, 4 Dec 2024 10:30:06 +0100 Subject: [PATCH] Listing an empty certificate store should not be an error. - `sq cert list` on an empty certificate store should not be an error. --- src/common/pki/authenticate.rs | 4 ++++ tests/integration/sq_cert_list.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/common/pki/authenticate.rs b/src/common/pki/authenticate.rs index c6e4106c..8ed362ca 100644 --- a/src/common/pki/authenticate.rs +++ b/src/common/pki/authenticate.rs @@ -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 diff --git a/tests/integration/sq_cert_list.rs b/tests/integration/sq_cert_list.rs index 35d45cf8..7e90ba32 100644 --- a/tests/integration/sq_cert_list.rs +++ b/tests/integration/sq_cert_list.rs @@ -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"]); +}