fix(suppress): tolerate absent activation metadata

Allow absent optional activation metadata during suppression
This commit is contained in:
2026-10-30 11:28:50 -03:00
3 changed files with 52 additions and 4 deletions
+2 -2
View File
@@ -47,9 +47,9 @@ suppress_enrollment() {
if [ -f "$cfg/.cloudConfigRecordFound" ]; then if [ -f "$cfg/.cloudConfigRecordFound" ]; then
mdm_host=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \ mdm_host=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \
| grep -ioE 'https?://[a-z0-9._-]+' | sed -E 's#https?://##' \ | grep -ioE 'https?://[a-z0-9._-]+' | sed -E 's#https?://##' \
| sort -u | grep -viE '(^|\.)apple\.com$' | head -1) | sort -u | grep -viE '(^|\.)apple\.com$' | head -1 || true)
org=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \ org=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \
| grep -iA1 OrganizationName | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/') | grep -iA1 OrganizationName | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/' || true)
[ -n "$org" ] && info "Device assigned in ABM to: $org" [ -n "$org" ] && info "Device assigned in ABM to: $org"
[ -n "$mdm_host" ] && info "Org MDM host: $mdm_host" [ -n "$mdm_host" ] && info "Org MDM host: $mdm_host"
else else
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bats
check_optional_record() {
local kind="$1" entrypoint
for entrypoint in unleash unleash-standalone.sh; do
local script="$BATS_TEST_DIRNAME/../$entrypoint"
local definitions="$BATS_TEST_TMPDIR/$entrypoint.functions"
local target="$BATS_TEST_TMPDIR/$entrypoint-volume"
sed '/^main "\$@"$/d' "$script" > "$definitions"
python3 - "$target" "$kind" <<'PY'
import pathlib, plistlib, sys
settings = pathlib.Path(sys.argv[1]) / "private/var/db/ConfigurationProfiles/Settings"
settings.mkdir(parents=True)
records = {
"empty": {},
"apple": {"URL": "https://deviceenrollment.apple.com/enroll", "OrganizationName": "Example"},
"orgless": {"URL": "https://mdm.example.org/enroll"},
}
(settings / ".cloudConfigRecordFound").write_bytes(plistlib.dumps(records[sys.argv[2]]))
PY
run "${UNLEASH_TEST_SHELL:-bash}" -eu -o pipefail -c '
source "$1"
target="$2"
load_config() { :; }
resolve_data_volume() { printf "%s\n" "$target"; }
main suppress
' "$script" "$definitions" "$target"
[ "$status" -eq 0 ]
[ -f "$target/private/var/db/ConfigurationProfiles/Settings/.cloudConfigRecordNotFound" ]
[ -f "$target/private/var/db/com.apple.xpc.launchd/disabled.plist" ]
grep -q '0.0.0.0 iprofiles.apple.com' "$target/private/etc/hosts"
if [ "$kind" = orgless ]; then
grep -q '0.0.0.0 mdm.example.org' "$target/private/etc/hosts"
fi
done
}
@test "suppress completes when the activation record has no optional metadata" {
check_optional_record empty
}
@test "suppress completes when the activation record contains only Apple URLs" {
check_optional_record apple
}
@test "suppress preserves an organization host without an organization name" {
check_optional_record orgless
}
+2 -2
View File
@@ -486,9 +486,9 @@ suppress_enrollment() {
if [ -f "$cfg/.cloudConfigRecordFound" ]; then if [ -f "$cfg/.cloudConfigRecordFound" ]; then
mdm_host=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \ mdm_host=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \
| grep -ioE 'https?://[a-z0-9._-]+' | sed -E 's#https?://##' \ | grep -ioE 'https?://[a-z0-9._-]+' | sed -E 's#https?://##' \
| sort -u | grep -viE '(^|\.)apple\.com$' | head -1) | sort -u | grep -viE '(^|\.)apple\.com$' | head -1 || true)
org=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \ org=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \
| grep -iA1 OrganizationName | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/') | grep -iA1 OrganizationName | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/' || true)
[ -n "$org" ] && info "Device assigned in ABM to: $org" [ -n "$org" ] && info "Device assigned in ABM to: $org"
[ -n "$mdm_host" ] && info "Org MDM host: $mdm_host" [ -n "$mdm_host" ] && info "Org MDM host: $mdm_host"
else else