From 990a23be281ee13e33c165f446d2ac3c0c88299c Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Sat, 21 Nov 2026 13:24:26 +0000 Subject: szecret create-local /: a new store's key goes in a bucket this machine reads; plain for an existing store or no buckets --- secrets/test/buckets.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'secrets/test/buckets.sh') diff --git a/secrets/test/buckets.sh b/secrets/test/buckets.sh index 010778a..782e7ad 100755 --- a/secrets/test/buckets.sh +++ b/secrets/test/buckets.sh @@ -313,6 +313,72 @@ test_local_store_key_in_bucket() { pass "get-local/put-local: an old-style repository store whose key moved to a bucket" } +test_create_local_in_bucket() { + local d="${TEST_DIR}/new-store" err pub + err="$(szecret create-local newstore "${d}" 2>&1)" && fail "create-local with no bucket should fail here" + assert_contains "${err}" "create-local /newstore" + [[ ! -e "${d}/.szecret" ]] || fail "a refused create-local left metadata" + [[ -z "$(find "${SZECRET_BUCKETS}" -name local-key-newstore.age)" ]] || fail "a refused create-local left a key" + + szecret create-local mine/newstore "${d}" 2>/dev/null || fail "create-local mine/newstore" + assert_file_exists "${SZECRET_BUCKETS}/mine/local-key-newstore.age" + pub="$(age -d -i "${TEST_DIR}/admin" "${SZECRET_BUCKETS}/mine/local-key-newstore.age" | age-keygen -y)" + assert_contains "$(cat "${d}/.szecret")" "pubkey=${pub}" + assert_success age -d -i "${TEST_DIR}/other" -o /dev/null "${SZECRET_BUCKETS}/mine/local-key-newstore.age" + echo "n1" | szecret put-local "${d}/v.age" 2>/dev/null || fail "put-local in the new store" + assert_equals "n1" "$(szecret get-local "${d}/v.age")" "get-local in the new store" + pass "create-local: a new store's key goes in the bucket named, read by that bucket's readers" +} + +test_create_local_existing_key() { + local d="${TEST_DIR}/new-store-2" err + err="$(szecret create-local theirs/newstore "${d}" 2>&1)" && fail "create-local naming another bucket should fail" + assert_contains "${err}" "is in mine/local-key-newstore, not in theirs" + [[ ! -e "${d}/.szecret" ]] || fail "a refused create-local left metadata" + szecret create-local newstore "${d}" 2>/dev/null || fail "create-local of an existing store" + assert_equals "n1" "$(cp "${TEST_DIR}/new-store/v.age" "${d}/v.age" && szecret get-local "${d}/v.age")" "the same store in a second directory" + szecret create-local mine/newstore "${TEST_DIR}/new-store-3" 2>/dev/null || fail "create-local naming the bucket it's in" + assert_equals "$(sed -n 's/^pubkey=//p' "${TEST_DIR}/new-store/.szecret")" "$(sed -n 's/^pubkey=//p' "${TEST_DIR}/new-store-3/.szecret")" "the existing store's key" + SZECRET_BUCKETS="" szecret create-local oldk "${TEST_DIR}/oldk" 2>/dev/null || fail "create-local in the old store" + err="$(szecret create-local mine/oldk "${TEST_DIR}/oldk-2" 2>&1)" && fail "create-local naming a bucket for an old-store key should fail" + assert_contains "${err}" "szecret mv local-key-oldk mine" + pass "create-local: an existing store gets metadata, and refuses a bucket it isn't in" +} + +test_create_local_refusals() { + local err + err="$(SZECRET_BUCKETS="" szecret create-local mine/x "${TEST_DIR}/r1" 2>&1)" && fail "a bucket with no buckets should fail" + assert_contains "${err}" "no buckets on this machine" + err="$(szecret create-local Mine/x "${TEST_DIR}/r2" 2>&1)" && fail "a bad bucket name should fail" + assert_contains "${err}" "not a bucket's name" + err="$(szecret create-local theirs/tx "${TEST_DIR}/r4" 2>&1)" && fail "a bucket this machine doesn't read should fail" + assert_contains "${err}" "doesn't read theirs" + [[ ! -e "${TEST_DIR}/r4" && ! -e "${SZECRET_BUCKETS}/theirs/local-key-tx.age" ]] || fail "a refused create-local left something" + bucket theirs "other ${other}" "me ${me}" + err="$(szecret create-local theirs/added "${TEST_DIR}/r7" 2>&1)" && fail "a reader not yet rekeyed in should fail" + assert_contains "${err}" "szecret rekey theirs first" + bucket theirs "other ${other}" + touch "${TEST_DIR}/afile" + err="$(szecret create-local mine/ff "${TEST_DIR}/afile" 2>&1)" && fail "a file as the directory should fail" + assert_contains "${err}" "is not a directory" + [[ ! -e "${SZECRET_BUCKETS}/mine/local-key-ff.age" ]] || fail "a refused create-local left a key" + err="$(szecret create-local nobucket/x "${TEST_DIR}/r5" 2>&1)" && fail "a missing bucket should fail" + assert_contains "${err}" "no bucket nobucket" + [[ ! -e "${TEST_DIR}/r5" ]] || fail "a refused create-local left its directory" + age-keygen 2>/dev/null | szecret put mine/local-key-dup 2>/dev/null + cp "${SZECRET_BUCKETS}/mine/local-key-dup.age" "${SZECRET_BUCKETS}/theirs/" + err="$(szecret create-local mine/dup "${TEST_DIR}/r6" 2>&1)" && fail "a key in two places should fail" + assert_contains "${err}" "more than one place" + rm "${SZECRET_BUCKETS}/mine/local-key-dup.age" "${SZECRET_BUCKETS}/theirs/local-key-dup.age" + bucket mine "me ${me}" + err="$(szecret create-local mine/stale "${TEST_DIR}/r3" 2>&1)" && fail "create-local into a stale bucket should fail" + assert_contains "${err}" "rekey" + [[ ! -e "${TEST_DIR}/r3" ]] || fail "a refused put left its directory" + [[ ! -e "${SZECRET_BUCKETS}/mine/local-key-stale.age" ]] || fail "a refused put left a key" + bucket mine "me ${me}" "other ${other}" + pass "create-local: refuses a bucket with no buckets, a bad name, one not read here, a missing one, a key in two places, and a bucket needing a rekey" +} + test_ready() { szecret ready || fail "ready with an identity" SZECRET_STORE="" SZECRET_PRIVATE_KEY="${TEST_DIR}/none" szecret ready || fail "ready with only buckets and an identity" @@ -339,6 +405,9 @@ test_admin_change_needs_rekey test_list test_check_ok test_local_store_key_in_bucket +test_create_local_in_bucket +test_create_local_existing_key +test_create_local_refusals test_check_stanza_types test_check_missing_plugin test_ready -- cgit v1.2.3