Skip to content

Commit 9778bbf

Browse files
committed
refactor: Improve auth middleware tests and add build constraints
- Update multiple auth headers test to verify specific expected value - Add build constraints to limit test support middleware to test/local builds - Clarify comment about http.Header.Get behavior with multiple headers
1 parent 1880b2a commit 9778bbf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

middleware/auth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ func TestStoreAuthHeader_WithEmptyAuthHeader(t *testing.T) {
7979
func TestStoreAuthHeader_MultipleAuthHeaders(t *testing.T) {
8080
// Test behavior when multiple authorization headers are present
8181
nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
82-
// Should get the first/combined value
82+
// Should get the first header value since http.Header.Get returns only the first value
8383
authFromContext, err := context.GetAuthHeaderFromContext(r.Context())
8484
assert.NoError(t, err)
85-
assert.NotEmpty(t, authFromContext)
85+
assert.Equal(t, "Bearer token1", authFromContext)
8686

8787
w.WriteHeader(http.StatusOK)
8888
})

middleware/test_support/local_middleware.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
//go:build test || local
2+
13
package local_middleware
24

35
import (
46
"net/http"
57

68
"github.com/go-jose/go-jose/v4"
79
"github.com/golang-jwt/jwt/v5"
10+
811
"github.com/platform-mesh/golang-commons/context"
912
)
1013

0 commit comments

Comments
 (0)