store_seeded: report a failed read instead of minting over it
This commit is contained in:
parent
b0a6a28d10
commit
5f9629dfc7
1 changed files with 113 additions and 14 deletions
|
|
@ -22,7 +22,7 @@ setup() {
|
|||
dir=$(mktemp -d)
|
||||
mkdir "$dir/kv"
|
||||
export FAKE_BAO_KV=$dir/kv FAKE_BAO_LOG=$dir/bao.log FAKE_BAO_LOGIN_RC=0
|
||||
unset FAKE_BAO_DENY_READ FAKE_BAO_DENY_WRITE FAKE_BAO_RACE
|
||||
unset FAKE_BAO_DENY_READ FAKE_BAO_DENY_WRITE FAKE_BAO_RACE FAKE_BAO_READ_TIMEOUT FAKE_BAO_READ_5XX
|
||||
: >"$FAKE_BAO_LOG"
|
||||
earlier=$dir/earlier
|
||||
minted=$dir/minted
|
||||
|
|
@ -69,6 +69,19 @@ ran_mint() {
|
|||
[ -s "$minted" ]
|
||||
}
|
||||
|
||||
no_write() {
|
||||
if grep -q '^kv put' "$FAKE_BAO_LOG"; then fail "wrote to the store"; fi
|
||||
}
|
||||
|
||||
no_mint() {
|
||||
if ran_mint; then fail "ran the mint command"; fi
|
||||
}
|
||||
|
||||
# err_has <text>: the run's stderr contains it.
|
||||
err_has() {
|
||||
if ! grep -qF -- "$1" "$dir/err"; then fail "stderr lacks '$1': $(cat "$dir/err")"; fi
|
||||
}
|
||||
|
||||
setup "an empty store is seeded from the file, unchanged, and nothing is minted"
|
||||
printf 'old-value\n' >"$earlier"
|
||||
run
|
||||
|
|
@ -111,19 +124,80 @@ run
|
|||
expect 0 winner-value
|
||||
held winner-value
|
||||
|
||||
setup "a store that grants neither read nor write leaves the file's value in use"
|
||||
setup "a refused read uses the file's value, writes nothing, mints nothing and prints the refusal"
|
||||
printf 'old-value\n' >"$earlier"
|
||||
export FAKE_BAO_DENY_READ=1 FAKE_BAO_DENY_WRITE=1
|
||||
run
|
||||
expect 0 old-value
|
||||
held ""
|
||||
if ran_mint; then fail "minted although the file held a value"; fi
|
||||
no_write
|
||||
no_mint
|
||||
err_has "could not read $leaf from the swarm secret store"
|
||||
err_has "permission denied"
|
||||
err_has "using the value of $earlier"
|
||||
|
||||
setup "a store that grants neither, and no file, gives no value and mints nothing into it"
|
||||
setup "a refused read, and no file, fails without writing or minting and prints the refusal"
|
||||
export FAKE_BAO_DENY_READ=1 FAKE_BAO_DENY_WRITE=1
|
||||
run
|
||||
expect 1 ""
|
||||
held ""
|
||||
no_write
|
||||
no_mint
|
||||
err_has "could not read $leaf from the swarm secret store"
|
||||
err_has "permission denied"
|
||||
|
||||
setup "a read that times out uses the file's value without writing, and says why"
|
||||
printf 'old-value\n' >"$earlier"
|
||||
export FAKE_BAO_READ_TIMEOUT=1
|
||||
run
|
||||
expect 0 old-value
|
||||
held ""
|
||||
no_write
|
||||
no_mint
|
||||
err_has "could not read $leaf from the swarm secret store (exit status 124)"
|
||||
|
||||
setup "a read that times out, and no file, fails without writing or minting"
|
||||
export FAKE_BAO_READ_TIMEOUT=1
|
||||
run
|
||||
expect 1 ""
|
||||
held ""
|
||||
no_write
|
||||
no_mint
|
||||
err_has "(exit status 124)"
|
||||
|
||||
setup "a read that times out on a leaf the store holds leaves the leaf as it is"
|
||||
printf 'stored-value' >"$stored"
|
||||
printf 'old-value\n' >"$earlier"
|
||||
export FAKE_BAO_READ_TIMEOUT=1
|
||||
run
|
||||
expect 0 old-value
|
||||
held stored-value
|
||||
no_write
|
||||
no_mint
|
||||
|
||||
setup "a read that gets a server error, and no file, fails without writing and prints the error"
|
||||
export FAKE_BAO_READ_5XX=1
|
||||
run
|
||||
expect 1 ""
|
||||
held ""
|
||||
no_write
|
||||
no_mint
|
||||
err_has "Code: 503"
|
||||
|
||||
setup "a leaf the store does not hold is the only read failure that mints, and no error is printed"
|
||||
run
|
||||
expect 0 minted-value
|
||||
held minted-value
|
||||
if ! ran_mint; then fail "did not mint"; fi
|
||||
if grep -q 'could not read' "$dir/err"; then fail "reported a missing leaf as a failed read"; fi
|
||||
|
||||
setup "a store that takes no write leaves the file's value in use"
|
||||
printf 'old-value\n' >"$earlier"
|
||||
export FAKE_BAO_DENY_WRITE=1
|
||||
run
|
||||
expect 0 old-value
|
||||
held ""
|
||||
if ran_mint; then fail "minted although the file held a value"; fi
|
||||
|
||||
setup "a store that refuses the login leaves the file's value in use and is not called again"
|
||||
printf 'old-value\n' >"$earlier"
|
||||
|
|
|
|||
Loading…
Reference in a new issue