Files
upstream-ory-kratos/selfservice/strategy/code/strategy_recovery_nonrfc_flow_test.go
upstream-mirror c60cc7ca75
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
snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:19:12 +05:00

69 lines
2.2 KiB
Go

// Copyright © 2026 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package code_test
import (
"context"
"maps"
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/require"
"github.com/ory/kratos/driver/config"
"github.com/ory/kratos/identity"
"github.com/ory/kratos/pkg"
"github.com/ory/kratos/pkg/testhelpers"
"github.com/ory/x/configx"
)
// TestNonRFCRecoveryFullFlow drives account recovery end to end through the
// real router for an identity whose email is a schema-approved non-RFC carrier
// address, covering submission decode, address lookup, and courier queue.
func TestNonRFCRecoveryFullFlow(t *testing.T) {
t.Parallel()
ctx := context.Background()
cfg := map[string]any{
config.ViperKeySelfServiceRecoveryEnabled: true,
config.ViperKeySelfServiceRecoveryUse: "code",
}
maps.Copy(cfg, testhelpers.DefaultIdentitySchemaConfig("file://./stub/recovery.nonrfc.schema.json"))
maps.Copy(cfg, testhelpers.MethodEnableConfig(identity.CredentialsTypePassword, true))
maps.Copy(cfg, testhelpers.MethodEnableConfig(identity.CredentialsTypeCodeAuth, true))
conf, reg := pkg.NewFastRegistryWithMocks(t, configx.WithValues(cfg))
_ = testhelpers.NewRecoveryUIFlowEchoServer(t, reg)
_ = testhelpers.NewLoginUIFlowEchoServer(t, reg)
_ = testhelpers.NewSettingsUIFlowEchoServer(t, reg)
_ = testhelpers.NewErrorTestServer(t, reg)
public, _, _, _ := testhelpers.NewKratosServerWithCSRFAndRouters(t, reg)
const email = "foo.@docomo.ne.jp"
id := &identity.Identity{
Traits: identity.Traits(`{"email":"` + email + `"}`),
SchemaID: config.DefaultIdentityTraitsSchemaID,
State: identity.StateActive,
}
require.NoError(t, reg.IdentityManager().Create(ctx, id, identity.ManagerAllowWriteProtectedTraits))
client := testhelpers.NewClientWithCookies(t)
client.Transport = testhelpers.NewTransportWithLogger(http.DefaultTransport, t).RoundTripper
testhelpers.SubmitRecoveryForm(t, false, false, client, public,
func(v url.Values) {
v.Set("email", email)
v.Set("method", "code")
},
http.StatusOK,
conf.SelfServiceFlowRecoveryUI(ctx).String(),
)
msg := testhelpers.CourierExpectMessage(ctx, t, reg, email, "recover access to your account")
require.Equal(t, email, msg.Recipient)
}