Merge remote-tracking branch 'origin/main' into integrate/pr13

This commit is contained in:
2026-10-30 11:13:55 -03:00
48 changed files with 1361 additions and 343 deletions
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/env python3
"""Inert macOS command fixtures; mutable plist operations stay in the suite root."""
import json
import os
import pathlib
import plistlib
import shlex
import subprocess
import sys
name = pathlib.Path(sys.argv[0]).name
args = sys.argv[1:]
root = pathlib.Path(os.environ["UNLEASH_TEST_ROOT"]).resolve()
with (root / "platform-calls.jsonl").open("a") as log:
log.write(json.dumps([name, *args]) + "\n")
def fixture_path(value):
path = pathlib.Path(value).resolve()
active_test = pathlib.Path(os.environ["BATS_TEST_TMPDIR"]).resolve()
if not (path.is_relative_to(root) or path.is_relative_to(active_test)):
sys.exit(f"Fixture refused path outside the suite: {path}")
return path
if name == "sudo":
if len(args) >= 2 and ((args[0] == "profiles" and args[1] in ("-C", "status"))
or (args[0] == "security" and args[1] == "find-identity")):
sys.exit(subprocess.call([str(pathlib.Path(sys.argv[0]).with_name(args[0])), *args[1:]]))
elif name == "profiles":
if args[:1] == ["-C"]:
sys.stdout.buffer.write(plistlib.dumps([]))
sys.exit(0)
if args[:1] == ["status"]:
print("MDM enrollment: No")
sys.exit(0)
elif name == "security" and args[:1] == ["find-identity"]:
sys.exit(0)
elif name == "plutil" and args[:4] == ["-convert", "xml1", "-o", "-"]:
sys.stdout.buffer.write(plistlib.dumps(plistlib.loads(fixture_path(args[-1]).read_bytes())))
sys.exit(0)
elif name == "PlistBuddy":
path = fixture_path(args[-1])
data = plistlib.loads(path.read_bytes())
command = shlex.split(args[1])
action = command[0]
key = command[1].lstrip(":") if len(command) > 1 else None
if action == "Print":
if key:
print(str(data[key]).lower())
else:
sys.stdout.buffer.write(plistlib.dumps(data))
sys.exit(0)
if action == "Add" and key in data:
sys.exit(1)
if action == "Set" and key not in data:
sys.exit(1)
if action in ("Add", "Set"):
data[key] = command[-1] == "true"
elif action == "Delete":
data.pop(key, None)
else:
sys.exit(97)
path.write_bytes(plistlib.dumps(data))
sys.exit(0)
elif name == "launchctl" and args[:1] in (["load"], ["unload"]):
fixture_path(args[-1])
sys.exit(0)
elif name == "host" and args[:2] == ["-t", "a"]:
print(f"{args[2]} has address 203.0.113.10")
sys.exit(0)
elif name == "dscl":
fixture_path(args[1])
sys.exit(1)
elif name in ("diskutil", "pgrep", "pkill", "curl", "pfctl", "host"):
sys.exit(1)
print(f"Blocked platform operation in test: {name} {' '.join(args)}", file=sys.stderr)
sys.exit(97)
+20
View File
@@ -0,0 +1,20 @@
setup_suite() {
local suite_dir
suite_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export UNLEASH_TEST_ROOT="$BATS_SUITE_TMPDIR"
export TMPDIR="$UNLEASH_TEST_ROOT/tmp"
local mock_bin="$UNLEASH_TEST_ROOT/bin"
mkdir -p "$TMPDIR" "$mock_bin"
local tool
for tool in sudo diskutil profiles security launchctl pfctl pkill pgrep killall \
dscacheutil defaults curl host plutil PlistBuddy dscl fdesetup chflags \
osascript ioreg ifconfig systemextensionsctl networksetup; do
cp "$suite_dir/helpers/platform.py" "$mock_bin/$tool"
chmod +x "$mock_bin/$tool"
done
export PATH="$mock_bin:$PATH"
export PB="$mock_bin/PlistBuddy"
export VERSION=2.0.0
export SCRIPT_DIR="$suite_dir/.."
export LIB_DIR="$SCRIPT_DIR/lib"
}
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env bats
run_cli() {
local script="$1"; shift
local definitions="$BATS_TEST_TMPDIR/${script##*/}.functions"
sed '/^main "\$@"$/d' "$script" > "$definitions"
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
source "$1"
shift
load_config() { :; }
is_root() { return 1; }
is_recovery() { return 1; }
cmd_interactive_normal() { printf "interactive verbose=%s\n" "$VERBOSE"; }
main "$@"
' "$script" "$definitions" "$@"
}
run_capture() {
local script="$1"; shift
local definitions="$BATS_TEST_TMPDIR/${script##*/}.functions"
sed '/^main "\$@"$/d' "$script" > "$definitions"
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
source "$1"
shift
load_config() { :; }
cmd_config() {
printf "dry=%s verbose=%s log=<%s>\nargc=%s\n" "$DRY_RUN" "$VERBOSE" "$LOG_FILE" "$#"
printf "<%s>\n" "$@"
}
main "$@"
' "$script" "$definitions" "$@"
}
@test "optional CLI arguments reach usage or privilege guards under nounset" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
run_cli "$script" audit
[ "$status" -ne 0 ]; [[ "$output" == *"Audit needs sudo"* ]]
run_cli "$script" --log-file
[ "$status" -ne 0 ]; [[ "$output" == *"--log-file requires a path"* ]]
run_cli "$script" monitor --webhook
[ "$status" -ne 0 ]; [[ "$output" == *"--webhook requires a URL"* ]]
run_cli "$script" config set
[ "$status" -ne 0 ]; [[ "$output" == *"Usage: ./unleash config set KEY VALUE"* ]]
run_cli "$script" config unset
[ "$status" -ne 0 ]; [[ "$output" == *"Usage: ./unleash config unset KEY"* ]]
done
}
@test "CLI values retain spaces quotes empty strings and literal shell syntax" {
local entrypoint value
for entrypoint in unleash unleash-standalone.sh; do
for value in 'a b $(printf injected) "quoted"' ''; do
run_capture "$BATS_TEST_DIRNAME/../$entrypoint" config set LOG_FILE "$value"
[ "$status" -eq 0 ]
local expected
expected=$(printf 'dry=false verbose=false log=<>\nargc=4\n<config>\n<set>\n<LOG_FILE>\n<%s>' "$value")
[ "$output" = "$expected" ]
done
done
}
@test "global flags around the command persist in the command shell" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
run_capture "$BATS_TEST_DIRNAME/../$entrypoint" --dry-run config --verbose set LOG_FILE value --log-file 'a b.log'
[ "$status" -eq 0 ]
[[ "$output" == 'dry=true verbose=true log=<a b.log>'* ]]
[[ "$output" == *'argc=4'* ]]
done
}
@test "global flags without a command preserve an empty argument list" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
run_cli "$BATS_TEST_DIRNAME/../$entrypoint" --verbose
[ "$status" -eq 0 ]
[ "$output" = 'interactive verbose=true' ]
done
}
@test "CLI option terminator preserves values that look like global options" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
run_capture "$BATS_TEST_DIRNAME/../$entrypoint" config set LOG_LEVEL -- --verbose
[ "$status" -eq 0 ]
[[ "$output" == 'dry=false verbose=false log=<>'* ]]
[[ "$output" == *'<--verbose>' ]]
done
}
@test "log-file rejects an empty path or another option as its missing value" {
local entrypoint value
for entrypoint in unleash unleash-standalone.sh; do
for value in '' --dry-run; do
run_cli "$BATS_TEST_DIRNAME/../$entrypoint" --log-file "$value" version
[ "$status" -ne 0 ]
[[ "$output" == *"--log-file requires a path"* ]]
done
done
}
+6
View File
@@ -19,3 +19,9 @@ setup() {
run run_preformat_check 2>/dev/null || true
echo "$output" | grep -qiE "safe|mdm"
}
@test "pre-format checks handle zero profiles without arithmetic diagnostics" {
run run_preformat_check
[ "$status" -eq 0 ]
[[ ! "$output" =~ integer.*expected ]]
}
+38
View File
@@ -2,6 +2,7 @@
# Tests for colors.sh - run with: bats tests/test_colors.bats
setup() {
bats_require_minimum_version 1.5.0
load '../lib/colors.sh'
TEST_LOG=$(mktemp)
}
@@ -39,3 +40,40 @@ teardown() {
[ "$status" -eq 0 ]
echo "$output" | grep -q "Test Title"
}
@test "header draws a valid Unicode border for the title width" {
run header Mac
[ "$status" -eq 0 ]
[[ "$output" == *"╔═══════╗"* ]]
[[ "$output" == *"╚═══════╝"* ]]
}
@test "diagnostics use stderr without contaminating helper return values" {
local source_file
for source_file in lib/colors.sh unleash-standalone.sh; do
run --separate-stderr bash -u -c '
source <(sed "/^error_exit()/,\$d" "$1")
volume_path() {
log INFO "Locating Data volume"
log OK "Data volume found"
printf "%s\n" "/Volumes/Work Data"
}
result=$(volume_path)
printf "%s\n" "$result"
' bash "$BATS_TEST_DIRNAME/../$source_file"
[ "$status" -eq 0 ]
[ "$output" = "/Volumes/Work Data" ]
[[ "$stderr" == *"Locating Data volume"* ]]
[[ "$stderr" == *"Data volume found"* ]]
done
}
@test "diagnostics still reach the log file when stdout is captured" {
LOG_FILE="$TEST_LOG"
local result
result=$(log WARN "Review the selected volume" 2>/dev/null)
[ -z "$result" ]
grep -q 'Review the selected volume' "$TEST_LOG"
}
+19
View File
@@ -35,3 +35,22 @@ teardown() {
run grep -c "KEY=new" "$CONFIG_FILE"
[ "$output" -eq 1 ]
}
@test "config preserves spaces and literal replacement characters" {
local value='/tmp/Unleash logs/quoted "name" & \tail'
save_config LOG_FILE old
save_config LOG_FILE "$value"
LOG_FILE=''
load_config
[ "$LOG_FILE" = "$value" ]
}
@test "config unset preserves other keys" {
save_config WEBHOOK 'https://example.com/a?x=1&y=2'
save_config LOG_LEVEL verbose
run cmd_config config unset LOG_LEVEL
[ "$status" -eq 0 ]
run grep -c '^LOG_LEVEL=' "$CONFIG_FILE"
[ "$status" -eq 1 ]
grep -q '^WEBHOOK=https://example.com/a?x=1&y=2$' "$CONFIG_FILE"
}
+10 -10
View File
@@ -5,14 +5,11 @@ setup() {
load '../lib/detect.sh'
}
@test "is_root returns true when EUID is 0" {
[ "$EUID" -eq 0 ] && skip "Already root"
[ "$EUID" -ne 0 ] && skip "Not root"
}
@test "is_root returns false when EUID is not 0" {
[ "$EUID" -ne 0 ] && skip "Not root (expected)"
[ "$EUID" -eq 0 ] && skip "Is root"
@test "is_root reports whether the effective user is root" {
local expected=1
[ "$EUID" -ne 0 ] || expected=0
run is_root
[ "$status" -eq "$expected" ]
}
@test "is_recovery returns false in normal environment" {
@@ -26,6 +23,9 @@ setup() {
}
@test "resolve_data_volume errors on non-existent device" {
run resolve_data_volume 2>/dev/null || true
[ "$status" -eq 0 ]
read() { echo PROMPT_WAS_REACHED; return 1; }
run resolve_data_volume </dev/null
[ "$status" -ne 0 ]
[[ "$output" == *"Cannot select a Data volume without a terminal"* ]]
[[ "$output" != *"PROMPT_WAS_REACHED"* ]]
}
+56
View File
@@ -18,3 +18,59 @@ setup() {
LIB_DIR="$old_dir"
echo "$output" | grep -qi "missing\|error"
}
@test "network doctor reports build power and link using only read commands" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local definitions="$BATS_TEST_TMPDIR/$entrypoint.functions"
local calls="$BATS_TEST_TMPDIR/$entrypoint.calls"
sed '/^main "\$@"$/d' "$script" > "$definitions"
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
source "$1"
calls="$2"
load_config() { :; }
sw_vers() {
echo "sw_vers $*" >> "$calls"
case "$1" in -productVersion) echo 27.0 ;; -buildVersion) echo TESTBUILD ;; *) return 97 ;; esac
}
networksetup() {
echo "networksetup $*" >> "$calls"
case "$*" in
-listallhardwareports) printf "Hardware Port: Ethernet\nDevice: en0\nHardware Port: Wi-Fi\nDevice: en7\nEthernet Address: PRIVATE-MAC\n" ;;
"-getairportpower en7") echo "Wi-Fi Power (en7): On" ;;
*) return 97 ;;
esac
}
ifconfig() {
echo "ifconfig $*" >> "$calls"
[ "$*" = en7 ] || return 97
printf "en7: flags\n ether PRIVATE-MAC\n status: inactive\n"
}
main doctor --network
' "$script" "$definitions" "$calls"
[ "$status" -eq 0 ]
[[ "$output" == *"27.0 (build TESTBUILD)"* ]]
[[ "$output" == *"Wi-Fi interface: en7"* ]]
[[ "$output" == *"Wi-Fi power: on"* ]]
[[ "$output" == *"Link status: inactive"* ]]
[[ "$output" != *"PRIVATE-MAC"* ]]
run grep -vE '^(sw_vers -(productVersion|buildVersion)|networksetup -listallhardwareports|networksetup -getairportpower en7|ifconfig en7)$' "$calls"
[ "$status" -eq 1 ]
done
}
@test "standalone doctor verifies embedded modules without a lib directory" {
local script="$BATS_TEST_DIRNAME/../unleash-standalone.sh"
local definitions="$BATS_TEST_TMPDIR/standalone.functions"
sed '/^main "\$@"$/d' "$script" > "$definitions"
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
unset LIB_DIR
source "$1"
load_config() { :; }
main doctor
' "$script" "$definitions"
[ "$status" -eq 0 ]
[[ "$output" == *"Embedded core modules loaded"* ]]
[[ "$output" != *"unbound variable"* ]]
}
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bats
@test "dualboot dry run returns before target access with or without root" {
local entrypoint root_status
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local definitions="$BATS_TEST_TMPDIR/$entrypoint.functions"
sed '/^main "\$@"$/d' "$script" > "$definitions"
for root_status in 0 1; do
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
source "$1"
root_status="$2"
load_config() { :; }
is_root() { return "$root_status"; }
resolve_target_volumes() { echo TARGET_WAS_ACCESSED; return 97; }
create_admin_user() { echo USER_WAS_WRITTEN; return 97; }
main --dry-run dualboot
' "$script" "$definitions" "$root_status"
[ "$status" -eq 0 ]
[[ "$output" == *"[DRY RUN] Would select an external macOS installation"* ]]
[[ "$output" != *"TARGET_WAS_ACCESSED"* ]]
[[ "$output" != *"USER_WAS_WRITTEN"* ]]
done
done
}
+15 -1
View File
@@ -6,11 +6,25 @@ setup() {
}
@test "harden_live_os exits cleanly" {
run harden_live_os 2>/dev/null || true
mkdir -p "$BATS_TEST_TMPDIR/Users/test/Library/LaunchAgents"
local agents="$BATS_TEST_TMPDIR/Users/test/Library/LaunchAgents"
echo mdm > "$agents/enrollment.plist"
echo normal > "$agents/normal.plist"
run harden_live_os "$BATS_TEST_TMPDIR"
[ "$status" -eq 0 ]
[ ! -f "$agents/enrollment.plist" ]
[ -f "$agents/normal.plist" ]
}
@test "harden_status exits cleanly" {
run harden_status 2>/dev/null || true
[ "$status" -eq 0 ]
}
@test "hardening keeps profile queries on stdout" {
local calls="$BATS_TEST_TMPDIR/profile-calls"
profiles() { printf '%s\n' "$*" > "$calls"; echo '<plist><array/></plist>'; }
run harden_live_os "$BATS_TEST_TMPDIR"
[ "$status" -eq 0 ]
[ "$(cat "$calls")" = '-C -output stdout-xml' ]
}
+4 -2
View File
@@ -6,11 +6,13 @@ setup() {
}
@test "show_history exits cleanly with no logs" {
run show_history 2>/dev/null || true
run show_history "$BATS_TEST_TMPDIR"
[ "$status" -eq 0 ]
}
@test "clear_history does not error with no logs" {
run clear_history 2>/dev/null || true
echo event > "$BATS_TEST_TMPDIR/unleash-monitor.log"
run clear_history "$BATS_TEST_TMPDIR"
[ "$status" -eq 0 ]
[ ! -s "$BATS_TEST_TMPDIR/unleash-monitor.log" ]
}
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bats
setup() {
PROJECT="$BATS_TEST_TMPDIR/project"
mkdir -p "$PROJECT/scripts" "$PROJECT/lib"
cp "$BATS_TEST_DIRNAME/../scripts/check-shell.py" "$PROJECT/scripts/"
cat > "$PROJECT/unleash" <<'SH'
#!/bin/bash
for _lib in sample; do
source "lib/$_lib.sh"
done
sample
SH
printf 'sample() { :; }\n' > "$PROJECT/lib/sample.sh"
printf '#!/bin/bash\n' > "$PROJECT/unleash-standalone.sh"
}
@test "lint reports sourced module findings without executing the application" {
export LINT_TEST_MARKER="$BATS_TEST_TMPDIR/app-executed"
printf 'sample() { echo $missing; }\n: > "$LINT_TEST_MARKER"\n' > "$PROJECT/lib/sample.sh"
run python3 "$PROJECT/scripts/check-shell.py"
[ "$status" -ne 0 ]
[[ "$output" == *"lib/sample.sh:1:"* ]]
[[ "$output" == *"SC2086"* ]]
[ ! -f "$LINT_TEST_MARKER" ]
}
@test "lint checks syntax in every library" {
printf 'sample() {\n' > "$PROJECT/lib/sample.sh"
run python3 "$PROJECT/scripts/check-shell.py"
[ "$status" -ne 0 ]
[[ "$output" == *"sample.sh"* ]]
}
@test "lint does not install tools after an analysis failure" {
cp "$BATS_TEST_DIRNAME/../Makefile" "$PROJECT/Makefile"
local mock_bin="$BATS_TEST_TMPDIR/lint-bin"
mkdir -p "$mock_bin"
ln -s "$(command -v python3)" "$mock_bin/python3"
ln -s "$(command -v bash)" "$mock_bin/bash"
printf '#!/bin/sh\nprintf "[]"\nexit 1\n' > "$mock_bin/shellcheck"
export TEST_BREW_MARKER="$BATS_TEST_TMPDIR/brew-called"
printf '#!/bin/sh\n: > "$TEST_BREW_MARKER"\n' > "$mock_bin/brew"
chmod +x "$mock_bin/shellcheck" "$mock_bin/brew"
run env PATH="$mock_bin" "$(command -v make)" -C "$PROJECT" lint
[ "$status" -ne 0 ]
[ ! -f "$TEST_BREW_MARKER" ]
}
+14 -2
View File
@@ -3,14 +3,26 @@
setup() {
load '../lib/colors.sh'
load '../lib/ma_detect.sh'
mkdir -p "$BATS_TEST_TMPDIR/Users"
}
@test "detect_migration_assistant exits cleanly" {
run detect_migration_assistant 2>/dev/null || true
run detect_migration_assistant "$BATS_TEST_TMPDIR"
[ "$status" -eq 0 ]
}
@test "clean_ma_artifacts does not error without users" {
run clean_ma_artifacts 2>/dev/null || true
run clean_ma_artifacts "$BATS_TEST_TMPDIR"
[ "$status" -eq 0 ]
}
@test "migration audit detects enrollment and MDM cache directories" {
local caches="$BATS_TEST_TMPDIR/Users/test/Library/Caches"
mkdir -p "$caches/com.apple.enrollmenttool" "$caches/com.apple.mdm"
echo cached > "$caches/com.apple.enrollmenttool/record"
echo cached > "$caches/com.apple.mdm/record"
run detect_migration_assistant "$BATS_TEST_TMPDIR"
[ "$status" -eq 1 ]
[[ "$output" == *"enrollment cache files"* ]]
[[ "$output" == *"MDM cache files"* ]]
}
+4 -2
View File
@@ -2,8 +2,10 @@
setup() {
load '../lib/colors.sh'
load '../lib/launchd.sh'
load '../lib/monitor.sh'
TEST_DIR=$(mktemp -d)
SCRIPT_PATH="$TEST_DIR/unleash"
}
teardown() {
@@ -11,12 +13,12 @@ teardown() {
}
@test "monitor_status exits cleanly when not running" {
run monitor_status 2>/dev/null || true
run monitor_status "$TEST_DIR/monitor.pid"
[ "$status" -eq 0 ]
}
@test "stop_monitor exits cleanly when not running" {
run stop_monitor 2>/dev/null || true
run stop_monitor "$TEST_DIR/monitor.pid"
[ "$status" -eq 0 ]
}
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bats
check_daemon_path() {
local installer="$1" action="$2" label="$3"
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local folder="$BATS_TEST_TMPDIR/$entrypoint/Tool Folder & <profile> \"quoted\""
local target="$BATS_TEST_TMPDIR/$entrypoint/Target"
local script="$folder/renamed standalone.sh"
local definitions="$BATS_TEST_TMPDIR/$entrypoint.functions"
mkdir -p "$folder" "$target/Library"
printf '#!/bin/bash\nprintf "ACTION=%%s\\n" "$1"\n' > "$script"
if [ "$entrypoint" = unleash ]; then
ln -s "$BATS_TEST_DIRNAME/../lib" "$folder/lib"
fi
sed '/^main "\$@"$/d' "$BATS_TEST_DIRNAME/../$entrypoint" > "$definitions"
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
unset SCRIPT_DIR SCRIPT_PATH
source "$1"
expected="$2/Library/LaunchDaemons"
mkdir() {
[ "$#" -eq 2 ] && [ "$1" = -p ] && [ "$2" = "$expected" ] || return 97
command mkdir "$@"
}
"$3" "$2"
' "$script" "$definitions" "$target" "$installer"
[ "$status" -eq 0 ]
run python3 - "$target/Library/LaunchDaemons/$label.plist" "$script" "$action" <<'PY'
import plistlib,subprocess,sys
with open(sys.argv[1],'rb') as source:
data=plistlib.load(source)
expected=['/bin/bash',sys.argv[2],sys.argv[3]]
assert data['ProgramArguments']==expected, data['ProgramArguments']
result=subprocess.run(expected,capture_output=True,text=True,timeout=5)
assert result.returncode==0, result.stderr
assert result.stdout=='ACTION='+sys.argv[3]+'\n', result.stdout
PY
[ "$status" -eq 0 ]
done
}
@test "persistence invokes renamed scripts with spaces and XML text literally" {
check_daemon_path install_persist_launchdaemon heal com.unleash.heal
}
@test "monitor invokes renamed scripts with spaces and XML text literally" {
check_daemon_path install_monitor_launchdaemon monitor com.unleash.monitor
}
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bats
@test "Recovery download runs without a library directory" {
local repo="$BATS_TEST_DIRNAME/.." artifact target="$BATS_TEST_TMPDIR/recovery"
artifact=$(sed -n 's|^curl -L https://raw.githubusercontent.com/mateussiqueira/unleash/main/\([^ ]*\) -o /tmp/unleash$|\1|p' "$repo/README.md")
[ -n "$artifact" ]
mkdir -p "$target"
cp "$repo/$artifact" "$target/unleash"
run env HOME="$target" XDG_CONFIG_HOME="$target/config" bash "$target/unleash" version
[ "$status" -eq 0 ]
[[ "$output" == *"unleash"* ]]
[ ! -d "$target/lib" ]
}
+90
View File
@@ -0,0 +1,90 @@
#!/usr/bin/env bats
suppress_fixture() {
local script="$1" target="$2"
local action="${3:-suppress_enrollment}" simulation="${4:-false}"
run bash -u -c '
source <(sed '\''/^main "\$@"$/d'\'' "$1")
DRY_RUN="$4"
"$3" "$2"
' "$script" "$script" "$target" "$action" "$simulation"
[ "$status" -eq 0 ]
}
@test "heal repairs old Rosetta blocks even when suppression is otherwise intact" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local target="$BATS_TEST_TMPDIR/$entrypoint" hosts
hosts="$target/private/etc/hosts"
suppress_fixture "$script" "$target"
printf '0.0.0.0 configuration.apple.com\n:: configuration.apple.com\n' >> "$hosts"
suppress_fixture "$script" "$target" heal_suppress
run grep -q 'configuration[.]apple[.]com' "$hosts"
[ "$status" -eq 1 ]
done
}
@test "heal dry run preserves old Rosetta entries" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local target="$BATS_TEST_TMPDIR/$entrypoint" hosts
hosts="$target/private/etc/hosts"
suppress_fixture "$script" "$target"
printf '0.0.0.0 configuration.apple.com\n:: configuration.apple.com\n' >> "$hosts"
cp "$hosts" "$target/original"
suppress_fixture "$script" "$target" heal_suppress true
cmp "$target/original" "$hosts"
[ ! -e "$hosts.unleash-rosetta.bak" ]
done
}
@test "suppression does not add hosts blocks for Rosetta configuration" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local target="$BATS_TEST_TMPDIR/$entrypoint"
mkdir -p "$target/private/etc"
printf '127.0.0.1 localhost\n' > "$target/private/etc/hosts"
suppress_fixture "$script" "$target"
run grep -q 'configuration[.]apple[.]com' "$target/private/etc/hosts"
[ "$status" -eq 1 ]
grep -q '^127.0.0.1 localhost$' "$target/private/etc/hosts"
done
}
@test "suppression repairs its old Rosetta blocks with an unchanged backup on rerun" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local target="$BATS_TEST_TMPDIR/$entrypoint" hosts
hosts="$target/private/etc/hosts"
mkdir -p "$(dirname "$hosts")"
printf '127.0.0.1 localhost\n# Added by unleash — DEP enrollment block\n0.0.0.0 configuration.apple.com\n:: configuration.apple.com\n' > "$hosts"
cp "$hosts" "$target/original"
suppress_fixture "$script" "$target"
run grep -q 'configuration[.]apple[.]com' "$hosts"
[ "$status" -eq 1 ]
cmp "$target/original" "$hosts.unleash-rosetta.bak"
cp "$hosts" "$target/repaired"
suppress_fixture "$script" "$target"
cmp "$target/repaired" "$hosts"
cmp "$target/original" "$hosts.unleash-rosetta.bak"
done
}
@test "suppression preserves Rosetta blocks outside its generated section" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local target="$BATS_TEST_TMPDIR/$entrypoint" hosts
hosts="$target/private/etc/hosts"
mkdir -p "$(dirname "$hosts")"
printf '0.0.0.0 configuration.apple.com\n:: configuration.apple.com manual.alias\n' > "$hosts"
suppress_fixture "$script" "$target"
grep -Fxq '0.0.0.0 configuration.apple.com' "$hosts"
grep -Fxq ':: configuration.apple.com manual.alias' "$hosts"
[ ! -e "$hosts.unleash-rosetta.bak" ]
done
}
+44
View File
@@ -26,3 +26,47 @@ teardown() {
run deep_status_json 2>/dev/null || true
echo "$output" | grep -q "}"
}
@test "deep_status_json counts a single matching process without subtracting it" {
profiles() {
if [ "$1" = -C ]; then echo '<key>ProfileDisplayName</key>';
else echo 'MDM enrollment: No'; fi
}
sudo() { "$@"; }
pgrep() { echo '42 mdmclient'; }
ps() { echo 'test 42 0.0 0.0 1 1 ? S 00:00 0:00 mdmclient'; }
run deep_status_json
[ "$status" -eq 0 ]
echo "$output" | python3 -c 'import json,sys; assert json.load(sys.stdin)["running_mdm_processes"] == 1'
}
@test "text audit completes with zero profiles under nounset" {
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
source "$1/lib/colors.sh"
source "$1/lib/status.sh"
pf_status() { :; }
deep_status
' bash "$BATS_TEST_DIRNAME/.."
[ "$status" -eq 0 ]
[[ "$output" == *"Risk:"* ]]
[[ ! "$output" =~ integer.*expected ]]
}
@test "audit and report JSON contain numeric zero counts under nounset" {
local module function_name field
for module in status report; do
if [ "$module" = status ]; then function_name=deep_status_json; field=profile_count;
else function_name=generate_report_json; field=installed_profiles; fi
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
source "$1/lib/colors.sh"
source "$1/lib/$2.sh"
grep() {
if [ "${1:-}" = -c ] && [ "${3:-}" = /private/etc/hosts ]; then echo 0; return 1; fi
command grep "$@"
}
"$3"
' bash "$BATS_TEST_DIRNAME/.." "$module" "$function_name"
[ "$status" -eq 0 ]
echo "$output" | python3 -c 'import json,sys; data=json.load(sys.stdin); assert data[sys.argv[1]] == 0; assert data.get("hosts_blocked",0) == 0' "$field"
done
}
+8 -1
View File
@@ -34,14 +34,21 @@ teardown() {
}
@test "suppress_enrollment disables daemons" {
TEST_DIR="$BATS_TEST_TMPDIR/volume"
DRY_RUN=false
suppress_enrollment "$TEST_DIR" 2>/dev/null || true
local ldp="$TEST_DIR/private/var/db/com.apple.xpc.launchd/disabled.plist"
[ -f "$ldp" ]
run /usr/libexec/PlistBuddy -c "Print :com.apple.ManagedClient.enroll" "$ldp" 2>/dev/null
run "$PB" -c "Print :com.apple.ManagedClient.enroll" "$ldp"
[ "$output" = "true" ]
}
@test "PlistBuddy fixture rejects writes outside the test suite" {
run "$PB" -c 'Add :test bool true' "$BATS_TEST_DIRNAME/../README.md"
[ "$status" -ne 0 ]
[[ "$output" == *"Fixture refused path outside the suite"* ]]
}
@test "dry-run mode does not write files" {
DRY_RUN=true
suppress_enrollment "$TEST_DIR" 2>/dev/null || true
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bats
check_volume_output() {
local mode="$1" entrypoint
bats_require_minimum_version 1.5.0
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local target="$BATS_TEST_TMPDIR/$entrypoint/Data volume"
mkdir -p "$target/private/var/db/dslocal/nodes/Default"
run --separate-stderr bash -u -c '
source <(sed '\''/^main "\$@"$/d'\'' "$1")
target="$2"; mode="$3"; mounted="$4"
diskutil() {
case "$*" in
"apfs list") echo "+-- Volume disk5s1 (Data)" ;;
"info /dev/disk5s1")
if [ -f "$mounted" ]; then printf "Mount Point: %s\n" "$target";
else echo "Mount Point: Not mounted"; fi ;;
"mount /dev/disk5s1")
echo "Mount attempt diagnostic"
[ "$mode" != locked ] || return 1
touch "$mounted" ;;
"apfs unlockVolume /dev/disk5s1")
echo "Unlocking any cryptographic user"
echo "Unlocked and mounted APFS Volume"
touch "$mounted" ;;
*) return 1 ;;
esac
}
resolve_data_volume
' "$script" "$script" "$target" "$mode" "$BATS_TEST_TMPDIR/$entrypoint.mounted"
[ "$status" -eq 0 ]
[ "$output" = "$target" ]
[[ "$stderr" == *"Mount attempt diagnostic"* ]]
if [ "$mode" = locked ]; then
[[ "$stderr" == *"Unlocked and mounted APFS Volume"* ]]
fi
done
}
@test "mount diagnostics stay out of the selected Data volume path" {
check_volume_output unmounted
}
@test "FileVault unlock diagnostics stay out of the selected Data volume path" {
check_volume_output locked
}