Files
Pierre Warnier 5d8ac9587d review: address all 13 Copilot review comments
- Fix cargo build --release --workspace in test scripts
- Document setuid-on-symlinks as intentional in Makefile
- Warn (not abort) on subid allocation failure in useradd
- Propagate subid file read errors instead of unwrap_or_default
- Update SELinux docs to describe best-effort behavior
- Add env_clear() to getfattr subprocess in selinux.rs
- Use hardening::sanitized_env() in nscd.rs instead of local reimpl
- Create testuser in pam-e2e.sh, add cleanup
- Document su-as-root limitation in pam-e2e.sh
- Fix set -e exit code capture in gnu-compat.sh
- Add 5 date validation unit tests in chage
- Wire audit::log_user_event into all 7 tools
2026-03-24 15:42:08 +01:00

93 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# GNU compatibility test suite for shadow-rs.
# Runs both GNU and shadow-rs tools, diffs output.
# Usage: docker compose run --rm debian bash tests/gnu-compat.sh
set -euo pipefail
PASS=0; FAIL=0; SKIP=0
cargo build --release --workspace 2>/dev/null
RS=./target/release
compare() {
local name="$1" our_cmd="$2" gnu_cmd="$3"
local our_out gnu_out
our_out=$(eval "$our_cmd" 2>&1) || true
gnu_out=$(eval "$gnu_cmd" 2>&1) || true
if [ "$our_out" = "$gnu_out" ]; then
echo " PASS: $name"
((PASS++))
else
echo " FAIL: $name"
echo " shadow-rs: ${our_out:0:80}"
echo " GNU: ${gnu_out:0:80}"
((FAIL++))
fi
}
compare_exit() {
local name="$1" our_cmd="$2" gnu_cmd="$3"
local our_rc gnu_rc
our_rc=0; eval "$our_cmd" >/dev/null 2>&1 || our_rc=$?
gnu_rc=0; eval "$gnu_cmd" >/dev/null 2>&1 || gnu_rc=$?
if [ "$our_rc" = "$gnu_rc" ]; then
echo " PASS: $name (exit $our_rc)"
((PASS++))
else
echo " FAIL: $name (shadow-rs=$our_rc, GNU=$gnu_rc)"
((FAIL++))
fi
}
echo "=== passwd ==="
compare "passwd -S root" "$RS/passwd -S root" "/usr/bin/passwd -S root"
compare_exit "passwd --help" "$RS/passwd --help" "/usr/bin/passwd --help"
compare_exit "passwd --bogus" "$RS/passwd --bogus" "/usr/bin/passwd --bogus"
echo "=== pwck ==="
compare "pwck -r output" "$RS/pwck -r" "/usr/sbin/pwck -r"
compare_exit "pwck -r exit" "$RS/pwck -r" "/usr/sbin/pwck -r"
compare_exit "pwck -q -r" "$RS/pwck -q -r" "/usr/sbin/pwck -q -r"
echo "=== useradd ==="
compare_exit "useradd --help" "$RS/useradd --help" "/usr/sbin/useradd --help"
echo "=== userdel ==="
compare_exit "userdel --help" "$RS/userdel --help" "/usr/sbin/userdel --help"
echo "=== usermod ==="
compare_exit "usermod --help" "$RS/usermod --help" "/usr/sbin/usermod --help"
echo "=== groupadd ==="
compare_exit "groupadd --help" "$RS/groupadd --help" "/usr/sbin/groupadd --help"
echo "=== groupdel ==="
compare_exit "groupdel --help" "$RS/groupdel --help" "/usr/sbin/groupdel --help"
echo "=== groupmod ==="
compare_exit "groupmod --help" "$RS/groupmod --help" "/usr/sbin/groupmod --help"
echo "=== chage ==="
compare_exit "chage --help" "$RS/chage --help" "/usr/bin/chage --help"
echo "=== chpasswd ==="
compare_exit "chpasswd --help" "$RS/chpasswd --help" "/usr/sbin/chpasswd --help"
echo "=== chfn ==="
compare_exit "chfn --help" "$RS/chfn --help" "/usr/bin/chfn --help"
echo "=== chsh ==="
compare_exit "chsh --help" "$RS/chsh --help" "/usr/bin/chsh --help"
echo "=== grpck ==="
compare_exit "grpck --help" "$RS/grpck --help" "/usr/sbin/grpck --help"
echo "=== newgrp ==="
compare_exit "newgrp --help" "$RS/newgrp --help" "/usr/bin/newgrp --help"
echo ""
echo "=== Results ==="
echo " PASS: $PASS"
echo " FAIL: $FAIL"
echo " SKIP: $SKIP"