fix(admin): reject account creation outside Recovery

This commit is contained in:
2026-10-30 03:53:32 -03:00
parent 61e49f4880
commit c9f0549591
3 changed files with 41 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env bats
@test "admin rejects normal mode before resolving a target volume" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
run bash -u -c '
source <(sed '\''/^main "\$@"$/d'\'' "$1")
is_recovery() { return 1; }
resolve_data_volume() { echo TARGET_WAS_ACCESSED; }
admin_only_mode() { echo ADMIN_FLOW_WAS_STARTED; }
cmd_admin
' "$script" "$script"
[ "$status" -ne 0 ]
[[ "$output" == *"Admin creation must run from Recovery mode"* ]]
[[ "$output" != *"TARGET_WAS_ACCESSED"* ]]
[[ "$output" != *"ADMIN_FLOW_WAS_STARTED"* ]]
done
}
@test "admin dry run returns before accessing account or enrollment state" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
run bash -u -c '
source <(sed '\''/^main "\$@"$/d'\'' "$1")
DRY_RUN=true
dscl_node() { echo ACCOUNT_STATE_WAS_ACCESSED; return 1; }
admin_only_mode "/mock/Data volume"
' "$script" "$script"
[ "$status" -eq 0 ]
[[ "$output" == *"[DRY RUN] Would create a local admin user"* ]]
[[ "$output" != *"ACCOUNT_STATE_WAS_ACCESSED"* ]]
done
}
+3
View File
@@ -200,6 +200,9 @@ cmd_backup() {
}
cmd_admin() {
if ! is_recovery; then
error_exit "Admin creation must run from Recovery mode."
fi
header "Create Local Admin User"
local data_mount
data_mount=$(resolve_data_volume)
+3
View File
@@ -2856,6 +2856,9 @@ cmd_suppress() {
}
cmd_admin() {
if ! is_recovery; then
error_exit "Admin creation must run from Recovery mode."
fi
header "Create Local Admin User"
local data_mount
data_mount=$(resolve_data_volume)