diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-17 14:08:18 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-17 14:08:18 -0600 |
| commit | 62c24d360745ef8778a322c276a9ad577dfc7713 (patch) | |
| tree | a93eb5de35fb283bfa014bd3c23094017a2e72c4 /pkg/web/middleware | |
| parent | 81d3482b6937617ba3fd778a42d2fbbbf0b8e2b7 (diff) | |
refactor: move context keys to key package
Diffstat (limited to 'pkg/web/middleware')
| -rw-r--r-- | pkg/web/middleware/unpack_token.go | 3 | ||||
| -rw-r--r-- | pkg/web/middleware/unpack_token_test.go | 7 |
2 files changed, 6 insertions, 4 deletions
diff --git a/pkg/web/middleware/unpack_token.go b/pkg/web/middleware/unpack_token.go index 949934b..914f405 100644 --- a/pkg/web/middleware/unpack_token.go +++ b/pkg/web/middleware/unpack_token.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/xlgmokha/x/pkg/log" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" ) @@ -36,7 +37,7 @@ func UnpackToken(cfg *oidc.OpenID) func(http.Handler) http.Handler { log.WithFields(r.Context(), log.Fields{"id_token": idToken}) next.ServeHTTP( w, - r.WithContext(oidc.IDTokenKey.With(r.Context(), idToken)), + r.WithContext(key.IDTokenKey.With(r.Context(), idToken)), ) }) } diff --git a/pkg/web/middleware/unpack_token_test.go b/pkg/web/middleware/unpack_token_test.go index 814aa79..1405d6d 100644 --- a/pkg/web/middleware/unpack_token_test.go +++ b/pkg/web/middleware/unpack_token_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/xlgmokha/x/pkg/log" "github.com/xlgmokha/x/pkg/x" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web" @@ -46,7 +47,7 @@ func TestUnpackToken(t *testing.T) { encoded := x.Must(tokens.ToBase64String()) server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - token := oidc.IDTokenKey.From(r.Context()) + token := key.IDTokenKey.From(r.Context()) require.NotNil(t, token) assert.Equal(t, user.Subject, token.Subject) @@ -67,7 +68,7 @@ func TestUnpackToken(t *testing.T) { t.Run("when an invalid session cookie is provided", func(t *testing.T) { t.Run("forwards the request", func(t *testing.T) { server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Nil(t, oidc.IDTokenKey.From(r.Context())) + require.Nil(t, key.IDTokenKey.From(r.Context())) w.WriteHeader(http.StatusTeapot) })) @@ -86,7 +87,7 @@ func TestUnpackToken(t *testing.T) { t.Run("when no cookies are provided", func(t *testing.T) { t.Run("forwards the request", func(t *testing.T) { server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Nil(t, oidc.IDTokenKey.From(r.Context())) + require.Nil(t, key.IDTokenKey.From(r.Context())) w.WriteHeader(http.StatusTeapot) })) |
