summaryrefslogtreecommitdiff
path: root/pkg/oidc/oidc_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/oidc/oidc_test.go')
-rw-r--r--pkg/oidc/oidc_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/oidc/oidc_test.go b/pkg/oidc/oidc_test.go
new file mode 100644
index 0000000..ef6a4f6
--- /dev/null
+++ b/pkg/oidc/oidc_test.go
@@ -0,0 +1,49 @@
+package oidc
+
+import (
+ "context"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+ "github.com/xlgmokha/x/pkg/serde"
+)
+
+func TestOpenID(t *testing.T) {
+ t.Run("GET /.well-known/openid-configuration", func(t *testing.T) {
+ srv := httptest.NewServer(nil)
+ srv.Config = &http.Server{
+ Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ require.Equal(t, "/.well-known/openid-configuration", r.URL.Path)
+ require.NoError(t, serde.ToJSON(w, &Metadata{
+ AuthorizationEndpoint: srv.URL + "/authorize",
+ ClaimsSupported: []string{"aud"},
+ CodeChallengeMethodsSupported: []string{"plain"},
+ DeviceAuthorizationEndpoint: srv.URL + "/device/authorize",
+ IDTokenSigningAlgValuesSupported: []string{"RS256"},
+ Issuer: srv.URL,
+ JWKSURI: srv.URL + "/jwks",
+ MFAChallengeEndpoint: srv.URL + "/mfa",
+ RegistrationEndpoint: srv.URL + "/users/new",
+ RequestURIParameterSupported: false,
+ ResponseModesSupported: []string{"query"},
+ ResponseTypeSupported: []string{"code"},
+ RevocationEndpoint: srv.URL + "/revoke",
+ ScopesSupported: []string{"oidc"},
+ SubjectTypesSupported: []string{"public"},
+ TokenEndpoint: srv.URL + "/token",
+ TokenEndpointAuthMethodsSupported: []string{"client_secret_post"},
+ UserInfoEndpoint: srv.URL + "/users/me",
+ }))
+ }),
+ }
+ defer srv.Close()
+
+ openID, err := New(context.Background(), srv.URL, "client_id", "client_secret", "https://example.com/oauth/callback")
+ require.NoError(t, err)
+
+ assert.Equal(t, srv.URL+"/authorize", openID.Provider.Endpoint().AuthURL)
+ })
+}