Skip to content

Commit 17474fe

Browse files
committed
gw: fix shellcheck warnings in e2e test.sh (prek CI)
prek's shellcheck-py started scanning e2e/test.sh once the previous commit modified it, and surfaced two pre-existing classes of warnings: - SC3043: `local` is undefined in POSIX sh. The script uses bash-only `local` throughout, so the `#!/bin/sh` shebang was already wrong. Switch to `#!/bin/bash`. - SC2155: `local foo=$(cmd)` masks the inner command's exit status. Split into `local foo; foo=$(cmd)` at every site (one inside `test_certificate_from_pebble`, the rest inside `main`). Remaining shellcheck findings are info-level only (SC2086, SC2317); the prek CI run only failed on warning-level findings.
1 parent a42b015 commit 17474fe

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

gateway/test-run/e2e/test.sh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# SPDX-FileCopyrightText: 2024-2025 Phala Network <dstack@phala.network>
33
#
44
# SPDX-License-Identifier: Apache-2.0
@@ -162,7 +162,8 @@ test_certificates_match() {
162162

163163
test_certificate_from_pebble() {
164164
local sni="$1"
165-
local proxy=$(echo "$GATEWAY_PROXIES" | cut -d' ' -f1)
165+
local proxy
166+
proxy=$(echo "$GATEWAY_PROXIES" | cut -d' ' -f1)
166167
get_cert_issuer "$proxy" "$sni" | grep -qi "pebble"
167168
}
168169

@@ -287,9 +288,10 @@ main() {
287288

288289
# Phase 5: Certificate issuance
289290
log_phase 5 "Certificate issuance"
290-
local first_domain=$(echo "$CERT_DOMAINS" | cut -d' ' -f1)
291-
local first_sni=$(get_test_sni "$first_domain")
292-
local first_proxy=$(echo "$GATEWAY_PROXIES" | cut -d' ' -f1)
291+
local first_domain first_sni first_proxy
292+
first_domain=$(echo "$CERT_DOMAINS" | cut -d' ' -f1)
293+
first_sni=$(get_test_sni "$first_domain")
294+
first_proxy=$(echo "$GATEWAY_PROXIES" | cut -d' ' -f1)
293295

294296
log_info "Waiting for certificates (up to 120s)..."
295297
local waited=0
@@ -303,8 +305,9 @@ main() {
303305
log_info "Waiting... (${waited}s)"
304306
done
305307

308+
local sni wildcard
306309
for domain in $CERT_DOMAINS; do
307-
local sni=$(get_test_sni "$domain")
310+
sni=$(get_test_sni "$domain")
308311
run_test "Certificate issued for $domain" \
309312
"$(test_certificate_issued "$first_proxy" "$sni"; echo $?)"
310313
done
@@ -315,7 +318,7 @@ main() {
315318
# Phase 6: Certificate consistency
316319
log_phase 6 "Certificate consistency"
317320
for domain in $CERT_DOMAINS; do
318-
local sni=$(get_test_sni "$domain")
321+
sni=$(get_test_sni "$domain")
319322
run_test "All gateways have same cert for $domain" \
320323
"$(test_certificates_match "$sni"; echo $?)"
321324
run_test "Cert for $domain issued by Pebble" \
@@ -325,17 +328,18 @@ main() {
325328
# Phase 7: SNI-based selection
326329
log_phase 7 "SNI-based certificate selection"
327330
for domain in $CERT_DOMAINS; do
328-
local sni=$(get_test_sni "$domain")
329-
local wildcard=$(get_wildcard_domain "$domain")
331+
sni=$(get_test_sni "$domain")
332+
wildcard=$(get_wildcard_domain "$domain")
330333
run_test "SNI $sni returns $wildcard cert" \
331334
"$(test_sni_cert_selection "$first_proxy" "$sni" "$wildcard"; echo $?)"
332335
done
333336

334337
# Phase 8: Proxy TLS health
335338
log_phase 8 "Proxy TLS health endpoint"
339+
local i
336340
for domain in $CERT_DOMAINS; do
337-
local sni=$(get_test_sni "$domain")
338-
local i=1
341+
sni=$(get_test_sni "$domain")
342+
i=1
339343
for proxy in $GATEWAY_PROXIES; do
340344
run_test "Gateway $i TLS health ($sni)" \
341345
"$(test_proxy_tls_health "$proxy" "$sni"; echo $?)"
@@ -345,7 +349,8 @@ main() {
345349

346350
# Phase 9: DNS records (informational)
347351
log_phase 9 "DNS-01 challenge records"
348-
local records=$(curl -sf "${MOCK_CF_API}/api/records" 2>/dev/null || echo "")
352+
local records
353+
records=$(curl -sf "${MOCK_CF_API}/api/records" 2>/dev/null || echo "")
349354
if echo "$records" | grep -q "TXT"; then
350355
log_success "DNS TXT records found"
351356
else

0 commit comments

Comments
 (0)