From 3cbfb6322616778c39f455f3a8cb4e0750a54ab6 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Fri, 9 Oct 2026 11:58:18 -0400 Subject: [PATCH] connect: fix flaky Test_validAuth header key collision The test authenticator kept request header casing, so X-SUBSTREAMS-Ll and x-substreams-ll collided once WithTrustedHeaders lower-cased them and map iteration order picked the winner. Lower-case keys like real authenticators do, and switch to stretchr/testify assert. --- go.mod | 1 - middleware/connect/authentication_test.go | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 37a1590..5d18e8e 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/streamingfast/logging v0.0.0-20220304214715-bc750a74b424 github.com/streamingfast/sf-tracing v0.0.0-20240209202324-9daa52c71a52 github.com/stretchr/testify v1.11.1 - github.com/test-go/testify v1.1.4 go.uber.org/zap v1.21.0 google.golang.org/grpc v1.77.0 google.golang.org/protobuf v1.36.10 diff --git a/middleware/connect/authentication_test.go b/middleware/connect/authentication_test.go index 10bb444..0d611b2 100644 --- a/middleware/connect/authentication_test.go +++ b/middleware/connect/authentication_test.go @@ -3,11 +3,12 @@ package server import ( "context" "net/http" + "strings" "testing" "github.com/streamingfast/dauth" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/test-go/testify/assert" ) type testAuthenticators struct { @@ -22,7 +23,9 @@ func (t testAuthenticators) Ready(_ context.Context) bool { func (t testAuthenticators) Authenticate(ctx context.Context, path string, headers map[string][]string, ipAddress string) (context.Context, error) { out := make(dauth.TrustedHeaders) for key, values := range headers { - out[key] = values[0] + // Lower-case like real authenticators do, otherwise "X-SUBSTREAMS-Ll" and "x-substreams-ll" + // collide in [dauth.WithTrustedHeaders] and the winner depends on map iteration order. + out[strings.ToLower(key)] = values[0] } out["x-substreams-ll"] = "987" out["x-user-id"] = "a1b2c3"