snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
94
selfservice/strategy/oidc/provider_generic_test.go
Normal file
94
selfservice/strategy/oidc/provider_generic_test.go
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package oidc_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ory/kratos/driver"
|
||||
"github.com/ory/kratos/driver/config"
|
||||
"github.com/ory/kratos/pkg"
|
||||
"github.com/ory/kratos/selfservice/flow/login"
|
||||
"github.com/ory/kratos/selfservice/strategy/oidc"
|
||||
"github.com/ory/kratos/x"
|
||||
"github.com/ory/x/configx"
|
||||
)
|
||||
|
||||
func makeOIDCClaims() json.RawMessage {
|
||||
claims, _ := json.Marshal(map[string]interface{}{
|
||||
"id_token": map[string]interface{}{
|
||||
"email": map[string]bool{
|
||||
"essential": true,
|
||||
},
|
||||
"email_verified": map[string]bool{
|
||||
"essential": true,
|
||||
},
|
||||
},
|
||||
})
|
||||
return claims
|
||||
}
|
||||
|
||||
func makeAuthCodeURL(t *testing.T, r *login.Flow, reg *driver.RegistryDefault) string {
|
||||
p := oidc.NewProviderGenericOIDC(&oidc.Configuration{
|
||||
Provider: "generic",
|
||||
ID: "valid",
|
||||
ClientID: "client",
|
||||
ClientSecret: "secret",
|
||||
IssuerURL: "https://accounts.google.com",
|
||||
Mapper: "file://./stub/hydra.schema.json",
|
||||
RequestedClaims: makeOIDCClaims(),
|
||||
}, reg)
|
||||
c, err := p.(oidc.OAuth2Provider).OAuth2(t.Context())
|
||||
require.NoError(t, err)
|
||||
return c.AuthCodeURL("state", p.(oidc.OAuth2Provider).AuthCodeURLOptions(r)...)
|
||||
}
|
||||
|
||||
func TestProviderGenericOIDC_AddAuthCodeURLOptions(t *testing.T) {
|
||||
conf, reg := pkg.NewFastRegistryWithMocks(t,
|
||||
configx.WithValue(config.ViperKeyPublicBaseURL, "https://ory.sh"))
|
||||
t.Run("case=redirectURI is public base url", func(t *testing.T) {
|
||||
r := &login.Flow{ID: x.NewUUID(), Refresh: true}
|
||||
actual, err := url.ParseRequestURI(makeAuthCodeURL(t, r, reg))
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, actual.Query().Get("redirect_uri"), "https://ory.sh")
|
||||
})
|
||||
|
||||
t.Run("case=redirectURI is public base url", func(t *testing.T) {
|
||||
conf.MustSet(t.Context(), config.ViperKeyOIDCBaseRedirectURL, "https://example.org")
|
||||
t.Cleanup(func() {
|
||||
conf.MustSet(t.Context(), config.ViperKeyOIDCBaseRedirectURL, nil)
|
||||
})
|
||||
r := &login.Flow{ID: x.NewUUID(), Refresh: true}
|
||||
actual, err := url.ParseRequestURI(makeAuthCodeURL(t, r, reg))
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, actual.Query().Get("redirect_uri"), "https://example.org")
|
||||
})
|
||||
|
||||
t.Run("case=expect prompt to be login with forced flag", func(t *testing.T) {
|
||||
r := &login.Flow{
|
||||
ID: x.NewUUID(),
|
||||
Refresh: true,
|
||||
}
|
||||
assert.Contains(t, makeAuthCodeURL(t, r, reg), "prompt=login")
|
||||
})
|
||||
|
||||
t.Run("case=expect prompt to not be login without forced flag", func(t *testing.T) {
|
||||
r := &login.Flow{
|
||||
ID: x.NewUUID(),
|
||||
}
|
||||
assert.NotContains(t, makeAuthCodeURL(t, r, reg), "prompt=login")
|
||||
})
|
||||
|
||||
t.Run("case=expect requested claims to be set", func(t *testing.T) {
|
||||
r := &login.Flow{
|
||||
ID: x.NewUUID(),
|
||||
}
|
||||
assert.Contains(t, makeAuthCodeURL(t, r, reg), "claims="+url.QueryEscape(string(makeOIDCClaims())))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user