summaryrefslogtreecommitdiff
path: root/secrets/test/list.sh
diff options
context:
space:
mode:
Diffstat (limited to 'secrets/test/list.sh')
-rwxr-xr-xsecrets/test/list.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/secrets/test/list.sh b/secrets/test/list.sh
index cf07dd0..bd72f9a 100755
--- a/secrets/test/list.sh
+++ b/secrets/test/list.sh
@@ -179,6 +179,43 @@ test_list_reads_nothing() {
pass "list: says what to do when this machine reads nothing"
}
+# A store's key shows as its store, apart from the secrets and their count;
+# what scripts read still names the file.
+test_list_stores() {
+ local out
+ echo v | szecret put mine/local-key-proj
+ echo v | szecret put mine/local-key-alpha
+ out="$(SZECRET_FORCE_TTY=80 szecret list)"
+ assert_contains "${out}" "mine 2 secrets, 2 stores"
+ assert_contains "${out}" " stores: alpha, proj"
+ assert_contains "${out}" " mine-a mine-b"
+ [[ "${out}" != *local-key-* ]] || fail "list shows a store's key as a secret: ${out}"
+ assert_contains "${out}" "me reads 2 buckets, 8 secrets, 2 stores"
+ assert_contains "$(SZECRET_FORCE_TTY=80 szecret list --all)" "me reads 2 of 4 buckets, 8 of 10 secrets, 2 of 2 stores"
+ out="$(SZECRET_FORCE_TTY=36 szecret list)"
+ assert_contains "${out}" "me reads 2 buckets, 8 secrets,"$'\n'" 2 stores"
+ assert_contains "$(szecret list --names)" "mine/local-key-proj"
+ assert_contains "$(szecret list)" "local-key-alpha"
+ assert_contains "$(szecret list --json)" '"secrets":["local-key-alpha","local-key-proj","mine-a","mine-b"]'
+ rm "${SZECRET_BUCKETS}/mine/local-key-alpha.age" "${SZECRET_BUCKETS}/mine/local-key-proj.age"
+ pass "list: store keys as one stores line, scripts still see the files"
+}
+
+# A bucket holding only a store's key: no empty grid, no "0 secrets".
+test_list_store_only() {
+ local out
+ mkdir -p "${SZECRET_BUCKETS}/storeonly"
+ printf '# me\n%s\n' "${me}" > "${SZECRET_BUCKETS}/storeonly/recipients"
+ szecret rekey --add-ok storeonly >/dev/null
+ echo v | szecret put storeonly/local-key-solo
+ out="$(SZECRET_FORCE_TTY=80 szecret list)"
+ assert_contains "${out}" "storeonly 1 store"
+ assert_contains "${out}" " stores: solo"
+ [[ "${out}" != *"0 secrets"* ]] || fail "list says 0 secrets: ${out}"
+ rm -r "${SZECRET_BUCKETS}/storeonly"
+ pass "list: a bucket holding only a store's key"
+}
+
run_tests() {
test_list_empty_store
test_list_shows_secrets
@@ -189,6 +226,8 @@ run_tests() {
test_list_terminal_all_and_keys
test_list_narrow
test_list_json
+ test_list_stores
+ test_list_store_only
test_list_problems
test_list_reads_nothing
}