summaryrefslogtreecommitdiff
path: root/app/controllers/sessions/service_test.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-05-15 09:12:22 -0600
committermo khan <mo@mokhan.ca>2025-05-15 09:12:22 -0600
commit8e211ff4bac177465fb9adc0bfa3744ca4e1da47 (patch)
tree0b1e3006ca4f947d844a4f9411d4d10a41eef22e /app/controllers/sessions/service_test.go
parent564e140de454c78d7e6d34044bb78f53bd0b2bf3 (diff)
refactor: delete code that is now handled by envoy
Diffstat (limited to 'app/controllers/sessions/service_test.go')
-rw-r--r--app/controllers/sessions/service_test.go92
1 files changed, 0 insertions, 92 deletions
diff --git a/app/controllers/sessions/service_test.go b/app/controllers/sessions/service_test.go
deleted file mode 100644
index 05baa2f..0000000
--- a/app/controllers/sessions/service_test.go
+++ /dev/null
@@ -1,92 +0,0 @@
-package sessions
-
-import (
- "net/http"
- "testing"
-
- "github.com/oauth2-proxy/mockoidc"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "github.com/xlgmokha/x/pkg/test"
- 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/pls"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web"
-)
-
-func TestService(t *testing.T) {
- srv := oidc.NewTestServer(t)
- defer srv.Close()
-
- clientID := srv.MockOIDC.Config().ClientID
- clientSecret := srv.MockOIDC.Config().ClientSecret
- cfg := oidc.New(
- srv.Provider,
- clientID,
- clientSecret,
- "/session/callback",
- )
- svc := NewService(cfg, http.DefaultClient)
-
- t.Run("Exchange", func(t *testing.T) {
- t.Run("when the csrf token is missing", func(t *testing.T) {
- r := test.Request("GET", "/session/callback")
- tokens, err := svc.Exchange(r)
-
- require.Error(t, err)
- assert.Nil(t, tokens)
- })
-
- t.Run("when the csrf token is invalid", func(t *testing.T) {
- user := mockoidc.DefaultUser()
- code := srv.CreateAuthorizationCodeFor(user)
- nonce := pls.GenerateRandomHex(32)
-
- r := test.Request(
- "GET",
- "/session/callback?code="+code+"&state=invalid",
- test.WithCookie(web.NewCookie(xcfg.CSRFCookie, nonce)),
- )
- tokens, err := svc.Exchange(r)
-
- require.Error(t, err)
- assert.Nil(t, tokens)
- })
-
- t.Run("with an invalid authorization code grant", func(t *testing.T) {
- nonce := pls.GenerateRandomHex(32)
-
- r := test.Request(
- "GET", "/session/callback?code=invalid",
- test.WithCookie(web.NewCookie(xcfg.CSRFCookie, nonce)),
- )
-
- tokens, err := svc.Exchange(r)
-
- require.Error(t, err)
- assert.Nil(t, tokens)
- })
-
- t.Run("with a valid grant", func(t *testing.T) {
- user := mockoidc.DefaultUser()
- code := srv.CreateAuthorizationCodeFor(user)
- nonce := pls.GenerateRandomHex(32)
-
- r := test.Request(
- "GET",
- "/session/callback?code="+code+"&state="+nonce,
- test.WithCookie(web.NewCookie(xcfg.CSRFCookie, nonce)),
- )
-
- tokens, err := svc.Exchange(r)
-
- require.NoError(t, err)
- assert.NotNil(t, tokens)
- assert.NotEmpty(t, tokens.AccessToken)
- assert.NotEmpty(t, tokens.Expiry)
- assert.NotEmpty(t, tokens.TokenType)
- assert.NotEmpty(t, tokens.RefreshToken)
- assert.NotEmpty(t, tokens.IDToken)
- })
- })
-}