From b3b9c10d68c127232514b183254574eb169d15ca Mon Sep 17 00:00:00 2001 From: Luca Sacchi Ricciardi Date: Thu, 9 Apr 2026 12:27:57 +0200 Subject: [PATCH] fix: correct line endings, paths, and syntax in all lab01 test scripts --- labs/lab-01-iam/tests/03-non-root-test.sh | 11 +++++++---- labs/lab-01-iam/tests/99-final-verification.sh | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/labs/lab-01-iam/tests/03-non-root-test.sh b/labs/lab-01-iam/tests/03-non-root-test.sh index eb3f286..2e7f8c3 100755 --- a/labs/lab-01-iam/tests/03-non-root-test.sh +++ b/labs/lab-01-iam/tests/03-non-root-test.sh @@ -4,6 +4,9 @@ set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" + # Helper function for incrementing counters that works with set -e inc_pass() { ((pass_count++)) || true; } inc_fail() { ((fail_count++)) || true; } @@ -20,7 +23,7 @@ fail_count=0 CONTAINER_NAME="lab01-test-container" test_non_root_dockerfile_exists() { - local dockerfile="labs/lab-01-iam/Dockerfile.test" + local dockerfile="$PROJECT_ROOT/labs/lab-01-iam/Dockerfile.test" if [ -f "$dockerfile" ]; then echo -e "${GREEN}PASS${NC}: Test Dockerfile exists" @@ -78,8 +81,8 @@ test_container_user_configured() { if [ -z "$user_config" ]; then # Check compose file for user directive (may override Dockerfile) - if [ -f "labs/lab-01-iam/docker-compose.yml" ]; then - if grep -q "user:" labs/lab-01-iam/docker-compose.yml; then + if [ -f "$PROJECT_ROOT/labs/lab-01-iam/docker-compose.yml" ]; then + if grep -q "user:" $PROJECT_ROOT/labs/lab-01-iam/docker-compose.yml; then echo -e "${GREEN}PASS${NC}: User directive found in docker-compose.yml" inc_pass return 0 @@ -98,7 +101,7 @@ test_container_user_configured() { test_no_container_runs_as_root() { # INF-01 requirement: NO container should run as root - local compose_file="labs/lab-01-iam/docker-compose.yml" + local compose_file="$PROJECT_ROOT/labs/lab-01-iam/docker-compose.yml" if [ ! -f "$compose_file" ]; then echo -e "${YELLOW}SKIP${NC}: docker-compose.yml not created yet" diff --git a/labs/lab-01-iam/tests/99-final-verification.sh b/labs/lab-01-iam/tests/99-final-verification.sh index ff50ef8..6f3b949 100755 --- a/labs/lab-01-iam/tests/99-final-verification.sh +++ b/labs/lab-01-iam/tests/99-final-verification.sh @@ -5,6 +5,9 @@ set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" + RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' @@ -49,7 +52,7 @@ echo "" # Test 3: Non-root container execution (INF-01) echo -e "${BLUE}[3/3] Checking non-root container execution (INF-01)...${NC}" -cd labs/lab-01-iam +cd "$PROJECT_ROOT/labs/lab-01-iam" compose_file="docker-compose.yml" if [ ! -f "$compose_file" ]; then echo -e " ${YELLOW}○${NC} docker-compose.yml not found"