-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
test.sh
executable file
·151 lines (128 loc) · 4.53 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
echo "🧪 Running salt-api tests ..."
# https://stackoverflow.com/a/4774063/3398062
# shellcheck disable=SC2164
SCRIPT_PATH="$(
cd -- "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"
COMMON_FILE="${SCRIPT_PATH}/../lib/common.sh"
# shellcheck source=tests/lib/common.sh
source "${COMMON_FILE}"
trap cleanup EXIT
export SALTAPI_URL="https://localhost:8000/"
export SALTAPI_USER=salt_api
export SALTAPI_PASS=4wesome-Pass0rd
export SALTAPI_EAUTH=pam
# Create configuration files
echo "==> Creating salt-api configuration file ..."
mkdir -p "${SCRIPT_PATH}/config"
cat >"${SCRIPT_PATH}/config/salt-api.conf" <<EOF
# Breaking change from 3006
# https://docs.saltproject.io/en/latest/topics/netapi/netapi-enable-clients.html
netapi_enable_clients:
- local
- local_async
- local_batch
- local_subset
- runner
- runner_async
external_auth:
${SALTAPI_EAUTH}:
${SALTAPI_USER}:
- .*
- '@runner'
- '@wheel'
- '@jobs'
EOF
ok "salt-api config created"
# Run test instance
echo "==> Starting docker-salt-master (${PLATFORM}) with salt-api config and no api user ..."
start_container_and_wait \
--publish 8000:8000 \
--env SALT_API_ENABLED=True \
--env SALT_API_USER="" ||
error "container started"
ok "container started"
INTERNAL_SALT_API_USER="$(docker-exec bash -c 'env | grep SALT_API_USER= | cut -d= -f2')"
is_empty "${INTERNAL_SALT_API_USER}" "SALT_API_USER remains empty when explicitly defined that way"
# Stop and start with salt-api config
echo "==> Stopping previous container ..."
cleanup || error "Unable to stop previour container"
echo "==> Starting docker-salt-master (${PLATFORM}) with salt-api config ..."
start_container_and_wait \
--publish 8000:8000 \
--env SALT_API_ENABLED=True \
--env SALT_API_USER_PASS="${SALTAPI_PASS}" ||
error "container started"
ok "container started"
# Test salt-api authentication
echo "==> Getting salt-api token ..."
CURL_OUTPUT="$(curl -sSk "${SALTAPI_URL%/}/login" \
-H "Accept: application/x-yaml" \
-d username="${SALTAPI_USER}" \
-d password="${SALTAPI_PASS}" \
-d eauth="${SALTAPI_EAUTH}")"
echo "${CURL_OUTPUT}"
SALTAPI_TOKEN=
SALTAPI_TOKEN="$(echo -n "${CURL_OUTPUT}" | grep -Ei 'token: ([^\s]+)' | awk '{print $2}')"
[[ -n "${SALTAPI_TOKEN}" ]] || error "salt-api token"
ok "salt-api token"
# Test salt-api command
echo "==> Testing curl command ..."
CURL_OUTPUT="$(curl -sSk "${SALTAPI_URL}" \
-H "Accept: application/x-yaml" \
-H "X-Auth-Token: ${SALTAPI_TOKEN}" \
-d client=runner \
-d tgt='*' \
-d fun=test.stream)"
echo "${CURL_OUTPUT}"
echo -n "${CURL_OUTPUT}" | grep -i true || error "curl command"
ok "curl command"
# Stop and start with salt-api pass via file
echo "==> Stopping previous container ..."
cleanup || error "Unable to stop previour container"
echo "==> Starting docker-salt-master (${PLATFORM}) with salt-api config and password via file ..."
export SALT_API_USER_PASS_FILE=salt_api_user_pass
echo -n "${SALTAPI_PASS}" >"./${SALT_API_USER_PASS_FILE}"
start_container_and_wait \
--publish 8000:8000 \
--env SALT_API_ENABLED=True \
--env SALT_API_USER_PASS_FILE="/run/secrets/${SALT_API_USER_PASS_FILE}" \
--volume "$(pwd)/${SALT_API_USER_PASS_FILE}":/run/secrets/${SALT_API_USER_PASS_FILE}:ro ||
error "container started"
ok "container started"
# Test salt-api authentication
echo "==> Getting salt-api token (pass via file) ..."
CURL_OUTPUT="$(curl -sSk "${SALTAPI_URL%/}/login" \
-H "Accept: application/x-yaml" \
-d username="${SALTAPI_USER}" \
-d password="${SALTAPI_PASS}" \
-d eauth="${SALTAPI_EAUTH}")"
echo "${CURL_OUTPUT}"
SALTAPI_TOKEN=
SALTAPI_TOKEN="$(echo -n "${CURL_OUTPUT}" | grep -Ei 'token: ([^\s]+)' | awk '{print $2}')"
[[ -n "${SALTAPI_TOKEN}" ]] || error "salt-api token"
ok "salt-api token"
# Test salt-api command via curl
echo "==> Testing curl command (pass via file) ..."
CURL_OUTPUT="$(curl -sSk "${SALTAPI_URL}" \
-H "Accept: application/x-yaml" \
-H "X-Auth-Token: ${SALTAPI_TOKEN}" \
-d client=runner \
-d tgt='*' \
-d fun=test.stream)"
echo "${CURL_OUTPUT}"
echo -n "${CURL_OUTPUT}" | grep -i true || error "curl command (pass via file)"
ok "curl command (pass via file)"
# Install salt-pepper
echo "==> Installing salt-pepper ..."
pip3 install salt-pepper || error "pepper installed"
ok "pepper installed"
# Test minion connection
setup_and_start_salt_minion || error "salt-minion started"
ok "salt-minion started"
# Test pepper with salt-minion
echo "==> Testing pepper with salt-minion (test.ping) ..."
pepper "${TEST_MINION_ID}" test.ping || error "pepper test.ping"
ok "pepper test.ping"