summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/dashboard/controller.go2
-rw-r--r--app/controllers/dashboard/controller_test.go2
-rw-r--r--pkg/key/init.go4
-rw-r--r--pkg/web/middleware/unpack_token.go2
-rw-r--r--pkg/web/middleware/unpack_token_test.go6
5 files changed, 8 insertions, 8 deletions
diff --git a/app/controllers/dashboard/controller.go b/app/controllers/dashboard/controller.go
index b27ebe1..184a8ed 100644
--- a/app/controllers/dashboard/controller.go
+++ b/app/controllers/dashboard/controller.go
@@ -20,7 +20,7 @@ func (c *Controller) MountTo(mux *http.ServeMux) {
}
func (c *Controller) Show(w http.ResponseWriter, r *http.Request) {
- currentUser := key.CurrentUserKey.From(r.Context())
+ currentUser := key.CurrentUser.From(r.Context())
if x.IsZero(currentUser) {
http.Redirect(w, r, "/", http.StatusFound)
diff --git a/app/controllers/dashboard/controller_test.go b/app/controllers/dashboard/controller_test.go
index b8199c4..01e3ff6 100644
--- a/app/controllers/dashboard/controller_test.go
+++ b/app/controllers/dashboard/controller_test.go
@@ -30,7 +30,7 @@ func TestController(t *testing.T) {
t.Run("when authenticated", func(t *testing.T) {
t.Run("renders a dashboard page", func(t *testing.T) {
- ctx := key.CurrentUserKey.With(t.Context(), &domain.User{})
+ ctx := key.CurrentUser.With(t.Context(), &domain.User{})
r, w := test.RequestResponse("GET", "/dashboard", test.WithContext(ctx))
mux.ServeHTTP(w, r)
diff --git a/pkg/key/init.go b/pkg/key/init.go
index 01d8a3d..f2d7b7f 100644
--- a/pkg/key/init.go
+++ b/pkg/key/init.go
@@ -6,5 +6,5 @@ import (
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc"
)
-var CurrentUserKey context.Key[*domain.User] = context.Key[*domain.User]("current_user")
-var IDTokenKey context.Key[*oidc.IDToken] = context.Key[*oidc.IDToken]("id_token")
+var CurrentUser context.Key[*domain.User] = context.Key[*domain.User]("current_user")
+var IDToken context.Key[*oidc.IDToken] = context.Key[*oidc.IDToken]("id_token")
diff --git a/pkg/web/middleware/unpack_token.go b/pkg/web/middleware/unpack_token.go
index 914f405..db04e0e 100644
--- a/pkg/web/middleware/unpack_token.go
+++ b/pkg/web/middleware/unpack_token.go
@@ -37,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(key.IDTokenKey.With(r.Context(), idToken)),
+ r.WithContext(key.IDToken.With(r.Context(), idToken)),
)
})
}
diff --git a/pkg/web/middleware/unpack_token_test.go b/pkg/web/middleware/unpack_token_test.go
index 1405d6d..f2250bc 100644
--- a/pkg/web/middleware/unpack_token_test.go
+++ b/pkg/web/middleware/unpack_token_test.go
@@ -47,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 := key.IDTokenKey.From(r.Context())
+ token := key.IDToken.From(r.Context())
require.NotNil(t, token)
assert.Equal(t, user.Subject, token.Subject)
@@ -68,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, key.IDTokenKey.From(r.Context()))
+ require.Nil(t, key.IDToken.From(r.Context()))
w.WriteHeader(http.StatusTeapot)
}))
@@ -87,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, key.IDTokenKey.From(r.Context()))
+ require.Nil(t, key.IDToken.From(r.Context()))
w.WriteHeader(http.StatusTeapot)
}))