fix(bootstrap): keep the operator's auth sources across re-runs
write_felis_toml regenerates felis.host.toml and felis.pod.toml with a wholesale `cat >`, and the [[auth_source]] list was a literal LittleSkin block in that heredoc. Re-running the installer, which is also what `felis setup` does, threw away any edit to the list: a root the operator added stopped admitting logins, and a root they removed came back. The generated comment invited exactly that edit. Carry the tables forward the way [smtp] already is: read every [[auth_source]] table from the existing felis.host.toml (falling back to felis.pod.toml) and emit the LittleSkin default only when there is no earlier file at all. An earlier file with no tables stays empty, because that is a Mojang-only server rather than a missing value; felis-api now treats an empty list that way. The file header and the comment above the list now say what survives a re-run, and point at felis.host.toml, which is what the next run reads. bootstrap_test.sh extracts the new function from bootstrap.sh and checks the fresh-install default, an operator's own table carried without the default or the following section, an empty list staying empty, and the indented form the setup TUI writes. It passes under dash with gawk and with mawk; forcing the function to always return the default fails five of the new cases.
This commit is contained in:
2 files changed
+76
-8
No files matched your search
@@ -132,6 +132,53 @@ esac
|
||||
out="$(run_velocity_install "$vwant")"
|
||||
expect "the matching download installs" "INSTALL: ${vdir}/velocity.jar" "$out"
|
||||
|
||||
# --- [[auth_source]] carry-forward -----------------------------------------------------
|
||||
# write_felis_toml regenerates felis.toml wholesale on every run; this is what keeps the
|
||||
# operator's Yggdrasil roots from being reset to the shipped default.
|
||||
|
||||
ablock="$(awk '/^persisted_auth_source_blocks\(\) \{/,/^}/' "$BS")"
|
||||
[ -n "$ablock" ] || { echo "FAIL: no persisted_auth_source_blocks found in $BS"; exit 1; }
|
||||
[ "$(printf '%s\n' "$ablock" | wc -l)" -lt 20 ] \
|
||||
|| { echo "FAIL: the extracted block is not the function -- did its closing brace move?"; exit 1; }
|
||||
|
||||
sdir="$(mktemp -d)"
|
||||
trap 'rm -f "$jar"; rm -rf "$vdir" "$sdir"' EXIT
|
||||
|
||||
run_carry() {
|
||||
STATE_DIR="$sdir" bash -c "$ablock"'
|
||||
persisted_auth_source_blocks'
|
||||
}
|
||||
|
||||
out="$(run_carry)"
|
||||
expect "a first install gets the LittleSkin default" 'tag = "littleskin"' "$out"
|
||||
|
||||
printf '%s\n' '[server]' 'listen = "0.0.0.0:8080"' '' '[[auth_source]]' 'tag = "guild"' \
|
||||
'prefix = "GD"' 'url = "https://guild.example/hasJoined"' '' '[smtp]' 'host = "mail.example"' \
|
||||
> "$sdir/felis.host.toml"
|
||||
out="$(run_carry)"
|
||||
expect "an operator's root is carried forward" 'tag = "guild"' "$out"
|
||||
case "$out" in
|
||||
*littleskin*|*"[smtp]"*) echo "FAIL the carried list must be exactly the operator's tables:"; echo "$out"; fails=$((fails + 1)) ;;
|
||||
*) echo "PASS the carried list stops at the next section and adds no default" ;;
|
||||
esac
|
||||
|
||||
printf '%s\n' '[server]' 'listen = "0.0.0.0:8080"' > "$sdir/felis.host.toml"
|
||||
out="$(run_carry)"
|
||||
if [ -z "$out" ]; then
|
||||
echo "PASS a config with no sources stays Mojang-only"
|
||||
else
|
||||
echo "FAIL a config with no sources must not get the default back:"; echo "$out"; fails=$((fails + 1))
|
||||
fi
|
||||
|
||||
# The felis setup TUI re-encodes the whole file, which indents keys under each table.
|
||||
rm -f "$sdir/felis.host.toml"
|
||||
printf '%s\n' '[[auth_source]]' ' tag = "littleskin"' ' prefix = "LS"' ' url = "https://a.example"' \
|
||||
'' '[[auth_source]]' ' tag = "guild"' ' prefix = "GD"' ' url = "https://b.example"' \
|
||||
> "$sdir/felis.pod.toml"
|
||||
out="$(run_carry)"
|
||||
expect "both encoder-written tables are carried (first)" ' tag = "littleskin"' "$out"
|
||||
expect "both encoder-written tables are carried (second)" ' tag = "guild"' "$out"
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if [ "$fails" -eq 0 ]; then
|
||||
echo "ALL PASS"
|
||||
|
||||
Reference in new issue
Block a user