@@ -4,23 +4,40 @@ log-info "testing disabled JWT functionality..."
44
55# Replace with disable_jwt_svids = true configuration
66sed -i.bak " s#disable_jwt_svids = false#disable_jwt_svids = true#g" conf/server/server.conf
7+
8+ # The restart reuses the container, so its log keeps the "Starting Server APIs"
9+ # markers from the original boot. Capture that count first and wait for the
10+ # restarted server to emit its own markers, otherwise the readiness check would
11+ # return on the stale ones before the server is actually listening again.
12+ baseline=$( count-server-api-starts spire-server)
713docker compose restart spire-server
8- check- server-started spire-server
14+ wait-for- server-restarted spire-server " $baseline "
915
1016test-jwt-disabled-command () {
1117 local test_name=" $1 "
1218 shift 1
1319 local command=(" $@ " )
14-
15- if ! ERROR_OUTPUT=$( " ${command[@]} " 2>&1 ) ; then
20+
21+ # Retry to ride out the brief window right after the restart where the
22+ # server (or the agent's connection to it) is not ready yet and the command
23+ # fails with a transient transport error instead of the expected JWT
24+ # disabled error. The agent JWT fetch reaches the server over its TCP API,
25+ # so it is the check most prone to racing the restart.
26+ local MAXCHECKS=15
27+ local CHECKINTERVAL=1
28+ for (( i= 1 ;i<= MAXCHECKS;i++ )) ; do
29+ if ERROR_OUTPUT=$( " ${command[@]} " 2>&1 ) ; then
30+ fail-now " $test_name should have failed when JWT is disabled"
31+ fi
1632 if echo " $ERROR_OUTPUT " | grep -q " JWT functionality is disabled" ; then
1733 log-info " ✓ $test_name correctly failed with JWT disabled error"
18- else
19- fail-now " $test_name expected JWT disabled error, but got: $ERROR_OUTPUT "
34+ return 0
2035 fi
21- else
22- fail-now " $test_name should have failed when JWT is disabled"
23- fi
36+ log-info " $test_name not ready yet (attempt $i of $MAXCHECKS ): $ERROR_OUTPUT "
37+ sleep " ${CHECKINTERVAL} "
38+ done
39+
40+ fail-now " $test_name expected JWT disabled error, but got: $ERROR_OUTPUT "
2441}
2542
2643test-jwt-disabled-command " JWT authority prepare" \
0 commit comments