1 parent
639362fbf5
commit
bdd69f0aad
101 files changed
+22691
-531
No files matched your search
@@ -36,32 +36,28 @@ assert_not_contains() {
|
||||
|
||||
make_payload() {
|
||||
local root=$1
|
||||
install -d -- "$root/bin" "$root/lib" "$root/share/echoion/web" "$root/service"
|
||||
install -d -- "$root/bin" "$root/lib" "$root/share/echoion/web" \
|
||||
"$root/share/echoion/tools" "$root/service" \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-internal/1.0.0" \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-external/1.0.0"
|
||||
install -m 0755 -- "$PACKAGING_DIR/install.sh" "$root/install.sh"
|
||||
install -m 0755 -- "$PACKAGING_DIR/uninstall.sh" "$root/uninstall.sh"
|
||||
install -m 0644 -- "$PACKAGING_DIR/service/echoion.service.in" "$root/service/echoion.service.in"
|
||||
cat > "$root/manifest.json" <<'EOF'
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"version": "1.2.3",
|
||||
"files": [
|
||||
{"path": "bin/echoiond"}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
install -m 0644 -- "$PACKAGING_DIR/service/echoion-updater.service.in" \
|
||||
"$root/service/echoion-updater.service.in"
|
||||
install -m 0644 -- "$PACKAGING_DIR/service/echoion-updater.timer.in" \
|
||||
"$root/service/echoion-updater.timer.in"
|
||||
install -m 0755 -- "$PACKAGING_DIR/../scripts/validate-release-manifest.py" \
|
||||
"$root/share/echoion/tools/validate-release-manifest.py"
|
||||
cat > "$root/bin/echoiond" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
if [[ ${1:-} == --validate-install && -n ${2:-} ]]; then
|
||||
printf '%s\n' "$2" >> "${VALIDATOR_LOG:?}"
|
||||
if [[ -n ${VALIDATOR_FAIL_PATH:-} && $2 == "$VALIDATOR_FAIL_PATH" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
if [[ ${ALLOW_DAEMON_RUN:-0} == 1 ]]; then
|
||||
printf 'ECHOION_HOME=%s\n' "${ECHOION_HOME:-}" >> "${DAEMON_LOG:?}"
|
||||
printf 'ECHOION_CORE_PATH=%s\n' "${ECHOION_CORE_PATH:-}" >> "$DAEMON_LOG"
|
||||
printf 'ECHOION_STATE_DIR=%s\n' "${ECHOION_STATE_DIR:-}" >> "$DAEMON_LOG"
|
||||
printf 'ECHOION_INCOMING_DIR=%s\n' "${ECHOION_INCOMING_DIR:-}" >> "$DAEMON_LOG"
|
||||
printf 'LD_LIBRARY_PATH=%s\n' "${LD_LIBRARY_PATH:-}" >> "$DAEMON_LOG"
|
||||
printf 'PWD=%s\n' "$PWD" >> "$DAEMON_LOG"
|
||||
argument_index=0
|
||||
for argument in "$@"; do
|
||||
printf 'ARG_%d=%s\n' "$argument_index" "$argument" >> "$DAEMON_LOG"
|
||||
@@ -73,6 +69,12 @@ printf 'daemon unexpectedly ran\n' >> "${DAEMON_LOG:?}"
|
||||
exit 1
|
||||
EOF
|
||||
chmod 0755 "$root/bin/echoiond"
|
||||
cat > "$root/bin/echoion-updater" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf 'updater unexpectedly ran\n' >> "${DAEMON_LOG:?}"
|
||||
exit 1
|
||||
EOF
|
||||
chmod 0755 "$root/bin/echoion-updater"
|
||||
printf 'fake dynamic core\n' > "$root/lib/Echoion.ts"
|
||||
cat > "$root/share/echoion/config.example.json" <<'EOF'
|
||||
{
|
||||
@@ -83,6 +85,12 @@ EOF
|
||||
}
|
||||
EOF
|
||||
printf '<!doctype html>\n' > "$root/share/echoion/web/index.html"
|
||||
printf 'fake internal shortener plugin 1.0.0\n' > \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-internal/1.0.0/url-shortener-internal.so"
|
||||
printf 'fake external shortener plugin 1.0.0\n' > \
|
||||
"$root/share/echoion/bootstrap-plugins/url-shortener-external/1.0.0/url-shortener-external.so"
|
||||
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
|
||||
--root "$root" --version 1.2.3
|
||||
}
|
||||
|
||||
fake_bin=$TEST_ROOT/fake-bin
|
||||
@@ -96,6 +104,10 @@ printf '%s\n' "$*" >> "${SYSTEMCTL_LOG:?}"
|
||||
if [[ ${SYSTEMCTL_FAIL_RESTART:-0} == 1 && " $* " == *' restart '* ]]; then
|
||||
exit 1
|
||||
fi
|
||||
if [[ ${SYSTEMCTL_FAIL_UPDATER_STOP:-0} == 1 &&
|
||||
" $* " == *' stop echoion-updater.service '* ]]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
chmod 0755 "$fake_bin/systemctl"
|
||||
@@ -114,16 +126,52 @@ export PATH=$fake_bin:$PATH
|
||||
export HOME=$home
|
||||
export XDG_CONFIG_HOME=$home/.config
|
||||
export XDG_STATE_HOME=$home/.state
|
||||
export XDG_CACHE_HOME=$home/.cache
|
||||
export SYSTEMCTL_LOG=$TEST_ROOT/systemctl.log
|
||||
export DAEMON_LOG=$TEST_ROOT/daemon.log
|
||||
export VALIDATOR_LOG=$TEST_ROOT/validator.log
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
: > "$DAEMON_LOG"
|
||||
: > "$VALIDATOR_LOG"
|
||||
|
||||
bash -n "$PACKAGING_DIR/install.sh"
|
||||
bash -n "$PACKAGING_DIR/uninstall.sh"
|
||||
|
||||
escaped_systemd_path=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_path_escape '/srv/echoion path/%/dollar$'
|
||||
)
|
||||
[[ $escaped_systemd_path == '/srv/echoion\x20path/%%/dollar$' ]] ||
|
||||
fail 'systemd path escaping did not preserve space, percent, and dollar characters'
|
||||
escaped_systemd_path_controls=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_path_escape $'/srv/line\ncarriage\rtab\tend'
|
||||
)
|
||||
[[ $escaped_systemd_path_controls == \
|
||||
'/srv/line\x0acarriage\x0dtab\x09end' ]] ||
|
||||
fail 'systemd path escaping emitted a raw control character'
|
||||
escaped_systemd_setting_controls=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_setting_escape $'line\ncarriage\rtab\tend'
|
||||
)
|
||||
[[ $escaped_systemd_setting_controls == 'line\ncarriage\rtab\tend' ]] ||
|
||||
fail 'systemd setting escaping emitted a raw control character'
|
||||
escaped_systemd_exec_dollar=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
systemd_exec_escape "/srv/\$HOME/path"
|
||||
)
|
||||
[[ $escaped_systemd_exec_dollar == "/srv/\$\$HOME/path" ]] ||
|
||||
fail 'systemd executable escaping did not protect a literal dollar variable'
|
||||
escaped_json_controls=$(
|
||||
# shellcheck source=../install.sh
|
||||
source "$PACKAGING_DIR/install.sh"
|
||||
json_escape $'line\ncarriage\rtab\tend'
|
||||
)
|
||||
[[ $escaped_json_controls == 'line\ncarriage\rtab\tend' ]] ||
|
||||
fail 'JSON escaping emitted a raw control character'
|
||||
|
||||
trusted_parent=$TEST_ROOT/trusted-parent
|
||||
trusted_prefix=$trusted_parent/echoion
|
||||
install -d -m 0700 -- "$trusted_prefix"
|
||||
@@ -242,13 +290,13 @@ chmod 0640 "$metadata_config/config.json"
|
||||
config_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_config")
|
||||
state_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_state")
|
||||
file_metadata_before=$(stat -c '%u:%g:%a' -- "$metadata_config/config.json")
|
||||
export VALIDATOR_FAIL_PATH=$metadata_prefix/versions/1.2.3
|
||||
export RECORD_COMMIT_FAIL=1
|
||||
if "$payload/install.sh" --mode portable --prefix "$metadata_prefix" \
|
||||
--config-dir "$metadata_config" --state-dir "$metadata_state" \
|
||||
--register-service none --non-interactive >/dev/null 2>&1; then
|
||||
fail 'installer accepted injected post-metadata validation failure'
|
||||
fail 'installer accepted injected post-metadata record failure'
|
||||
fi
|
||||
unset VALIDATOR_FAIL_PATH
|
||||
unset RECORD_COMMIT_FAIL
|
||||
config_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_config")
|
||||
state_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_state")
|
||||
file_metadata_after=$(stat -c '%u:%g:%a' -- "$metadata_config/config.json")
|
||||
@@ -295,18 +343,39 @@ self_prefix=$TEST_ROOT/self-contained
|
||||
--data-layout self-contained --register-service none --non-interactive
|
||||
[[ $(readlink -- "$self_prefix/current") == versions/1.2.3 ]] || fail 'wrong current target'
|
||||
assert_file "$self_prefix/versions/1.2.3/bin/echoiond"
|
||||
assert_file "$self_prefix/versions/1.2.3/bin/echoion-updater"
|
||||
assert_file "$self_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
[[ -d $self_prefix/libexec/updater/1.2.3/lib ]] ||
|
||||
fail 'privileged updater has no private dynamic library closure'
|
||||
assert_file "$self_prefix/config/config.json"
|
||||
assert_file "$self_prefix/state/plugins/.managed/url-shortener-internal/versions/1.0.0/url-shortener-internal.so"
|
||||
assert_file "$self_prefix/state/plugins/.managed/url-shortener-external/versions/1.0.0/url-shortener-external.so"
|
||||
[[ -d $self_prefix/state/plugins/.managed/url-shortener-internal/staging ]] ||
|
||||
fail 'internal shortener managed staging directory was not created'
|
||||
[[ $(readlink -- "$self_prefix/state/plugins/.managed/url-shortener-internal/current") == versions/1.0.0 ]] ||
|
||||
fail 'internal shortener bootstrap did not select its bundled version'
|
||||
[[ $(readlink -- "$self_prefix/state/plugins/.managed/url-shortener-external/current") == versions/1.0.0 ]] ||
|
||||
fail 'external shortener bootstrap did not select its bundled version'
|
||||
[[ -d $self_prefix/config/plugins.d ]] ||
|
||||
fail 'per-plugin configuration directory was not created'
|
||||
assert_file "$self_prefix/install.json"
|
||||
[[ -d $self_prefix/state && -d $self_prefix/cache && -d $self_prefix/logs &&
|
||||
-d $self_prefix/incoming ]] || fail 'single-root mutable layout is incomplete'
|
||||
[[ -x $self_prefix/echoion ]] || fail 'portable launcher is not executable'
|
||||
assert_contains "$self_prefix/.echoion-install" 'relocatable=1'
|
||||
assert_contains "$self_prefix/.echoion-install" 'prefix=.'
|
||||
assert_contains "$self_prefix/.echoion-install" 'config_dir=config'
|
||||
assert_contains "$self_prefix/.echoion-install" 'state_dir=data'
|
||||
assert_contains "$self_prefix/.echoion-install" 'state_dir=state'
|
||||
assert_contains "$self_prefix/.echoion-install" 'launcher=echoion'
|
||||
assert_contains "$self_prefix/config/config.json" '"webRoot": "./web"'
|
||||
assert_contains "$self_prefix/.echoion-install" \
|
||||
'updater_helper=libexec/updater/1.2.3/bin/echoion-updater'
|
||||
assert_contains "$self_prefix/install.json" \
|
||||
'"privilegedHelper": "libexec/updater/1.2.3/bin/echoion-updater"'
|
||||
assert_contains "$self_prefix/config/config.json" \
|
||||
'"webRoot": "./share/echoion/web"'
|
||||
assert_not_contains "$self_prefix/config/config.json" "$self_prefix/current"
|
||||
[[ ! -s $SYSTEMCTL_LOG ]] || fail 'service command ran for register-service none'
|
||||
[[ ! -s $DAEMON_LOG ]] || fail 'daemon ran during installation'
|
||||
assert_contains "$VALIDATOR_LOG" "$self_prefix/versions/1.2.3"
|
||||
self_moved_prefix=$TEST_ROOT/self-contained-moved
|
||||
mv -- "$self_prefix" "$self_moved_prefix"
|
||||
assert_not_exists "$self_prefix"
|
||||
@@ -314,11 +383,15 @@ assert_not_exists "$self_prefix"
|
||||
ALLOW_DAEMON_RUN=1 "$self_moved_prefix/echoion" --probe 'two words'
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_HOME=$self_moved_prefix/current"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_CORE_PATH=$self_moved_prefix/current/lib/Echoion.ts"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_STATE_DIR=$self_moved_prefix/data"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_STATE_DIR=$self_moved_prefix/state"
|
||||
assert_contains "$DAEMON_LOG" "ECHOION_INCOMING_DIR=$self_moved_prefix/incoming"
|
||||
assert_contains "$DAEMON_LOG" \
|
||||
"LD_LIBRARY_PATH=$self_moved_prefix/current/lib"
|
||||
assert_contains "$DAEMON_LOG" "PWD=$self_moved_prefix/current"
|
||||
assert_contains "$DAEMON_LOG" 'ARG_0=--config'
|
||||
assert_contains "$DAEMON_LOG" "ARG_1=$self_moved_prefix/config/config.json"
|
||||
assert_contains "$DAEMON_LOG" 'ARG_2=--state-dir'
|
||||
assert_contains "$DAEMON_LOG" "ARG_3=$self_moved_prefix/data"
|
||||
assert_contains "$DAEMON_LOG" "ARG_3=$self_moved_prefix/state"
|
||||
assert_contains "$DAEMON_LOG" 'ARG_4=--probe'
|
||||
assert_contains "$DAEMON_LOG" 'ARG_5=two words'
|
||||
: > "$DAEMON_LOG"
|
||||
@@ -370,49 +443,250 @@ assert_not_exists "$custom_prefix"
|
||||
assert_not_exists "$custom_config"
|
||||
assert_not_exists "$custom_state"
|
||||
|
||||
unit=$XDG_CONFIG_HOME/systemd/user/echoion.service
|
||||
updater_unit=$XDG_CONFIG_HOME/systemd/user/echoion-updater.service
|
||||
updater_timer=$XDG_CONFIG_HOME/systemd/user/echoion-updater.timer
|
||||
self_service_prefix=$TEST_ROOT/portable-self-contained-service
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
: > "$DAEMON_LOG"
|
||||
"$payload/install.sh" --mode portable --prefix "$self_service_prefix" \
|
||||
--data-layout self-contained --register-service user --non-interactive
|
||||
assert_file "$unit"
|
||||
assert_file "$updater_unit"
|
||||
assert_file "$updater_timer"
|
||||
assert_file "$self_service_prefix/config/config.json"
|
||||
[[ -d $self_service_prefix/state && -d $self_service_prefix/cache &&
|
||||
-d $self_service_prefix/logs && -d $self_service_prefix/incoming ]] ||
|
||||
fail 'self-contained service mutable layout escaped the portable prefix'
|
||||
assert_contains "$unit" "WorkingDirectory=$self_service_prefix/current"
|
||||
assert_contains "$unit" "Environment=\"ECHOION_STATE_DIR=$self_service_prefix/state\""
|
||||
assert_contains "$unit" \
|
||||
"Environment=\"ECHOION_INCOMING_DIR=$self_service_prefix/incoming\""
|
||||
assert_contains "$unit" \
|
||||
"Environment=\"LD_LIBRARY_PATH=$self_service_prefix/current/lib\""
|
||||
assert_contains "$unit" \
|
||||
"--config \"$self_service_prefix/config/config.json\" --state-dir \"$self_service_prefix/state\""
|
||||
assert_contains "$updater_unit" \
|
||||
"WorkingDirectory=$self_service_prefix"
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user daemon-reload'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" \
|
||||
'--user disable --now echoion.service echoion-updater.timer'
|
||||
if grep -E -- '(^| )(enable|restart|start)( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
|
||||
fail 'self-contained portable service was activated without --start'
|
||||
fi
|
||||
[[ ! -s $DAEMON_LOG ]] ||
|
||||
fail 'daemon or updater ran during self-contained service registration'
|
||||
"$self_service_prefix/uninstall.sh" --purge --non-interactive >/dev/null
|
||||
assert_not_exists "$unit"
|
||||
assert_not_exists "$updater_unit"
|
||||
assert_not_exists "$updater_timer"
|
||||
assert_not_exists "$self_service_prefix"
|
||||
|
||||
service_prefix="$TEST_ROOT/portable path % dollar\$"
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
"$payload/install.sh" --mode portable --prefix "$service_prefix" \
|
||||
--data-layout standard --register-service user --non-interactive
|
||||
unit=$XDG_CONFIG_HOME/systemd/user/echoion.service
|
||||
assert_file "$unit"
|
||||
assert_contains "$unit" 'WorkingDirectory="'
|
||||
assert_contains "$unit" 'portable path %% dollar$/current"'
|
||||
assert_file "$updater_unit"
|
||||
assert_file "$updater_timer"
|
||||
assert_contains "$unit" 'WorkingDirectory='
|
||||
assert_not_contains "$unit" 'WorkingDirectory="'
|
||||
assert_contains "$unit" 'portable\x20path\x20%%\x20dollar$/current'
|
||||
assert_contains "$unit" 'ExecStart="'
|
||||
assert_contains "$unit" 'portable path %% dollar$$/current/bin/echoiond"'
|
||||
assert_contains "$unit" 'Environment="ECHOION_HOME='
|
||||
assert_contains "$unit" 'Environment="ECHOION_CORE_PATH='
|
||||
assert_contains "$unit" 'Environment="ECHOION_STATE_DIR='
|
||||
assert_contains "$unit" 'Environment="ECHOION_INCOMING_DIR='
|
||||
assert_contains "$unit" 'Environment="LD_LIBRARY_PATH='
|
||||
assert_contains "$unit" '--config "'
|
||||
assert_contains "$unit" '--state-dir "'
|
||||
assert_contains "$updater_unit" \
|
||||
'portable path %% dollar$$/libexec/updater/1.2.3/bin/echoion-updater"'
|
||||
assert_not_contains "$updater_unit" '/current/bin/echoion-updater'
|
||||
assert_contains "$updater_unit" \
|
||||
'WorkingDirectory='"$TEST_ROOT"'/portable\x20path\x20%%\x20dollar$'
|
||||
assert_not_contains "$updater_unit" 'WorkingDirectory="'
|
||||
if grep -E '@[A-Z_]+@' "$unit" >/dev/null; then
|
||||
fail 'generated systemd unit contains an unresolved template marker'
|
||||
fi
|
||||
if grep -E '@[A-Z_]+@' "$updater_unit" "$updater_timer" >/dev/null; then
|
||||
fail 'generated updater unit contains an unresolved template marker'
|
||||
fi
|
||||
if command -v systemd-analyze >/dev/null 2>&1; then
|
||||
verify_log=$TEST_ROOT/systemd-verify.log
|
||||
if ! systemd-analyze verify "$unit" 2> "$verify_log" &&
|
||||
grep -E 'echoion\.service:|Failed to load unit' "$verify_log" >/dev/null; then
|
||||
if ! systemd-analyze verify "$unit" "$updater_unit" "$updater_timer" \
|
||||
2> "$verify_log" &&
|
||||
grep -E 'not absolute|Unknown escape|Failed to parse|Invalid argument|fatal error|bad unit file setting|Failed to load unit' \
|
||||
"$verify_log" >/dev/null; then
|
||||
cat "$verify_log" >&2
|
||||
fail 'generated systemd unit did not verify'
|
||||
fail 'generated systemd units did not verify'
|
||||
fi
|
||||
fi
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user daemon-reload'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user disable --now echoion.service'
|
||||
if grep -E -- '(^| )enable( |$)|(^| )restart( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
|
||||
fail 'service was activated without --start'
|
||||
fi
|
||||
[[ ! -s $DAEMON_LOG ]] || fail 'daemon ran during service registration'
|
||||
|
||||
command -v fakeroot >/dev/null 2>&1 ||
|
||||
fail 'fakeroot is required for rootless system-service installer coverage'
|
||||
system_fake_bin=$TEST_ROOT/system-fake-bin
|
||||
system_payload=$TEST_ROOT/system-payload
|
||||
system_service_prefix="$TEST_ROOT/portable system % dollar\$"
|
||||
system_unit_root=$TEST_ROOT/systemd/system
|
||||
install -d -- "$system_fake_bin" "$system_service_prefix" "$system_unit_root"
|
||||
make_payload "$system_payload"
|
||||
sed -i "s#/etc/systemd/system#$system_unit_root#g" \
|
||||
"$system_payload/install.sh"
|
||||
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
|
||||
--root "$system_payload" --version 1.2.3
|
||||
|
||||
REAL_CHOWN=$(command -v chown)
|
||||
REAL_CP=$(command -v cp)
|
||||
REAL_GETENT=$(command -v getent)
|
||||
REAL_ID=$(command -v id)
|
||||
export REAL_CHOWN REAL_CP REAL_GETENT REAL_ID
|
||||
export SYSTEM_SERVICE_PREFIX=$system_service_prefix
|
||||
cat > "$system_fake_bin/chown" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
arguments=()
|
||||
for argument in "$@"; do
|
||||
case $argument in
|
||||
echoion:echoion) arguments+=(4242:4242) ;;
|
||||
root:echoion) arguments+=(0:4242) ;;
|
||||
*) arguments+=("$argument") ;;
|
||||
esac
|
||||
done
|
||||
"${REAL_CHOWN:?}" "${arguments[@]}" 2>/dev/null || true
|
||||
EOF
|
||||
cat > "$system_fake_bin/cp" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
arguments=()
|
||||
for argument in "$@"; do
|
||||
if [[ $argument == -a ]]; then
|
||||
arguments+=(-R --preserve=mode,timestamps,links)
|
||||
else
|
||||
arguments+=("$argument")
|
||||
fi
|
||||
done
|
||||
exec "${REAL_CP:?}" "${arguments[@]}"
|
||||
EOF
|
||||
cat > "$system_fake_bin/getent" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
case ${1:-}:${2:-} in
|
||||
passwd:echoion) printf 'echoion:x:4242:4242::/nonexistent:/usr/sbin/nologin\n' ;;
|
||||
group:echoion) printf 'echoion:x:4242:\n' ;;
|
||||
*) exec "${REAL_GETENT:?}" "$@" ;;
|
||||
esac
|
||||
EOF
|
||||
cat > "$system_fake_bin/id" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
case ${1:-}:${2:-} in
|
||||
-u:echoion | -g:echoion) printf '4242\n' ;;
|
||||
*) exec "${REAL_ID:?}" "$@" ;;
|
||||
esac
|
||||
EOF
|
||||
cat > "$system_fake_bin/runuser" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
[[ ${1:-} == -u && ${2:-} == echoion && ${3:-} == -- ]] || exit 64
|
||||
shift 3
|
||||
if [[ ${1:-} == find ]]; then
|
||||
exit 0
|
||||
fi
|
||||
if [[ ${1:-} == test && ${2:-} == -w ]]; then
|
||||
case ${3:-} in
|
||||
"${SYSTEM_SERVICE_PREFIX:?}/state" | "${SYSTEM_SERVICE_PREFIX:?}/state"/* | \
|
||||
"${SYSTEM_SERVICE_PREFIX:?}/cache" | "${SYSTEM_SERVICE_PREFIX:?}/logs" | \
|
||||
"${SYSTEM_SERVICE_PREFIX:?}/incoming") exit 0 ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
fi
|
||||
exec "$@"
|
||||
EOF
|
||||
chmod 0755 "$system_fake_bin/chown" "$system_fake_bin/cp" \
|
||||
"$system_fake_bin/getent" "$system_fake_bin/id" "$system_fake_bin/runuser"
|
||||
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
: > "$DAEMON_LOG"
|
||||
# shellcheck disable=SC2016 # Expanded by the fakeroot child shell.
|
||||
SYSTEM_PAYLOAD=$system_payload PATH=$system_fake_bin:$PATH fakeroot -- \
|
||||
bash -euo pipefail -c '
|
||||
current=${SYSTEM_SERVICE_PREFIX:?}
|
||||
while :; do
|
||||
chown root:root -- "$current"
|
||||
[[ $current == / ]] && break
|
||||
current=$(dirname -- "$current")
|
||||
done
|
||||
"${SYSTEM_PAYLOAD:?}/install.sh" --mode portable \
|
||||
--prefix "$SYSTEM_SERVICE_PREFIX" --data-layout self-contained \
|
||||
--register-service system --non-interactive
|
||||
'
|
||||
system_unit=$system_unit_root/echoion.service
|
||||
system_updater_unit=$system_unit_root/echoion-updater.service
|
||||
system_updater_timer=$system_unit_root/echoion-updater.timer
|
||||
assert_file "$system_unit"
|
||||
assert_file "$system_updater_unit"
|
||||
assert_file "$system_updater_timer"
|
||||
assert_contains "$system_unit" 'User=echoion'
|
||||
assert_contains "$system_unit" 'Group=echoion'
|
||||
assert_contains "$system_unit" 'WantedBy=multi-user.target'
|
||||
assert_contains "$system_unit" \
|
||||
'portable\x20system\x20%%\x20dollar$/current'
|
||||
assert_not_contains "$system_unit" 'WorkingDirectory="'
|
||||
assert_contains "$system_updater_unit" \
|
||||
'WorkingDirectory='"$TEST_ROOT"'/portable\x20system\x20%%\x20dollar$'
|
||||
assert_contains "$system_updater_unit" 'ReadWritePaths='
|
||||
assert_contains "$system_updater_unit" \
|
||||
'portable\x20system\x20%%\x20dollar$'
|
||||
assert_not_contains "$system_updater_unit" 'ReadWritePaths="'
|
||||
assert_contains "$SYSTEMCTL_LOG" 'daemon-reload'
|
||||
assert_contains "$SYSTEMCTL_LOG" 'stop echoion-updater.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" \
|
||||
'disable --now echoion.service echoion-updater.timer'
|
||||
assert_not_contains "$SYSTEMCTL_LOG" '--user'
|
||||
if grep -E -- '(^| )(enable|restart|start)( |$)' "$SYSTEMCTL_LOG" >/dev/null; then
|
||||
fail 'portable system service was activated without --start'
|
||||
fi
|
||||
[[ ! -s $DAEMON_LOG ]] ||
|
||||
fail 'daemon or updater ran during portable system service registration'
|
||||
if command -v systemd-analyze >/dev/null 2>&1; then
|
||||
verify_log=$TEST_ROOT/system-systemd-verify.log
|
||||
if ! systemd-analyze verify "$system_unit" "$system_updater_unit" \
|
||||
"$system_updater_timer" 2> "$verify_log" &&
|
||||
grep -E 'not absolute|Unknown escape|Failed to parse|Invalid argument|fatal error|bad unit file setting|Failed to load unit' \
|
||||
"$verify_log" >/dev/null; then
|
||||
cat "$verify_log" >&2
|
||||
fail 'generated system-scope systemd units did not verify'
|
||||
fi
|
||||
fi
|
||||
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
"$payload/install.sh" --mode portable --prefix "$service_prefix" \
|
||||
--data-layout standard --register-service user --start --non-interactive
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user enable echoion.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" 'echoion-updater.timer'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user restart echoion.service'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user start echoion-updater.timer'
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user is-active --quiet echoion.service'
|
||||
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
export SYSTEMCTL_FAIL_UPDATER_STOP=1
|
||||
if "$service_prefix/uninstall.sh" --non-interactive >/dev/null 2>&1; then
|
||||
fail 'uninstaller continued after the updater service could not be stopped'
|
||||
fi
|
||||
unset SYSTEMCTL_FAIL_UPDATER_STOP
|
||||
assert_file "$service_prefix/current/bin/echoiond"
|
||||
assert_file "$unit"
|
||||
: > "$SYSTEMCTL_LOG"
|
||||
"$service_prefix/uninstall.sh" --non-interactive
|
||||
assert_contains "$SYSTEMCTL_LOG" '--user stop echoion-updater.service'
|
||||
assert_not_exists "$unit"
|
||||
assert_not_exists "$updater_unit"
|
||||
assert_not_exists "$updater_timer"
|
||||
assert_not_exists "$service_prefix/versions"
|
||||
assert_file "$XDG_CONFIG_HOME/echoion/config.json"
|
||||
[[ -d $XDG_STATE_HOME/echoion ]] || fail 'state directory was not preserved'
|
||||
@@ -444,12 +718,96 @@ rollback_prefix=$TEST_ROOT/rollback
|
||||
--register-service user --non-interactive >/dev/null
|
||||
old_unit_hash=$(sha256sum -- "$unit")
|
||||
old_unit_hash=${old_unit_hash%% *}
|
||||
old_updater_helper_hash=$(sha256sum -- \
|
||||
"$rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
old_updater_helper_hash=${old_updater_helper_hash%% *}
|
||||
upgrade_payload=$TEST_ROOT/upgrade-payload
|
||||
cp -a -- "$payload" "$upgrade_payload"
|
||||
sed -i 's/"version": "1.2.3"/"version": "1.2.4"/' "$upgrade_payload/manifest.json"
|
||||
for plugin_id in url-shortener-internal url-shortener-external; do
|
||||
mv -- "$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.0.0" \
|
||||
"$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.1.0"
|
||||
printf 'fake %s plugin 1.1.0\n' "$plugin_id" > \
|
||||
"$upgrade_payload/share/echoion/bootstrap-plugins/$plugin_id/1.1.0/$plugin_id.so"
|
||||
done
|
||||
printf '# changed in 1.2.4\n' >> "$upgrade_payload/service/echoion.service.in"
|
||||
printf '# changed installer helper in 1.2.4\n' >> "$upgrade_payload/install.sh"
|
||||
printf '# changed uninstaller helper in 1.2.4\n' >> "$upgrade_payload/uninstall.sh"
|
||||
printf '# changed privileged updater helper in 1.2.4\n' >> \
|
||||
"$upgrade_payload/bin/echoion-updater"
|
||||
python3 "$PACKAGING_DIR/../scripts/generate-release-manifest.py" \
|
||||
--root "$upgrade_payload" --version 1.2.4
|
||||
|
||||
bootstrap_upgrade_prefix=$TEST_ROOT/bootstrap-upgrade
|
||||
"$payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
install -d -- \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/9.0.0" \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal"
|
||||
printf 'custom internal plugin\n' > \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/9.0.0/url-shortener-internal.so"
|
||||
rm -f -- \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
ln -s -- versions/9.0.0 \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
printf '{"allowHttp":false}\n' > \
|
||||
"$bootstrap_upgrade_prefix/config/plugins.d/url-shortener-internal.json"
|
||||
printf 'persistent sqlite bytes\n' > \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal/links.db"
|
||||
"$upgrade_payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
# Installing the exact release twice must be a no-op for managed plugin state.
|
||||
"$upgrade_payload/install.sh" --mode portable --prefix "$bootstrap_upgrade_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
[[ $(readlink -- "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/current") == versions/9.0.0 ]] ||
|
||||
fail 'upgrade replaced a custom active internal shortener version'
|
||||
[[ $(readlink -- "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-external/current") == versions/1.0.0 ]] ||
|
||||
fail 'upgrade changed an existing external shortener selection'
|
||||
assert_file "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0/url-shortener-internal.so"
|
||||
assert_file "$bootstrap_upgrade_prefix/state/plugins/.managed/url-shortener-external/versions/1.1.0/url-shortener-external.so"
|
||||
assert_contains \
|
||||
"$bootstrap_upgrade_prefix/config/plugins.d/url-shortener-internal.json" \
|
||||
'"allowHttp":false'
|
||||
assert_contains \
|
||||
"$bootstrap_upgrade_prefix/state/plugins/data/url-shortener-internal/links.db" \
|
||||
'persistent sqlite bytes'
|
||||
"$bootstrap_upgrade_prefix/uninstall.sh" --purge --non-interactive >/dev/null
|
||||
assert_not_exists "$bootstrap_upgrade_prefix"
|
||||
|
||||
missing_plugin_current_prefix=$TEST_ROOT/missing-plugin-current
|
||||
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
rm -f -- \
|
||||
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
sed -i 's#\./share/echoion/web#./web#' \
|
||||
"$missing_plugin_current_prefix/config/config.json"
|
||||
export RECORD_COMMIT_FAIL=1
|
||||
if "$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null 2>&1; then
|
||||
fail 'missing plugin selection upgrade accepted a failed record commit'
|
||||
fi
|
||||
unset RECORD_COMMIT_FAIL
|
||||
assert_not_exists \
|
||||
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current"
|
||||
assert_contains "$missing_plugin_current_prefix/config/config.json" \
|
||||
'"webRoot": "./web"'
|
||||
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
[[ $(readlink -- \
|
||||
"$missing_plugin_current_prefix/state/plugins/.managed/url-shortener-internal/current") == \
|
||||
versions/1.0.0 ]] ||
|
||||
fail 'reinstall did not initialize a missing managed plugin selection'
|
||||
assert_contains "$missing_plugin_current_prefix/config/config.json" \
|
||||
'"webRoot": "./share/echoion/web"'
|
||||
sed -i 's#\./share/echoion/web#/srv/custom-echoion-web#' \
|
||||
"$missing_plugin_current_prefix/config/config.json"
|
||||
"$payload/install.sh" --mode portable --prefix "$missing_plugin_current_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
assert_contains "$missing_plugin_current_prefix/config/config.json" \
|
||||
'"webRoot": "/srv/custom-echoion-web"'
|
||||
"$missing_plugin_current_prefix/uninstall.sh" --purge --non-interactive >/dev/null
|
||||
assert_not_exists "$missing_plugin_current_prefix"
|
||||
|
||||
export SYSTEMCTL_FAIL_RESTART=1
|
||||
if "$upgrade_payload/install.sh" --mode portable --prefix "$rollback_prefix" \
|
||||
--register-service user --start --non-interactive >/dev/null 2>&1; then
|
||||
@@ -461,7 +819,14 @@ unset SYSTEMCTL_FAIL_RESTART
|
||||
restored_unit_hash=$(sha256sum -- "$unit")
|
||||
restored_unit_hash=${restored_unit_hash%% *}
|
||||
[[ $restored_unit_hash == "$old_unit_hash" ]] || fail 'failed upgrade did not restore unit bytes'
|
||||
restored_updater_helper_hash=$(sha256sum -- \
|
||||
"$rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
restored_updater_helper_hash=${restored_updater_helper_hash%% *}
|
||||
[[ $restored_updater_helper_hash == "$old_updater_helper_hash" ]] ||
|
||||
fail 'failed upgrade did not restore the privileged updater helper'
|
||||
assert_contains "$rollback_prefix/.echoion-install" 'version=1.2.3'
|
||||
assert_not_exists \
|
||||
"$rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
|
||||
"$rollback_prefix/uninstall.sh" --non-interactive >/dev/null
|
||||
|
||||
record_rollback_prefix=$TEST_ROOT/record-rollback
|
||||
@@ -473,6 +838,9 @@ record_old_install_hash=$(sha256sum -- "$record_rollback_prefix/install.sh")
|
||||
record_old_install_hash=${record_old_install_hash%% *}
|
||||
record_old_uninstall_hash=$(sha256sum -- "$record_rollback_prefix/uninstall.sh")
|
||||
record_old_uninstall_hash=${record_old_uninstall_hash%% *}
|
||||
record_old_updater_helper_hash=$(sha256sum -- \
|
||||
"$record_rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
record_old_updater_helper_hash=${record_old_updater_helper_hash%% *}
|
||||
export RECORD_COMMIT_FAIL=1
|
||||
if "$upgrade_payload/install.sh" --mode portable --prefix "$record_rollback_prefix" \
|
||||
--register-service user --non-interactive >/dev/null 2>&1; then
|
||||
@@ -487,6 +855,8 @@ record_restored_unit_hash=${record_restored_unit_hash%% *}
|
||||
fail 'record-commit failure did not restore unit bytes'
|
||||
assert_contains "$record_rollback_prefix/.echoion-install" 'version=1.2.3'
|
||||
assert_not_exists "$record_rollback_prefix/versions/1.2.4"
|
||||
assert_not_exists \
|
||||
"$record_rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
|
||||
record_restored_install_hash=$(sha256sum -- "$record_rollback_prefix/install.sh")
|
||||
record_restored_install_hash=${record_restored_install_hash%% *}
|
||||
record_restored_uninstall_hash=$(sha256sum -- "$record_rollback_prefix/uninstall.sh")
|
||||
@@ -495,6 +865,11 @@ record_restored_uninstall_hash=${record_restored_uninstall_hash%% *}
|
||||
fail 'record-commit failure did not restore installer helper bytes'
|
||||
[[ $record_restored_uninstall_hash == "$record_old_uninstall_hash" ]] ||
|
||||
fail 'record-commit failure did not restore uninstaller helper bytes'
|
||||
record_restored_updater_helper_hash=$(sha256sum -- \
|
||||
"$record_rollback_prefix/libexec/updater/1.2.3/bin/echoion-updater")
|
||||
record_restored_updater_helper_hash=${record_restored_updater_helper_hash%% *}
|
||||
[[ $record_restored_updater_helper_hash == "$record_old_updater_helper_hash" ]] ||
|
||||
fail 'record-commit failure did not restore privileged updater helper bytes'
|
||||
"$record_rollback_prefix/uninstall.sh" --non-interactive >/dev/null
|
||||
|
||||
scope_rollback_prefix=$TEST_ROOT/scope-rollback
|
||||
@@ -516,6 +891,8 @@ scope_restored_unit_hash=${scope_restored_unit_hash%% *}
|
||||
[[ $(readlink -- "$scope_rollback_prefix/current") == versions/1.2.3 ]] ||
|
||||
fail 'scope migration failure did not restore current'
|
||||
assert_contains "$scope_rollback_prefix/.echoion-install" 'service_scope=user'
|
||||
assert_not_exists \
|
||||
"$scope_rollback_prefix/state/plugins/.managed/url-shortener-internal/versions/1.1.0"
|
||||
"$scope_rollback_prefix/uninstall.sh" --non-interactive >/dev/null
|
||||
|
||||
tamper_prefix=$TEST_ROOT/tamper
|
||||
@@ -528,6 +905,27 @@ fi
|
||||
assert_file "$unit"
|
||||
rm -f -- "$unit"
|
||||
|
||||
helper_tamper_prefix=$TEST_ROOT/helper-tamper
|
||||
"$payload/install.sh" --mode portable --prefix "$helper_tamper_prefix" \
|
||||
--register-service none --non-interactive >/dev/null
|
||||
printf '# local change\n' >> \
|
||||
"$helper_tamper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
if "$helper_tamper_prefix/uninstall.sh" --non-interactive >/dev/null 2>&1; then
|
||||
fail 'uninstaller removed a modified privileged updater helper'
|
||||
fi
|
||||
assert_file "$helper_tamper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
|
||||
unrecognized_helper_prefix=$TEST_ROOT/unrecognized-helper
|
||||
install -d -- "$unrecognized_helper_prefix/libexec/updater/1.2.3/bin"
|
||||
printf '#!/bin/sh\nexit 0\n' > \
|
||||
"$unrecognized_helper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
chmod 0755 \
|
||||
"$unrecognized_helper_prefix/libexec/updater/1.2.3/bin/echoion-updater"
|
||||
if "$payload/install.sh" --mode portable --prefix "$unrecognized_helper_prefix" \
|
||||
--register-service none --non-interactive >/dev/null 2>&1; then
|
||||
fail 'installer overwrote an unrecognized privileged updater helper'
|
||||
fi
|
||||
|
||||
if "$payload/install.sh" --mode portable --prefix "/tmp/echoion-installer-test-$$" \
|
||||
--register-service user --non-interactive >/dev/null 2>&1; then
|
||||
fail 'temporary portable service prefix was accepted'
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# != 2 ]]; then
|
||||
echo "usage: $0 ECHOION_UPDATER SOURCE_ROOT" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
updater=$(realpath -e -- "$1")
|
||||
source_root=$(realpath -e -- "$2")
|
||||
temporary=$(mktemp -d "${TMPDIR:-/tmp}/echoion-updater-test.XXXXXX")
|
||||
trap 'rm -rf -- "$temporary"' EXIT
|
||||
root=$temporary/root
|
||||
stable_helper=$root/libexec/updater/installer/bin/echoion-updater
|
||||
mkdir -p "$root/versions" "$root/state" "$(dirname -- "$stable_helper")"
|
||||
install -m 0755 "$updater" "$stable_helper"
|
||||
stable_helper_sha=$(sha256sum "$stable_helper")
|
||||
stable_helper_sha=${stable_helper_sha%% *}
|
||||
|
||||
make_release() {
|
||||
local destination=$1
|
||||
local version=$2
|
||||
mkdir -p "$destination/bin" "$destination/lib" "$destination/service" \
|
||||
"$destination/share/echoion/web" "$destination/share/echoion/tools"
|
||||
install -m 0755 /bin/true "$destination/bin/echoiond"
|
||||
install -m 0755 "$updater" "$destination/bin/echoion-updater"
|
||||
printf 'core %s\n' "$version" >"$destination/lib/Echoion.ts"
|
||||
install -m 0644 "$source_root/packaging/service/echoion.service.in" \
|
||||
"$destination/service/echoion.service.in"
|
||||
install -m 0644 "$source_root/packaging/service/echoion-updater.service.in" \
|
||||
"$destination/service/echoion-updater.service.in"
|
||||
install -m 0644 "$source_root/packaging/service/echoion-updater.timer.in" \
|
||||
"$destination/service/echoion-updater.timer.in"
|
||||
install -m 0755 "$source_root/scripts/validate-release-manifest.py" \
|
||||
"$destination/share/echoion/tools/validate-release-manifest.py"
|
||||
printf '{}\n' >"$destination/share/echoion/config.example.json"
|
||||
printf '<!doctype html>\n' >"$destination/share/echoion/web/index.html"
|
||||
python3 "$source_root/scripts/generate-release-manifest.py" \
|
||||
--root "$destination" --version "$version"
|
||||
}
|
||||
|
||||
make_release "$root/versions/1.0.0" 1.0.0
|
||||
make_release "$root/versions/1.1.0" 1.1.0
|
||||
ln -s versions/1.1.0 "$root/current"
|
||||
cat >"$root/.echoion-install" <<EOF
|
||||
format=1
|
||||
prefix=$root
|
||||
version=1.1.0
|
||||
state_dir=$root/state
|
||||
EOF
|
||||
cat >"$root/install.json" <<EOF
|
||||
{"schemaVersion":1,"version":"1.1.0","stateDir":"$root/state"}
|
||||
EOF
|
||||
install -m 0644 /dev/null "$root/.update.lock"
|
||||
printf 'P 1.0.0\nH 1.0.0\nP 1.1.0\nH 1.1.0\n' >"$root/health.log"
|
||||
chmod 0644 "$root/health.log"
|
||||
|
||||
status=$("$updater" --root "$root" status --json)
|
||||
[[ $status == *'"current":"1.1.0"'* ]]
|
||||
[[ $status == *'"1.0.0"'* ]]
|
||||
|
||||
make_release "$root/versions/0.9.0" 0.9.0
|
||||
if "$updater" --root "$root" rollback-runtime --version 0.9.0 \
|
||||
--retain 2 >/dev/null 2>&1; then
|
||||
echo "updater accepted a runtime without durable healthy state" >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ $(readlink -- "$root/current") == versions/1.1.0 ]]
|
||||
rm -rf -- "$root/versions/0.9.0"
|
||||
|
||||
history_victim=$temporary/history-victim
|
||||
printf '%s\n' 'must remain unchanged' >"$history_victim"
|
||||
chmod 0600 "$history_victim"
|
||||
mkdir -p "$root/state/updates"
|
||||
ln -s "$history_victim" "$root/state/updates/history.jsonl"
|
||||
if "$updater" --root "$root" request rollback-runtime --version 1.0.0 \
|
||||
--retain 2 --origin test >/dev/null 2>&1; then
|
||||
echo "updater followed a symlink while opening privileged history" >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ $(<"$history_victim") == 'must remain unchanged' ]]
|
||||
[[ $(stat -c '%a' -- "$history_victim") == 600 ]]
|
||||
rm -- "$root/state/updates/history.jsonl"
|
||||
rm -f -- "$root/state/updates/privileged-requests/"*.json
|
||||
|
||||
queue_victim=$temporary/queue-victim
|
||||
mkdir "$queue_victim"
|
||||
mv "$root/state/updates/privileged-requests" \
|
||||
"$root/state/updates/privileged-requests.safe"
|
||||
ln -s "$queue_victim" "$root/state/updates/privileged-requests"
|
||||
if "$updater" --root "$root" request rollback-runtime --version 1.0.0 \
|
||||
--retain 2 --origin test >/dev/null 2>&1; then
|
||||
echo "updater accepted a symlinked privileged request directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ -z $(find "$queue_victim" -mindepth 1 -print -quit) ]]
|
||||
rm -- "$root/state/updates/privileged-requests"
|
||||
mv "$root/state/updates/privileged-requests.safe" \
|
||||
"$root/state/updates/privileged-requests"
|
||||
|
||||
if "$updater" --root "$root" check >/dev/null 2>&1 ||
|
||||
[[ -e $root/state/updates/requests ]]; then
|
||||
echo "updater still exposes the dead generic request queue" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if "$updater" --root "$root" request rollback-runtime \
|
||||
--version '../escape' --retain 2 >/dev/null 2>&1; then
|
||||
echo "updater accepted an unsafe request identifier" >&2
|
||||
exit 1
|
||||
fi
|
||||
if "$updater" --root "$root" request rollback-runtime \
|
||||
--version 1.0.0 --retain 0 >/dev/null 2>&1; then
|
||||
echo "updater accepted an out-of-range retention count" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
candidate=$root/state/updates/staged/runtime-1-2-0
|
||||
make_release "$candidate" 1.2.0
|
||||
# Candidate runtime code must never replace the stable privileged helper.
|
||||
install -m 0755 /bin/false "$candidate/bin/echoion-updater"
|
||||
python3 "$source_root/scripts/generate-release-manifest.py" \
|
||||
--root "$candidate" --version 1.2.0
|
||||
manifest_sha=$(sha256sum "$candidate/manifest.json")
|
||||
manifest_sha=${manifest_sha%% *}
|
||||
pending_victim=$temporary/pending-victim
|
||||
printf '%s\n' 'must remain unchanged' >"$pending_victim"
|
||||
ln -s "$pending_victim" "$root/state/updates/pending-runtime.json"
|
||||
privileged=$("$updater" --root "$root" request activate-runtime \
|
||||
--staging runtime-1-2-0 --version 1.2.0 \
|
||||
--manifest-sha256 "$manifest_sha" --retain 3 --origin test)
|
||||
[[ $privileged == "$root/state/updates/privileged-requests/"*.json ]]
|
||||
if "$updater" --root "$root" consume >/dev/null 2>&1; then
|
||||
echo "updater accepted a symlinked pending-runtime journal" >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ $(<"$pending_victim") == 'must remain unchanged' ]]
|
||||
[[ $(readlink -- "$root/current") == versions/1.1.0 ]]
|
||||
[[ -d $candidate ]]
|
||||
rm -- "$root/state/updates/pending-runtime.json"
|
||||
"$updater" --root "$root" consume >/dev/null
|
||||
[[ $(<"$pending_victim") == 'must remain unchanged' ]]
|
||||
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
|
||||
[[ ! -e $candidate ]]
|
||||
[[ $(sha256sum "$stable_helper") == "$stable_helper_sha "* ]]
|
||||
[[ $(sha256sum "$root/current/bin/echoion-updater") != "$stable_helper_sha "* ]]
|
||||
grep -F '"version": "1.2.0"' "$root/state/updates/activated-runtime.json" >/dev/null
|
||||
grep -F '"manifestPath": "versions/1.2.0/manifest.json"' \
|
||||
"$root/state/updates/activated-runtime.json" >/dev/null
|
||||
grep -F '"retainHealthyVersions": 3' \
|
||||
"$root/state/updates/activated-runtime.json" >/dev/null
|
||||
grep -F '"state": "pending"' "$root/state/updates/pending-runtime.json" >/dev/null
|
||||
grep -F '"retainHealthyVersions": 3' \
|
||||
"$root/state/updates/pending-runtime.json" >/dev/null
|
||||
grep -F 'version=1.2.0' "$root/.echoion-install" >/dev/null
|
||||
grep -F '"version":"1.2.0"' "$root/install.json" >/dev/null
|
||||
|
||||
rm -- "$root/state/updates/status.json"
|
||||
mkdir "$root/state/updates/status.json"
|
||||
"$updater" --root "$root" request commit-runtime --version 1.2.0 \
|
||||
--retain 3 --origin daemon >/dev/null
|
||||
"$updater" --root "$root" consume >/dev/null
|
||||
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
|
||||
[[ ! -e $root/state/updates/pending-runtime.json ]]
|
||||
[[ -f $root/state/updates/committed-runtime.json ]]
|
||||
grep -F '"state": "committed"' \
|
||||
"$root/state/updates/activated-runtime.json" >/dev/null
|
||||
grep -F 'H 1.2.0' "$root/health.log" >/dev/null
|
||||
[[ ! -e $root/staging ]]
|
||||
rmdir "$root/state/updates/status.json"
|
||||
|
||||
candidate=$root/state/updates/staged/runtime-1-3-0
|
||||
make_release "$candidate" 1.3.0
|
||||
manifest_sha=$(sha256sum "$candidate/manifest.json")
|
||||
manifest_sha=${manifest_sha%% *}
|
||||
"$updater" --root "$root" request activate-runtime \
|
||||
--staging runtime-1-3-0 --version 1.3.0 \
|
||||
--manifest-sha256 "$manifest_sha" --retain 3 --origin test >/dev/null
|
||||
"$updater" --root "$root" consume >/dev/null
|
||||
[[ $(readlink -- "$root/current") == versions/1.3.0 ]]
|
||||
[[ -f $root/state/updates/pending-runtime.json ]]
|
||||
|
||||
# A helper pass inside the durable health grace period must not race the
|
||||
# daemon's 30-second health confirmation.
|
||||
"$updater" --root "$root" consume >/dev/null
|
||||
[[ $(readlink -- "$root/current") == versions/1.3.0 ]]
|
||||
[[ -f $root/state/updates/pending-runtime.json ]]
|
||||
|
||||
# Once the durable deadline has expired, a pass with no matching confirmation
|
||||
# restores the previous version and records the failed candidate.
|
||||
sed -i 's/"activatedAt": "[^"]*"/"activatedAt": "2000-01-01T00:00:00Z"/' \
|
||||
"$root/state/updates/pending-runtime.json"
|
||||
"$updater" --root "$root" consume >/dev/null
|
||||
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
|
||||
[[ ! -e $root/state/updates/pending-runtime.json ]]
|
||||
grep -F '"version": "1.3.0"' \
|
||||
"$root/state/updates/failed-runtime.json" >/dev/null
|
||||
grep -F '"state": "rolled-back"' \
|
||||
"$root/state/updates/activated-runtime.json" >/dev/null
|
||||
grep -F 'F 1.3.0' "$root/health.log" >/dev/null
|
||||
[[ ! -e $root/versions/1.3.0 ]]
|
||||
|
||||
"$updater" --root "$root" request rollback-runtime --version 1.1.0 \
|
||||
--retain 3 --origin test >/dev/null
|
||||
"$updater" --root "$root" consume >/dev/null
|
||||
[[ $(readlink -- "$root/current") == versions/1.1.0 ]]
|
||||
grep -F '"version": "1.1.0"' "$root/state/updates/activated-runtime.json" >/dev/null
|
||||
|
||||
"$updater" --root "$root" rollback-runtime --version 1.0.0 \
|
||||
--retain 3 >/dev/null
|
||||
[[ $(readlink -- "$root/current") == versions/1.0.0 ]]
|
||||
grep -F '"operation":"rollback-runtime"' "$root/state/updates/history.jsonl" >/dev/null
|
||||
|
||||
if "$updater" --root "$root" rollback-runtime --version '../../tmp' \
|
||||
>/dev/null 2>&1; then
|
||||
echo "updater accepted an unsafe rollback target" >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ $(readlink -- "$root/current") == versions/1.0.0 ]]
|
||||
|
||||
"$updater" --root "$root" reconcile >/dev/null
|
||||
grep -F '"current": "1.0.0"' "$root/state/updates/status.json" >/dev/null
|
||||
[[ $(sha256sum "$stable_helper") == "$stable_helper_sha "* ]]
|
||||
|
||||
# Retention is evaluated only after a committed health confirmation or an
|
||||
# explicit validated rollback. Active plus one previous healthy version is
|
||||
# retained; known failed and older healthy versions are eligible for pruning.
|
||||
"$updater" --root "$root" rollback-runtime --version 1.2.0 \
|
||||
--retain 1 >/dev/null
|
||||
[[ $(readlink -- "$root/current") == versions/1.2.0 ]]
|
||||
[[ -d $root/versions/1.0.0 ]]
|
||||
[[ ! -e $root/versions/1.1.0 ]]
|
||||
[[ ! -e $root/versions/1.3.0 ]]
|
||||
[[ ! -e $root/staging ]]
|
||||
|
||||
echo "updater lifecycle tests passed"
|
||||
Reference in new issue
Block a user