summaryrefslogtreecommitdiff
path: root/pkg/authz/id_token_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/authz/id_token_test.go')
-rw-r--r--pkg/authz/id_token_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/authz/id_token_test.go b/pkg/authz/id_token_test.go
new file mode 100644
index 0000000..22aabc4
--- /dev/null
+++ b/pkg/authz/id_token_test.go
@@ -0,0 +1,30 @@
+package authz
+
+import (
+ "testing"
+
+ "github.com/oauth2-proxy/mockoidc"
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web"
+)
+
+func TestIDToken(t *testing.T) {
+ idp := web.NewOIDCServer(t)
+ defer idp.Close()
+
+ t.Run("when the token is valid", func(t *testing.T) {
+ user := mockoidc.DefaultUser()
+ _, rawIDToken := idp.CreateTokensFor(user)
+ token, err := NewIDToken(rawIDToken)
+
+ require.NoError(t, err)
+ require.NotNil(t, token)
+ })
+
+ t.Run("when the token is invalid", func(t *testing.T) {
+ token, err := NewIDToken("invalid")
+
+ require.Error(t, err)
+ require.Nil(t, token)
+ })
+}