Skip to content

Commit

Permalink
feat: Add tests for checking there's not ubuntu user
Browse files Browse the repository at this point in the history
  • Loading branch information
cdalvaro committed Jun 20, 2024
1 parent b444cfe commit 6b23178
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/basic/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand All @@ -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"

0 comments on commit 6b23178

Please sign in to comment.