From 6b2317824d379c4341a6aac18f13300ae8cc72e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20A=CC=81lvaro?= Date: Mon, 17 Jun 2024 12:52:54 +0200 Subject: [PATCH] feat: Add tests for checking there's not ubuntu user --- tests/basic/test.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/basic/test.sh b/tests/basic/test.sh index 452d30c..e702127 100755 --- a/tests/basic/test.sh +++ b/tests/basic/test.sh @@ -5,7 +5,10 @@ echo "🧪 Running basic tests ..." # https://stackoverflow.com/a/4774063/3398062 # shellcheck disable=SC2164 -SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +SCRIPT_PATH="$( + cd -- "$(dirname "$0")" >/dev/null 2>&1 + pwd -P +)" # shellcheck source=assets/build/functions.sh COMMON_FILE="${SCRIPT_PATH}/../lib/common.sh" @@ -34,6 +37,7 @@ echo "${output}" CURRENT_MINION_VERSION="$(echo -n "${output}" | grep -Ei 'salt: ([^\s]+)' | awk '{print $2}')" check_equal "${CURRENT_MINION_VERSION%%-*}" "${EXPECTED_VERSION%%-*}" "salt-minion version" +echo "==> Checking salt-minion service ..." docker-exec bash -c 'test -z "$(ps aux | grep salt-minion | grep -v grep)"' || error "salt-minion is running inside the container by default" ok "salt-minion is not running inside the container" @@ -44,6 +48,24 @@ ok "salt-minion started" salt "${TEST_MINION_ID}" test.ping || error "${TEST_MINION_ID} ping" ok "${TEST_MINION_ID} ping" +echo "==> Checking salt user permissions ..." + # Test salt home permissions docker-exec bash -c 'test $(stat -c "%U:%G" "${SALT_HOME}") = "${SALT_USER}:${SALT_USER}"' || error "salt home permissions" ok "salt home permissions" + +# Test salt PUID and PGID +EXPECTED_USER_ID="salt:x:$(id -u):$(id -g):Salt:/home/salt:/usr/sbin/nologin" +CURRENT_USER_ID="$(docker-exec bash -c 'getent passwd salt')" +check_equal "${CURRENT_USER_ID}" "${EXPECTED_USER_ID}" "salt user id" + +EXPECTED_GROUP_ID="salt:x:$(id -g):" +CURRENT_GROUP_ID="$(docker-exec bash -c 'getent group salt')" +check_equal "${CURRENT_GROUP_ID}" "${EXPECTED_GROUP_ID}" "salt group id" + +echo "==> Checking there is not ubuntu user/group ..." +docker-exec bash -c 'getent passwd ubuntu >/dev/null 2>&1' && error "ubuntu user is present inside the container" +ok "There is not ubuntu user inside the container" + +docker-exec bash -c 'getent group ubuntu >/dev/null 2>&1' && error "ubuntu group is present inside the container" +ok "There is not ubuntu group inside the container"