fix(profiles): keep preflight queries read-only and numeric

This commit is contained in:
2026-10-30 11:10:22 -03:00
parent 460ed05a1f
commit c9014c9b36
5 changed files with 20 additions and 4 deletions
+2 -1
View File
@@ -44,7 +44,8 @@ run_preformat_check() {
step "Checking installed profiles..." step "Checking installed profiles..."
if command -v profiles &>/dev/null; then if command -v profiles &>/dev/null; then
local profile_count local profile_count
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0) profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
profile_count="${profile_count:-0}"
if [ "$profile_count" -gt 0 ]; then if [ "$profile_count" -gt 0 ]; then
echo -e " ${YEL}$profile_count profile(s) installed${NC}" echo -e " ${YEL}$profile_count profile(s) installed${NC}"
clean=false clean=false
+1 -1
View File
@@ -12,7 +12,7 @@ harden_live_os() {
step "Removing residual MDM profiles..." step "Removing residual MDM profiles..."
if command -v profiles &>/dev/null; then if command -v profiles &>/dev/null; then
local installed local installed
installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true) installed=$(profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
if [ "$installed" -gt 0 ]; then if [ "$installed" -gt 0 ]; then
if sudo profiles -D -F 2>/dev/null; then if sudo profiles -D -F 2>/dev/null; then
success "Forced profile removal" success "Forced profile removal"
+6
View File
@@ -19,3 +19,9 @@ setup() {
run run_preformat_check 2>/dev/null || true run run_preformat_check 2>/dev/null || true
echo "$output" | grep -qiE "safe|mdm" 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 expression expected"* ]]
}
+8
View File
@@ -20,3 +20,11 @@ setup() {
run harden_status 2>/dev/null || true run harden_status 2>/dev/null || true
[ "$status" -eq 0 ] [ "$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' ]
}
+3 -2
View File
@@ -1286,7 +1286,7 @@ harden_live_os() {
step "Removing residual MDM profiles..." step "Removing residual MDM profiles..."
if command -v profiles &>/dev/null; then if command -v profiles &>/dev/null; then
local installed local installed
installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true) installed=$(profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
if [ "$installed" -gt 0 ]; then if [ "$installed" -gt 0 ]; then
if sudo profiles -D -F 2>/dev/null; then if sudo profiles -D -F 2>/dev/null; then
success "Forced profile removal" success "Forced profile removal"
@@ -1501,7 +1501,8 @@ run_preformat_check() {
step "Checking installed profiles..." step "Checking installed profiles..."
if command -v profiles &>/dev/null; then if command -v profiles &>/dev/null; then
local profile_count local profile_count
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0) profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
profile_count="${profile_count:-0}"
if [ "$profile_count" -gt 0 ]; then if [ "$profile_count" -gt 0 ]; then
echo -e " ${YEL}$profile_count profile(s) installed${NC}" echo -e " ${YEL}$profile_count profile(s) installed${NC}"
clean=false clean=false