@@ -2777,6 +2777,104 @@ test_native_shortcut_targets_compose_existing_flows() {
27772777 assert_contains " $setup_log " ' bash scripts/bootstrap-wizard.sh'
27782778}
27792779
2780+ test_sudo_alert_wrapper () {
2781+ info " Checking opt-in sudo password alerts"
2782+ local workspace=" $TMP_DIR /sudo-alert"
2783+ local bin_dir=" $workspace /bin"
2784+ local log_file=" $workspace /events.log"
2785+ local wrapper=" $REPO_DIR /scripts/sudo-with-alert.sh"
2786+ mkdir -p " $bin_dir "
2787+
2788+ cat > " $bin_dir /sudo" << 'EOF '
2789+ #!/usr/bin/env bash
2790+ set -eu
2791+ printf 'sudo:%s\n' "$*" >> "$SUDO_ALERT_TEST_LOG"
2792+ if [ "${1-}" = "-n" ] && [ "${2-}" = "-v" ]; then
2793+ exit "${SUDO_ALERT_TEST_CACHE_STATUS:-0}"
2794+ fi
2795+ if [ "${1-}" = "-v" ]; then
2796+ exit "${SUDO_ALERT_TEST_AUTH_STATUS:-0}"
2797+ fi
2798+ exit "${SUDO_ALERT_TEST_COMMAND_STATUS:-0}"
2799+ EOF
2800+ chmod +x " $bin_dir /sudo"
2801+
2802+ cat > " $bin_dir /pw-play" << 'EOF '
2803+ #!/usr/bin/env bash
2804+ set -eu
2805+ printf 'alert:%s\n' "$*" >> "$SUDO_ALERT_TEST_LOG"
2806+ exit "${SUDO_ALERT_TEST_SOUND_STATUS:-0}"
2807+ EOF
2808+ chmod +x " $bin_dir /pw-play"
2809+
2810+ : > " $log_file "
2811+ PATH=" $bin_dir :$HOST_TOOL_PATH " SUDO_ALERT_TEST_LOG=" $log_file " \
2812+ " $wrapper " true
2813+ assert_occurrence_count " $log_file " ' ^sudo:true$' 1
2814+ assert_not_contains " $log_file " ' sudo:-n -v'
2815+ assert_not_contains " $log_file " ' alert:'
2816+
2817+ : > " $log_file "
2818+ CODEX_SUDO_ALERT=1 PATH=" $bin_dir :$HOST_TOOL_PATH " SUDO_ALERT_TEST_LOG=" $log_file " \
2819+ " $wrapper " true
2820+ assert_contains " $log_file " ' sudo:-n -v'
2821+ assert_not_contains " $log_file " ' alert:'
2822+ assert_contains " $log_file " ' sudo:true'
2823+
2824+ : > " $log_file "
2825+ CODEX_SUDO_ALERT=1 SUDO_ALERT_TEST_CACHE_STATUS=1 \
2826+ PATH=" $bin_dir :$HOST_TOOL_PATH " SUDO_ALERT_TEST_LOG=" $log_file " \
2827+ " $wrapper " true
2828+ [ " $( sed -n ' 1p' " $log_file " ) " = ' sudo:-n -v' ] || fail " Expected cached sudo check first"
2829+ [ " $( sed -n ' 2p' " $log_file " ) " = ' alert:/usr/share/sounds/freedesktop/stereo/dialog-warning.oga' ] \
2830+ || fail " Expected alert before authentication"
2831+ [ " $( sed -n ' 3p' " $log_file " ) " = ' sudo:-v' ] || fail " Expected sudo authentication after alert"
2832+ [ " $( sed -n ' 4p' " $log_file " ) " = ' sudo:true' ] || fail " Expected command after authentication"
2833+
2834+ : > " $log_file "
2835+ CODEX_SUDO_ALERT=1 SUDO_ALERT_TEST_CACHE_STATUS=1 SUDO_ALERT_TEST_SOUND_STATUS=1 \
2836+ PATH=" $bin_dir :$HOST_TOOL_PATH " SUDO_ALERT_TEST_LOG=" $log_file " \
2837+ " $wrapper " true 2> /dev/null
2838+ assert_contains " $log_file " ' sudo:-v'
2839+ assert_contains " $log_file " ' sudo:true'
2840+
2841+ : > " $log_file "
2842+ local status=0
2843+ CODEX_SUDO_ALERT=1 SUDO_ALERT_TEST_CACHE_STATUS=1 SUDO_ALERT_TEST_AUTH_STATUS=23 \
2844+ PATH=" $bin_dir :$HOST_TOOL_PATH " SUDO_ALERT_TEST_LOG=" $log_file " \
2845+ " $wrapper " true 2> /dev/null || status=$?
2846+ [ " $status " -eq 23 ] || fail " Expected sudo authentication failure status, got $status "
2847+ assert_not_contains " $log_file " ' sudo:true'
2848+
2849+ : > " $log_file "
2850+ status=0
2851+ CODEX_SUDO_ALERT=1 SUDO_ALERT_TEST_COMMAND_STATUS=17 \
2852+ PATH=" $bin_dir :$HOST_TOOL_PATH " SUDO_ALERT_TEST_LOG=" $log_file " \
2853+ " $wrapper " true || status=$?
2854+ [ " $status " -eq 17 ] || fail " Expected privileged command status, got $status "
2855+ }
2856+
2857+ test_native_sudo_alert_wiring () {
2858+ info " Checking native targets route sudo through the alert wrapper"
2859+ local install_log=" $TMP_DIR /make-install-sudo-alert.log"
2860+ local bootstrap_log=" $TMP_DIR /make-bootstrap-sudo-alert.log"
2861+ local update_log=" $TMP_DIR /make-update-sudo-alert.log"
2862+
2863+ CODEX_SUDO_ALERT=1 make -n -C " $REPO_DIR " install > " $install_log "
2864+ assert_occurrence_count " $install_log " ' scripts/sudo-with-alert.sh' 5
2865+
2866+ CODEX_SUDO_ALERT=1 make -n -C " $REPO_DIR " bootstrap-native > " $bootstrap_log "
2867+ assert_contains " $bootstrap_log " ' bash scripts/install-deps.sh'
2868+ assert_contains " $bootstrap_log " ' install-native'
2869+
2870+ CODEX_SUDO_ALERT=1 make -n -C " $REPO_DIR " update-native > " $update_log "
2871+ assert_contains " $update_log " ' git pull --ff-only'
2872+ assert_contains " $update_log " ' install-native'
2873+
2874+ assert_contains " $REPO_DIR /scripts/install-deps.sh" ' sudo-with-alert.sh'
2875+ assert_contains " $REPO_DIR /Makefile" ' CODEX_SUDO_ALERT=1'
2876+ }
2877+
27802878test_fedora_dependency_bootstrap_installs_rpmbuild () {
27812879 info " Checking Fedora dependency bootstrap includes rpmbuild and C++ build tools"
27822880 local install_deps=" $REPO_DIR /scripts/install-deps.sh"
@@ -9082,6 +9180,8 @@ main() {
90829180 test_transactional_install_uses_managed_node_and_isolated_reports
90839181 test_installer_cleanup_handles_readonly_trees
90849182 test_native_shortcut_targets_compose_existing_flows
9183+ test_sudo_alert_wrapper
9184+ test_native_sudo_alert_wiring
90859185 test_fedora_dependency_bootstrap_installs_rpmbuild
90869186 test_fedora_atomic_rpm_ostree_target_detection
90879187 test_setup_native_wizard_noninteractive_feature_writer
0 commit comments