Skip to content

Commit c26d198

Browse files
committed
fix(ci): capture protocol forensics and patch stdlib floor
1 parent 87e27cb commit c26d198

4 files changed

Lines changed: 139 additions & 2 deletions

File tree

gen/go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nantian-gw/proto
22

3-
go 1.26.3
3+
go 1.26.4
44

55
require (
66
google.golang.org/grpc v1.80.0

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nantian-gw/gateway
22

3-
go 1.26.3
3+
go 1.26.4
44

55
require (
66
github.com/go-logr/logr v1.4.3

scripts/ci/ci_assets_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,23 @@ func TestSmokeScriptUsesCurlBasedInClusterProbe(t *testing.T) {
308308
}
309309
}
310310

311+
func TestSmokeScriptCapturesProtocolForensicsOnFailure(t *testing.T) {
312+
contents := string(readFile(t, repoPath("test", "e2e", "smoke", "run.sh")))
313+
314+
for _, want := range []string{
315+
`last_https_fallback_code`,
316+
`last_https_fallback_body`,
317+
`last_backend_direct_code`,
318+
`last_backend_direct_body`,
319+
`https_fallback_url=`,
320+
`backend_direct_url=`,
321+
} {
322+
if !strings.Contains(contents, want) {
323+
t.Fatalf("smoke script missing %q", want)
324+
}
325+
}
326+
}
327+
311328
func TestEmbeddedProtoGoModuleAvoidsKnownVulnerableIndirectDeps(t *testing.T) {
312329
contents := string(readFile(t, repoPath("gen", "go", "go.mod")))
313330

@@ -330,6 +347,24 @@ func TestEmbeddedProtoGoModuleAvoidsKnownVulnerableIndirectDeps(t *testing.T) {
330347
}
331348
}
332349

350+
func TestGoModulesDeclarePatchedStdlibVersion(t *testing.T) {
351+
for _, path := range []string{
352+
repoPath("go.mod"),
353+
repoPath("gen", "go", "go.mod"),
354+
} {
355+
t.Run(path, func(t *testing.T) {
356+
contents := string(readFile(t, path))
357+
358+
if !strings.Contains(contents, "go 1.26.4") {
359+
t.Fatalf("%s missing %q", path, "go 1.26.4")
360+
}
361+
if strings.Contains(contents, "go 1.26.3") {
362+
t.Fatalf("%s still contains %q", path, "go 1.26.3")
363+
}
364+
})
365+
}
366+
}
367+
333368
func TestCIEntrypointsUseCurrentDeployResourceNames(t *testing.T) {
334369
conformanceWorkflow := string(readFile(t, repoPath(".github", "workflows", "conformance.yml")))
335370
if !strings.Contains(conformanceWorkflow, "-gateway-class nantian-gw") {

test/e2e/smoke/run.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ GATEWAY_SERVICE="nantian-gw-$GATEWAY_NAME"
1717
SMOKE_CLIENT_POD="smoke-client"
1818
SMOKE_CLIENT_IMAGE="${SMOKE_CLIENT_IMAGE:-curlimages/curl:8.16.0}"
1919
SMOKE_URL="http://${GATEWAY_SERVICE}.${CONTROL_PLANE_NS}.svc.cluster.local/echo"
20+
BACKEND_DIRECT_URL="http://echo.${TEST_NS}.svc.cluster.local/echo"
2021
ECHO_PORT=8080
2122
TIMEOUT="${TIMEOUT:-180}"
2223
KIND_CONFIG="${KIND_CONFIG:-$GATEWAY_ROOT/scripts/ci/kind-ci-config.yaml}"
@@ -50,6 +51,65 @@ trim_response_detail() {
5051
printf '%.240s' "$value"
5152
}
5253

54+
probe_from_smoke_client() {
55+
local url="$1"
56+
local request_timeout="$2"
57+
local mode="${3:-plain}"
58+
59+
kubectl exec -n "$TEST_NS" "$SMOKE_CLIENT_POD" -- \
60+
sh -c '
61+
body_file=/tmp/smoke-response-body.txt
62+
rm -f "$body_file"
63+
64+
curl_flags=""
65+
if [ "$3" = "insecure" ]; then
66+
curl_flags="-k"
67+
fi
68+
69+
if ! status="$(curl -sS ${curl_flags} --connect-timeout "$1" --max-time "$1" \
70+
-o "$body_file" -w "%{http_code}" "$2")"; then
71+
rc=$?
72+
printf "__CURL_EXIT__%s\n" "$rc"
73+
[ -f "$body_file" ] && cat "$body_file"
74+
exit "$rc"
75+
fi
76+
77+
printf "__STATUS__%s\n" "$status"
78+
cat "$body_file"
79+
' sh "$request_timeout" "$url" "$mode" 2>&1
80+
}
81+
82+
probe_output_code() {
83+
printf '%s\n' "$1" | awk 'NR == 1 {sub(/^__STATUS__/, "", $0); print; exit}'
84+
}
85+
86+
probe_output_body() {
87+
printf '%s\n' "$1" | tail -n +2
88+
}
89+
90+
probe_and_capture() {
91+
local url="$1"
92+
local request_timeout="$2"
93+
local mode="$3"
94+
local -n code_ref="$4"
95+
local -n body_ref="$5"
96+
local -n error_ref="$6"
97+
local output=""
98+
99+
code_ref=""
100+
body_ref=""
101+
error_ref=""
102+
103+
if ! output="$(probe_from_smoke_client "$url" "$request_timeout" "$mode")"; then
104+
error_ref="$output"
105+
return 1
106+
fi
107+
108+
code_ref="$(probe_output_code "$output")"
109+
body_ref="$(probe_output_body "$output")"
110+
return 0
111+
}
112+
53113
fail() {
54114
red "FAIL: $*"
55115
FAILED=true
@@ -281,6 +341,14 @@ send_request() {
281341
local last_request_error=""
282342
local last_response_code=""
283343
local last_response_body=""
344+
local https_fallback_url="https://${GATEWAY_SERVICE}.${CONTROL_PLANE_NS}.svc.cluster.local/echo"
345+
local backend_direct_url="$BACKEND_DIRECT_URL"
346+
local last_https_fallback_error=""
347+
local last_https_fallback_code=""
348+
local last_https_fallback_body=""
349+
local last_backend_direct_error=""
350+
local last_backend_direct_code=""
351+
local last_backend_direct_body=""
284352
local output=""
285353
local response_code=""
286354
local response_body=""
@@ -325,6 +393,22 @@ send_request() {
325393
sleep 2
326394
done
327395

396+
probe_and_capture \
397+
"$https_fallback_url" \
398+
"$request_timeout" \
399+
insecure \
400+
last_https_fallback_code \
401+
last_https_fallback_body \
402+
last_https_fallback_error || true
403+
404+
probe_and_capture \
405+
"$backend_direct_url" \
406+
"$request_timeout" \
407+
plain \
408+
last_backend_direct_code \
409+
last_backend_direct_body \
410+
last_backend_direct_error || true
411+
328412
local detail=""
329413
if [[ -n "$last_request_error" ]]; then
330414
detail=$'\nlast request error: '"$last_request_error"
@@ -335,6 +419,24 @@ send_request() {
335419
if [[ -n "$last_response_body" ]]; then
336420
detail+=$'\nlast response body: '"$(trim_response_detail "$last_response_body")"
337421
fi
422+
if [[ -n "$last_https_fallback_error" ]]; then
423+
detail+=$'\nlast https fallback error: '"$(trim_response_detail "$last_https_fallback_error")"
424+
fi
425+
if [[ -n "$last_https_fallback_code" ]]; then
426+
detail+=$'\nlast https fallback code: '"$last_https_fallback_code"
427+
fi
428+
if [[ -n "$last_https_fallback_body" ]]; then
429+
detail+=$'\nlast https fallback body: '"$(trim_response_detail "$last_https_fallback_body")"
430+
fi
431+
if [[ -n "$last_backend_direct_error" ]]; then
432+
detail+=$'\nlast backend direct error: '"$(trim_response_detail "$last_backend_direct_error")"
433+
fi
434+
if [[ -n "$last_backend_direct_code" ]]; then
435+
detail+=$'\nlast backend direct code: '"$last_backend_direct_code"
436+
fi
437+
if [[ -n "$last_backend_direct_body" ]]; then
438+
detail+=$'\nlast backend direct body: '"$(trim_response_detail "$last_backend_direct_body")"
439+
fi
338440

339441
fail "GET /echo via $GATEWAY_SERVICE did not succeed within ${TIMEOUT}s${detail}"
340442
return 1

0 commit comments

Comments
 (0)