diff options
Diffstat (limited to 'app/middleware')
| -rw-r--r-- | app/middleware/id_token.go | 4 | ||||
| -rw-r--r-- | app/middleware/id_token_test.go | 8 | ||||
| -rw-r--r-- | app/middleware/require_user.go | 4 | ||||
| -rw-r--r-- | app/middleware/require_user_test.go | 4 | ||||
| -rw-r--r-- | app/middleware/user.go | 6 | ||||
| -rw-r--r-- | app/middleware/user_test.go | 12 |
6 files changed, 19 insertions, 19 deletions
diff --git a/app/middleware/id_token.go b/app/middleware/id_token.go index a32c77b..da39f43 100644 --- a/app/middleware/id_token.go +++ b/app/middleware/id_token.go @@ -5,7 +5,7 @@ import ( "github.com/xlgmokha/x/pkg/log" "github.com/xlgmokha/x/pkg/x" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" + xcfg "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" ) @@ -43,7 +43,7 @@ func IDToken(cfg *oidc.OpenID) func(http.Handler) http.Handler { log.WithFields(r.Context(), log.Fields{"id_token": idToken}) next.ServeHTTP( w, - r.WithContext(key.IDToken.With(r.Context(), idToken)), + r.WithContext(xcfg.IDToken.With(r.Context(), idToken)), ) return } diff --git a/app/middleware/id_token_test.go b/app/middleware/id_token_test.go index 4f26cdf..607c028 100644 --- a/app/middleware/id_token_test.go +++ b/app/middleware/id_token_test.go @@ -12,7 +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" + xcfg "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "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" @@ -47,7 +47,7 @@ func TestIDToken(t *testing.T) { encoded := x.Must(tokens.ToBase64String()) server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - token := key.IDToken.From(r.Context()) + token := xcfg.IDToken.From(r.Context()) require.NotNil(t, token) assert.Equal(t, user.Subject, token.Subject) @@ -68,7 +68,7 @@ func TestIDToken(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.IDToken.From(r.Context())) + require.Nil(t, xcfg.IDToken.From(r.Context())) w.WriteHeader(http.StatusTeapot) })) @@ -87,7 +87,7 @@ func TestIDToken(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.IDToken.From(r.Context())) + require.Nil(t, xcfg.IDToken.From(r.Context())) w.WriteHeader(http.StatusTeapot) })) diff --git a/app/middleware/require_user.go b/app/middleware/require_user.go index e81d5b5..8df4fd7 100644 --- a/app/middleware/require_user.go +++ b/app/middleware/require_user.go @@ -4,13 +4,13 @@ import ( "net/http" "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/app/cfg" ) func RequireUser(code int, url string) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - user := key.CurrentUser.From(r.Context()) + user := cfg.CurrentUser.From(r.Context()) if x.IsZero(user) { http.Redirect(w, r, url, code) return diff --git a/app/middleware/require_user_test.go b/app/middleware/require_user_test.go index 68b9911..17c0276 100644 --- a/app/middleware/require_user_test.go +++ b/app/middleware/require_user_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) @@ -30,7 +30,7 @@ func TestRequireUser(t *testing.T) { t.Run("when a user is logged in", func(t *testing.T) { t.Run("forwards the request", func(t *testing.T) { - r, w := test.RequestResponse("GET", "/example", test.WithContextKeyValue(t.Context(), key.CurrentUser, &domain.User{})) + r, w := test.RequestResponse("GET", "/example", test.WithContextKeyValue(t.Context(), cfg.CurrentUser, &domain.User{})) server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusTeapot) diff --git a/app/middleware/user.go b/app/middleware/user.go index 194ded6..e2f1ce3 100644 --- a/app/middleware/user.go +++ b/app/middleware/user.go @@ -6,15 +6,15 @@ import ( "github.com/xlgmokha/x/pkg/log" "github.com/xlgmokha/x/pkg/mapper" "github.com/xlgmokha/x/pkg/x" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" ) func User(db domain.Repository[*domain.User]) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - idToken := key.IDToken.From(r.Context()) + idToken := cfg.IDToken.From(r.Context()) if x.IsZero(idToken) { next.ServeHTTP(w, r) return @@ -30,7 +30,7 @@ func User(db domain.Repository[*domain.User]) func(http.Handler) http.Handler { } } - next.ServeHTTP(w, r.WithContext(key.CurrentUser.With(r.Context(), user))) + next.ServeHTTP(w, r.WithContext(cfg.CurrentUser.With(r.Context(), user))) }) } } diff --git a/app/middleware/user_test.go b/app/middleware/user_test.go index e6c74d8..3e2425c 100644 --- a/app/middleware/user_test.go +++ b/app/middleware/user_test.go @@ -6,9 +6,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/db" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" - "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/pls" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" @@ -24,14 +24,14 @@ func TestUser(t *testing.T) { t.Run("when ID Token is provided", func(t *testing.T) { t.Run("when user is known", func(t *testing.T) { server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - user := key.CurrentUser.From(r.Context()) + user := cfg.CurrentUser.From(r.Context()) require.NotNil(t, user) assert.Equal(t, knownUser.ID, user.ID) w.WriteHeader(http.StatusTeapot) })) - ctx := key.IDToken.With(t.Context(), &oidc.IDToken{Subject: knownUser.ID.String()}) + ctx := cfg.IDToken.With(t.Context(), &oidc.IDToken{Subject: knownUser.ID.String()}) r, w := test.RequestResponse("GET", "/example", test.WithContext(ctx)) server.ServeHTTP(w, r) @@ -43,14 +43,14 @@ func TestUser(t *testing.T) { unknownID := pls.GenerateULID() server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - user := key.CurrentUser.From(r.Context()) + user := cfg.CurrentUser.From(r.Context()) require.NotNil(t, user) assert.Equal(t, domain.ID(unknownID), user.ID) w.WriteHeader(http.StatusTeapot) })) - ctx := key.IDToken.With(t.Context(), &oidc.IDToken{Subject: unknownID}) + ctx := cfg.IDToken.With(t.Context(), &oidc.IDToken{Subject: unknownID}) r, w := test.RequestResponse("GET", "/example", test.WithContext(ctx)) server.ServeHTTP(w, r) @@ -62,7 +62,7 @@ func TestUser(t *testing.T) { t.Run("when ID Token is not provided", func(t *testing.T) { server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - user := key.CurrentUser.From(r.Context()) + user := cfg.CurrentUser.From(r.Context()) require.Nil(t, user) w.WriteHeader(http.StatusTeapot) |
