summaryrefslogtreecommitdiff
path: root/secrets/test/buckets.sh
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-11-19 22:31:31 +0000
committerIgor Soarez <igor@soarez.org>2026-11-19 22:31:31 +0000
commitdcbd341a04bbbf0ac7d720a3a3bf882778983bfe (patch)
treed9abbc2ddfae873f01de96dd0f5ab7501c607b5f /secrets/test/buckets.sh
parentf82380fcf0d7901635c27871162fdfc3dff2c555 (diff)
szecret mv --phone: an admin elsewhere rewraps the file key for a secret this machine can't read
The move goes to SZECRET_PHONE_COMMAND with a snapshot of the file; the new file is that snapshot's payload under the header that comes back, written only if the file is unchanged, and opened first where this machine is a new reader.
Diffstat (limited to 'secrets/test/buckets.sh')
-rwxr-xr-xsecrets/test/buckets.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/secrets/test/buckets.sh b/secrets/test/buckets.sh
index 2703952..010778a 100755
--- a/secrets/test/buckets.sh
+++ b/secrets/test/buckets.sh
@@ -139,6 +139,62 @@ test_mv() {
pass "mv: moves out of the old store; one it can't read stays put; never overwrites"
}
+# mv --phone: what szecret itself checks of the header that comes back. The
+# phone's own work (cloud-setup's phone/szmv.py) is tested there.
+test_mv_phone_refusals() {
+ local err f="${SZECRET_BUCKETS}/admin-only/a.age" before
+ before="$(shasum "${f}")"
+ untouched() {
+ assert_equals "${before}" "$(shasum "${f}")" "$1: admin-only/a is as it was"
+ [[ ! -e "${SZECRET_BUCKETS}/mine/a.age" ]] || fail "$1: left mine/a"
+ [[ -z "$(ls -A "${SZECRET_BUCKETS}/mine" | grep '^\.put\.')" ]] || fail "$1: left a temporary file"
+ }
+ err="$(SZECRET_PHONE_COMMAND="" szecret mv --phone a mine 2>&1)" && fail "no command should fail"
+ assert_contains "${err}" "SZECRET_PHONE_COMMAND"
+ untouched "no command"
+ err="$(SZECRET_PHONE_COMMAND="cat >/dev/null; exit 1" szecret mv --phone a mine 2>&1)" && fail "a failed command should fail"
+ untouched "a failed command"
+ err="$(SZECRET_PHONE_COMMAND="cat >/dev/null; echo not-a-header" szecret mv --phone a mine 2>&1)" && fail "garbage should fail"
+ assert_contains "${err}" "not a whole age header"
+ untouched "garbage"
+ # The readers it is told of, and a header of the right shape for them that
+ # is not for this file: this machine is one of the readers, and cannot open it.
+ cat > "${TEST_DIR}/fake-phone" <<'STUB'
+#!/bin/bash
+desc="$(cat)"
+args=()
+while read -r k v _; do [[ "${k}" == reader ]] && args+=(-r "${v}"); done <<<"${desc}"
+echo "${desc}" > "${TEST_DIR}/fake-phone.desc"
+echo x | age "${args[@]}" | LC_ALL=C awk '{ print } /^--- / { exit }'
+STUB
+ chmod +x "${TEST_DIR}/fake-phone"
+ err="$(TEST_DIR="${TEST_DIR}" SZECRET_PHONE_COMMAND="${TEST_DIR}/fake-phone" szecret mv --phone a mine 2>&1)" \
+ && fail "a header for another file key should fail where this machine reads it"
+ assert_contains "${err}" "cannot open the new file"
+ untouched "a wrong header"
+ assert_contains "$(cat "${TEST_DIR}/fake-phone.desc")" "name a"
+ assert_contains "$(cat "${TEST_DIR}/fake-phone.desc")" "from admin-only"
+ assert_contains "$(cat "${TEST_DIR}/fake-phone.desc")" "reader ${me} me"
+ assert_contains "$(cat "${TEST_DIR}/fake-phone.desc")" "reader ${admin} admin"
+ # The readers change while the phone answers.
+ local saved
+ saved="$(cat "${SZECRET_BUCKETS}/mine/recipients")"
+ err="$(TEST_DIR="${TEST_DIR}" SZECRET_PHONE_COMMAND="${TEST_DIR}/fake-phone; echo '${other}' >> '${SZECRET_BUCKETS}/mine/recipients'" \
+ szecret mv --phone a mine 2>&1)" && fail "a reader change while waiting should fail"
+ echo "${saved}" > "${SZECRET_BUCKETS}/mine/recipients"
+ untouched "a reader change"
+ # The file changes while the phone answers (a rekey arriving), into a
+ # bucket this machine does not read, so it cannot open the result.
+ cp "${f}" "${TEST_DIR}/a.saved"
+ err="$(TEST_DIR="${TEST_DIR}" SZECRET_PHONE_COMMAND="${TEST_DIR}/fake-phone; printf x >> '${f}'" \
+ szecret mv --phone a theirs 2>&1)" && fail "a file changed while waiting should fail"
+ assert_contains "${err}" "changed while the phone answered"
+ [[ ! -e "${SZECRET_BUCKETS}/theirs/a.age" ]] || fail "a changed file: left theirs/a"
+ cp "${TEST_DIR}/a.saved" "${f}"
+ untouched "a changed file"
+ pass "mv --phone: no command, a failure, garbage, a header that is not this file's, readers or the file changing: nothing written"
+}
+
test_put_refuses_stale_readers() {
bucket mine "me ${me}"
local err
@@ -273,6 +329,7 @@ test_plain_put_admin_only
test_old_store_side_by_side
test_two_places
test_mv
+test_mv_phone_refusals
test_put_refuses_stale_readers
test_rekey_removal
test_rekey_addition_needs_yes