Skip to content

Agent Mesh

node: stop swapping http.DefaultTransport in the STS tests

Antonio Ojea60e8d3b3435d
diff --git a/internal/node/sts_test.go b/internal/node/sts_test.go
index 21fa80bd..0f8fab25 100644
--- a/internal/node/sts_test.go
+++ b/internal/node/sts_test.go
@@ -304,7 +304,11 @@ func TestNodeOAuthRevokeAndSyncRevocations(t *testing.T) {
}
revIDHex := hex.EncodeToString(parsedThird.RevocationIds()[0])
- cpServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ // A plaintext loopback control plane passes ValidateControlPlaneTransport,
+ // so the node's own client reaches cpServer without touching
+ // http.DefaultTransport, which every other test's background request
+ // also reads.
+ cpServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/revocations" {
http.NotFound(w, r)
return
@@ -317,11 +321,6 @@ func TestNodeOAuthRevokeAndSyncRevocations(t *testing.T) {
}))
defer cpServer.Close()
- // Point controlPlaneClient at cpServer by temporarily swapping http.DefaultTransport.
- origTransport := http.DefaultTransport
- http.DefaultTransport = cpServer.Client().Transport
- t.Cleanup(func() { http.DefaultTransport = origTransport })
-
if err := h.node.syncRevocations(context.Background(), cpServer.URL); err != nil {
t.Fatalf("syncRevocations: %v", err)
}
@@ -349,7 +348,7 @@ func TestWithCallerOrTokenAuthAndJWTExchange(t *testing.T) {
}
var exchangeCalls atomic.Int32
- cpServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ cpServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/token/exchange" {
exchangeCalls.Add(1)
payload, _ := proto.Marshal(&api.TokenExchangeResponse{
@@ -366,9 +365,6 @@ func TestWithCallerOrTokenAuthAndJWTExchange(t *testing.T) {
}))
defer cpServer.Close()
- origTransport := http.DefaultTransport
- http.DefaultTransport = cpServer.Client().Transport
- t.Cleanup(func() { http.DefaultTransport = origTransport })
if err := h.node.Store.SaveControlPlaneURL(cpServer.URL); err != nil {
t.Fatalf("SaveControlPlaneURL: %v", err)
}
@@ -430,7 +426,7 @@ func TestWithCallerOrTokenAuthAndJWTExchange(t *testing.T) {
func startFakeExchangeControlPlane(t *testing.T, h *stsNodeHarness, delegated []byte) *atomic.Int32 {
t.Helper()
var calls atomic.Int32
- cpServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ cpServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/token/exchange" {
http.NotFound(w, r)
return
@@ -467,9 +463,6 @@ func startFakeExchangeControlPlane(t *testing.T, h *stsNodeHarness, delegated []
_, _ = w.Write(payload)
}))
t.Cleanup(cpServer.Close)
- origTransport := http.DefaultTransport
- http.DefaultTransport = cpServer.Client().Transport
- t.Cleanup(func() { http.DefaultTransport = origTransport })
if err := h.node.Store.SaveControlPlaneURL(cpServer.URL); err != nil {
t.Fatalf("SaveControlPlaneURL: %v", err)
}