Repository navigation
containerinfra: Fix wrong HTTP method and path in certificate create test - #3946
Conversation
I think this analysis is wrong. go 1.22 is pretty old at this point. The test is clearly broken though, and it fails reliably in my environment. It might be more likely that this test is simply not running in CI? Later: Hmm, no, the test is running here alright 😕 From the latest run:
(That test is the sole caller of Later again: okay, it's a change in the redirect behavior in go 1.26. Updating the commit message now. |
…test
The HandleCreateCertificateSuccessfully fixture registered its handler
at "/v1/certificates/" (with trailing slash) and asserted the request
method was GET, but certificates.Create issues a POST to
"/v1/certificates" (without trailing slash).
This worked by accident prior to Go 1.26: the ServeMux redirected
requests from "/v1/certificates" to "/v1/certificates/" via 301, and
Go's HTTP client changed POST to GET when following a 301 redirect. Go
1.26 changed these trailing-slash redirects to use 307 instead [1],
which preserves the original method, so POST now arrives at the handler
unchanged and the incorrect assertion fails.
Fix by matching the actual URL ("/v1/certificates", no trailing slash)
and asserting the correct method (POST).
[1] https://go.dev/doc/go1.26
Signed-off-by: Stephen Finucane <[email protected]>
Assisted-By: Claude Opus 4.6 <[email protected]>
91714b2 to
47354d2
Compare
Ok, this explains everything now. after @kayrus pushed a PR for this, I did some tests locally and wasn't getting why this was working with go 1.25 without the trailing slash but with 1.26 it was failing either way. good catch 👌 |
The
HandleCreateCertificateSuccessfullyfixture registered its handler at/v1/certificates/(with trailing slash) and asserted the request method wasGET, butcertificates.Createissues aPOSTto/v1/certificates(without trailing slash).This worked by accident prior to Go 1.26: the
ServeMuxredirected requests from/v1/certificatesto/v1/certificates/via 301, and Go's HTTP client changedPOSTtoGETwhen following a 301 redirect. Go 1.26 changed these trailing-slash redirects to use 307 instead, which preserves the original method, soPOSTnow arrives at the handler unchanged and the incorrect assertion fails.Fix by matching the actual URL (
/v1/certificates, no trailing slash) and asserting the correct method (POST).Fixes #3898