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:
55
courier/template/email/authenticator_key_added_test.go
Normal file
55
courier/template/email/authenticator_key_added_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright © 2026 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package email_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ory/kratos/courier/template/email"
|
||||
"github.com/ory/kratos/identity"
|
||||
"github.com/ory/kratos/pkg"
|
||||
"github.com/ory/kratos/x"
|
||||
)
|
||||
|
||||
func TestAuthenticatorKeyAdded(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
_, reg := pkg.NewFastRegistryWithMocks(t)
|
||||
|
||||
// Build the Identity map exactly as the courier does in production
|
||||
// (identity.Manager.sendIdentityNotifications uses x.StructToMap), so the
|
||||
// template's key lookup is tested against the real key casing instead of a
|
||||
// hand-crafted map. StructToMap marshals via JSON tags, so the ID lands under
|
||||
// the lowercase "id" key.
|
||||
id := &identity.Identity{ID: uuid.Must(uuid.FromString("00000000-0000-0000-0000-000000000001"))}
|
||||
idMap, err := x.StructToMap(id)
|
||||
require.NoError(t, err)
|
||||
|
||||
tpl := email.NewAuthenticatorKeyAdded(reg, &email.AuthenticatorKeyAddedModel{
|
||||
To: "owner@example.com",
|
||||
AddedAt: "2026-04-21T12:00:00Z",
|
||||
Identity: idMap,
|
||||
})
|
||||
|
||||
recipient, err := tpl.EmailRecipient()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "owner@example.com", recipient)
|
||||
|
||||
subject, err := tpl.EmailSubject(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, strings.ToLower(subject), "sign-in method")
|
||||
|
||||
body, err := tpl.EmailBody(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, body, "00000000-0000-0000-0000-000000000001", "the account ID must render in the email body")
|
||||
|
||||
plain, err := tpl.EmailBodyPlaintext(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, plain, "00000000-0000-0000-0000-000000000001", "the account ID must render in the plaintext body")
|
||||
assert.Contains(t, plain, "2026-04-21T12:00:00Z")
|
||||
}
|
||||
Reference in New Issue
Block a user