summaryrefslogtreecommitdiff
path: root/app/controllers/sessions/controller_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/sessions/controller_test.go')
-rw-r--r--app/controllers/sessions/controller_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/controllers/sessions/controller_test.go b/app/controllers/sessions/controller_test.go
index 6dcb3f3..9b701d6 100644
--- a/app/controllers/sessions/controller_test.go
+++ b/app/controllers/sessions/controller_test.go
@@ -3,6 +3,7 @@ package sessions
import (
"encoding/base64"
"encoding/json"
+ "fmt"
"net/http"
"net/url"
"testing"
@@ -10,6 +11,7 @@ import (
"github.com/oauth2-proxy/mockoidc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/xlgmokha/x/pkg/serde"
"github.com/xlgmokha/x/pkg/test"
"github.com/xlgmokha/x/pkg/x"
xcfg "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg"
@@ -190,6 +192,31 @@ func TestSessions(t *testing.T) {
})
})
+ t.Run("GET /session", func(t *testing.T) {
+ t.Run("with an id_token cookie", func(t *testing.T) {
+ user := mockoidc.DefaultUser()
+ _, rawIDToken := srv.CreateTokensFor(user)
+ cookie := &http.Cookie{Name: xcfg.IDTokenCookie, Value: rawIDToken}
+ r, w := test.RequestResponse("GET", "/session", test.WithCookie(cookie))
+
+ mux.ServeHTTP(w, r)
+
+ require.Equal(t, http.StatusOK, w.Code)
+ items, err := serde.FromJSON[map[string]interface{}](w.Body)
+ require.NoError(t, err)
+ fmt.Printf("%v\n", items)
+ assert.Equal(t, srv.Issuer(), items["iss"])
+ })
+
+ t.Run("without an id_token cookie", func(t *testing.T) {
+ r, w := test.RequestResponse("GET", "/session")
+
+ mux.ServeHTTP(w, r)
+
+ require.Equal(t, http.StatusNotFound, w.Code)
+ })
+ })
+
t.Run("POST /session/destroy", func(t *testing.T) {
t.Run("clears the session cookie", func(t *testing.T) {
cookie := web.NewCookie(xcfg.SessionCookie, "value")