forked from spiffe/java-spiffe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration-tests.sh
executable file
·77 lines (63 loc) · 2.21 KB
/
integration-tests.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
#!/usr/bin/env bash
# Start a SPIRE Server and Agent and run the integration tests
# Only works on Linux.
set -euf -o pipefail
export SPIFFE_ENDPOINT_SOCKET="unix:/tmp/spire-agent/public/api.sock"
spire_version="1.4.0"
spire_folder="spire-${spire_version}"
spire_server_log_file="/tmp/spire-server/server.log"
spire_agent_log_file="/tmp/spire-agent/agent.log"
function cleanup() {
killall -9 spire-agent || true
killall -9 spire-server || true
rm -f /tmp/spire-server/private/api.sock
rm -f /tmp/spire-agent/public/api.sock
rm -rf ${spire_folder}
}
# Some cleanup: kill spire processes that could have remained from previous run
trap cleanup EXIT
# Install and run a SPIRE server
curl -s -N -L https://github.com/spiffe/spire/releases/download/v${spire_version}/spire-${spire_version}-linux-x86_64-glibc.tar.gz | tar xz
pushd "${spire_folder}"
mkdir -p /tmp/spire-server
bin/spire-server run -config conf/server/server.conf > "${spire_server_log_file}" 2>&1 &
spire_server_started=0
for i in {1..10}
do
if bin/spire-server healthcheck >/dev/null 2>&1; then
spire_server_started=1
break
fi
sleep 1
done
if [ ${spire_server_started} -ne 1 ]; then
cat ${spire_server_log_file} >&2
echo 'SPIRE Server failed to start' >&2
exit 1
fi
# Generate token and run Spire Agent
agent_id="spiffe://example.org/myagent"
bin/spire-server token generate -spiffeID ${agent_id} > token
cut -d ' ' -f 2 token > token_stripped
mkdir -p /tmp/spire-agent
bin/spire-agent run -config conf/agent/agent.conf -joinToken "$(< token_stripped)" > "${spire_agent_log_file}" 2>&1 &
spire_agent_started=0
for i in {1..10}
do
if bin/spire-agent healthcheck >/dev/null 2>&1; then
spire_agent_started=1
break
fi
sleep 1
done
if [ ${spire_agent_started} -ne 1 ]; then
cat ${spire_agent_log_file} >&2
echo 'SPIRE Agent failed to start' >&2
exit 1
fi
# Register the workload through UID with the SPIFFE ID "spiffe://example.org/myservice"
bin/spire-server entry create -parentID ${agent_id} -spiffeID spiffe://example.org/myservice -selector unix:uid:$(id -u)
sleep 10 # this value is derived from the default Agent sync interval
popd
# Run only the integration tests
./gradlew integrationTest