@@ -151,10 +151,15 @@ func curlHTTPCodeFromClient(ctx context.Context, host, url string) (code string,
151151
152152// curlHTTPRedirectFromClient executes curl and returns the HTTP status code and Location header.
153153// It does NOT follow redirects (no -L flag) so we can see the redirect response.
154- func curlHTTPRedirectFromClient (ctx context.Context , host , url string ) (code string , location string , out string , err error ) {
154+ // If insecure is true, adds -k flag to skip certificate verification (useful for HTTPS with self-signed certs).
155+ func curlHTTPRedirectFromClient (ctx context.Context , host , url string , insecure bool ) (code string , location string , out string , err error ) {
155156 // Use -i to include headers, -s for silent, but keep stderr for errors
156157 // Extract status code and Location header
157- script := `set -o pipefail; curl -sSi --connect-timeout 2 --max-time 5 -H "Host: $1" "$2" 2>&1 || echo "000"`
158+ insecureFlag := ""
159+ if insecure {
160+ insecureFlag = "-k "
161+ }
162+ script := fmt .Sprintf (`set -o pipefail; curl %s-sSi --connect-timeout 2 --max-time 5 -H "Host: $1" "$2" 2>&1 || echo "000"` , insecureFlag )
158163 out , err = kubectl (ctx , "-n" , "default" , "exec" , "deploy/curl" , "--" ,
159164 "sh" , "-c" , script , "_" , host , url ,
160165 )
@@ -188,19 +193,6 @@ func curlHTTPRedirectFromClient(ctx context.Context, host, url string) (code str
188193 return code , location , out , nil
189194}
190195
191- // curlHTTPS200FromClient executes curl with -k (insecure) flag for HTTPS requests.
192- func curlHTTPS200FromClient (ctx context.Context , host , url string ) (code string , out string , err error ) {
193- // Use -k to skip certificate verification for self-signed certs
194- script := `set -o pipefail; curl -k -sS -o /dev/null -w "%{http_code}" --connect-timeout 2 --max-time 5 -H "Host: $1" "$2" || echo 000`
195- out , err = kubectl (ctx , "-n" , "default" , "exec" , "deploy/curl" , "--" ,
196- "sh" , "-c" , script , "_" , host , url ,
197- )
198- if err != nil {
199- return "000" , out , err
200- }
201- return strings .TrimSpace (out ), out , nil
202- }
203-
204196func debugCurlVerbose (t * testing.T , ctx context.Context , host , url string ) error {
205197 t .Helper ()
206198 script := `curl -v --connect-timeout 2 --max-time 5 -H "Host: $1" "$2" || true`
@@ -226,7 +218,7 @@ func requireHTTPRedirectEventually(t *testing.T, ctx context.Context, host, url
226218 var lastErr error
227219
228220 for attempt := 1 ; time .Now ().Before (deadline ); attempt ++ {
229- code , location , out , err := curlHTTPRedirectFromClient (ctx , host , url )
221+ code , location , out , err := curlHTTPRedirectFromClient (ctx , host , url , false )
230222 lastCode , lastLocation , lastOut , lastErr = code , location , out , err
231223
232224 codeTrimmed := strings .TrimSpace (code )
@@ -250,8 +242,8 @@ func requireHTTPRedirectEventually(t *testing.T, ctx context.Context, host, url
250242 expectedCode , host , url , timeout , strings .TrimSpace (lastCode ), lastLocation , lastErr , lastOut )
251243}
252244
253- // requireHTTPS200Eventually waits for an HTTPS 200 response using insecure curl (-k flag).
254- func requireHTTPS200Eventually (t * testing.T , ctx context.Context , host , url string , timeout time.Duration ) {
245+ // requireHTTP200OverHTTPSEventually waits for HTTP 200 status code over an HTTPS connection using insecure curl (-k flag).
246+ func requireHTTP200OverHTTPSEventually (t * testing.T , ctx context.Context , host , url string , timeout time.Duration ) {
255247 t .Helper ()
256248
257249 deadline := time .Now ().Add (timeout )
@@ -262,15 +254,15 @@ func requireHTTPS200Eventually(t *testing.T, ctx context.Context, host, url stri
262254 var lastErr error
263255
264256 for attempt := 1 ; time .Now ().Before (deadline ); attempt ++ {
265- code , out , err := curlHTTPS200FromClient (ctx , host , url )
257+ code , _ , out , err := curlHTTPRedirectFromClient (ctx , host , url , true )
266258 lastCode , lastOut , lastErr = code , out , err
267259
268260 if err == nil && strings .TrimSpace (code ) == "200" {
269261 return
270262 }
271263
272264 if attempt == 1 || attempt % 10 == 0 {
273- t .Logf ("waiting for HTTPS 200 (attempt=%d host=%s url=%s): code=%q err=%v" ,
265+ t .Logf ("waiting for HTTP 200 over HTTPS (attempt=%d host=%s url=%s): code=%q err=%v" ,
274266 attempt , host , url , strings .TrimSpace (code ), err )
275267 }
276268 time .Sleep (interval )
@@ -297,7 +289,7 @@ func requireHTTPS200Eventually(t *testing.T, ctx context.Context, host, url stri
297289 )
298290 t .Logf ("debug curl -kv output:\n %s" , out )
299291
300- t .Fatalf ("timed out waiting for HTTPS 200 (host=%s url=%s timeout=%s). lastCode=%q lastErr=%v lastOut=%s" ,
292+ t .Fatalf ("timed out waiting for HTTP 200 over HTTPS (host=%s url=%s timeout=%s). lastCode=%q lastErr=%v lastOut=%s" ,
301293 host , url , timeout , strings .TrimSpace (lastCode ), lastErr , lastOut )
302294}
303295
0 commit comments