From 5bd5a74df91518a7a19fcf24231dd21cc4375360 Mon Sep 17 00:00:00 2001 From: Flo Date: Tue, 31 Mar 2026 18:29:40 +0200 Subject: [PATCH] fix: SSH permissions test failing in Linux containers Use if/else for stat format detection instead of || which can fail under set -e. Remove run wrapper for apply_ssh_config. Co-Authored-By: Claude --- test/git-harden.bats | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/git-harden.bats b/test/git-harden.bats index 4f86058..b7a0018 100755 --- a/test/git-harden.bats +++ b/test/git-harden.bats @@ -449,19 +449,27 @@ SSHEOF source_functions AUTO_YES=true - run apply_ssh_config - assert_success + apply_ssh_config # Check directory exists with correct mode [ -d "${TEST_HOME}/.ssh" ] [ -f "${TEST_HOME}/.ssh/config" ] + # stat format differs: macOS uses -f '%Lp', Linux uses -c '%a' local dir_perms - dir_perms="$(stat -f '%Lp' "${TEST_HOME}/.ssh" 2>/dev/null || stat -c '%a' "${TEST_HOME}/.ssh" 2>/dev/null)" + if stat -f '%Lp' "${TEST_HOME}/.ssh" >/dev/null 2>&1; then + dir_perms="$(stat -f '%Lp' "${TEST_HOME}/.ssh")" + else + dir_perms="$(stat -c '%a' "${TEST_HOME}/.ssh")" + fi [ "$dir_perms" = "700" ] local file_perms - file_perms="$(stat -f '%Lp' "${TEST_HOME}/.ssh/config" 2>/dev/null || stat -c '%a' "${TEST_HOME}/.ssh/config" 2>/dev/null)" + if stat -f '%Lp' "${TEST_HOME}/.ssh/config" >/dev/null 2>&1; then + file_perms="$(stat -f '%Lp' "${TEST_HOME}/.ssh/config")" + else + file_perms="$(stat -c '%a' "${TEST_HOME}/.ssh/config")" + fi [ "$file_perms" = "600" ] }