diff options
| -rw-r--r-- | app/middleware/id_token_test.go | 3 | ||||
| -rw-r--r-- | pkg/web/oidc_server.go (renamed from pkg/oidc/test_server.go) | 18 | ||||
| -rw-r--r-- | test/integration/container_test.go | 6 |
3 files changed, 13 insertions, 14 deletions
diff --git a/app/middleware/id_token_test.go b/app/middleware/id_token_test.go index 015ef0d..9b96a50 100644 --- a/app/middleware/id_token_test.go +++ b/app/middleware/id_token_test.go @@ -11,13 +11,12 @@ import ( "github.com/xlgmokha/x/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" 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/web" "golang.org/x/oauth2" ) func TestIDToken(t *testing.T) { - srv := oidc.NewTestServer(t) + srv := web.NewOIDCServer(t) defer srv.Close() config := &oauth2.Config{ diff --git a/pkg/oidc/test_server.go b/pkg/web/oidc_server.go index 80f2c9a..31ef572 100644 --- a/pkg/oidc/test_server.go +++ b/pkg/web/oidc_server.go @@ -1,4 +1,4 @@ -package oidc +package web import ( "net/http" @@ -12,14 +12,14 @@ import ( "golang.org/x/oauth2" ) -type TestServer struct { +type OIDCServer struct { *mockoidc.MockOIDC *oauth2.Config *oidc.Provider *testing.T } -func NewTestServer(t *testing.T) *TestServer { +func NewOIDCServer(t *testing.T) *OIDCServer { srv, err := mockoidc.Run() require.NoError(t, err) @@ -32,7 +32,7 @@ func NewTestServer(t *testing.T) *TestServer { provider, err := oidc.NewProvider(t.Context(), srv.Issuer()) require.NoError(t, err) - return &TestServer{ + return &OIDCServer{ srv, &oauth2.Config{ ClientID: srv.ClientID, @@ -46,7 +46,7 @@ func NewTestServer(t *testing.T) *TestServer { } } -func (srv *TestServer) CreateAuthorizationCodeFor(user mockoidc.User) string { +func (srv *OIDCServer) CreateAuthorizationCodeFor(user mockoidc.User) string { code := strconv.FormatInt(time.Now().Unix(), 10) srv.QueueUser(user) srv.QueueCode(code) @@ -56,21 +56,21 @@ func (srv *TestServer) CreateAuthorizationCodeFor(user mockoidc.User) string { return code } -func (srv *TestServer) CreateTokenFor(user mockoidc.User) *oauth2.Token { +func (srv *OIDCServer) CreateTokenFor(user mockoidc.User) *oauth2.Token { code := srv.CreateAuthorizationCodeFor(user) token, err := srv.Exchange(srv.Context(), code) require.NoError(srv, err) return token } -func (srv *TestServer) CreateTokensFor(user mockoidc.User) (*oauth2.Token, string) { +func (srv *OIDCServer) CreateTokensFor(user mockoidc.User) (*oauth2.Token, string) { token := srv.CreateTokenFor(user) rawIDToken, ok := token.Extra("id_token").(string) require.True(srv, ok) return token, rawIDToken } -func (srv *TestServer) Verify(rawIDToken string) *oidc.IDToken { +func (srv *OIDCServer) Verify(rawIDToken string) *oidc.IDToken { idToken, err := srv. Verifier(&oidc.Config{ClientID: srv.MockOIDC.Config().ClientID}). Verify(srv.Context(), rawIDToken) @@ -79,6 +79,6 @@ func (srv *TestServer) Verify(rawIDToken string) *oidc.IDToken { return idToken } -func (s *TestServer) Close() { +func (s *OIDCServer) Close() { s.Shutdown() } diff --git a/test/integration/container_test.go b/test/integration/container_test.go index 4768c98..73724fb 100644 --- a/test/integration/container_test.go +++ b/test/integration/container_test.go @@ -14,10 +14,10 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/xlgmokha/x/pkg/env" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web" ) -func environmentVariables(srv *oidc.TestServer) map[string]string { +func environmentVariables(srv *web.OIDCServer) map[string]string { return map[string]string{ "APP_ENV": "test", "DEBUG": env.Fetch("DEBUG", ""), @@ -32,7 +32,7 @@ func TestContainer(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() - srv := oidc.NewTestServer(t) + srv := web.NewOIDCServer(t) defer srv.Close() container := NewContainer(t, ctx, environmentVariables(srv)) |
