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
94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
// Copyright © 2023 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package identity
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gofrs/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/ory/kratos/x"
|
|
)
|
|
|
|
func TestNewRecoveryEmailAddress(t *testing.T) {
|
|
iid := x.NewUUID()
|
|
a := NewRecoveryEmailAddress("foo@ory.sh", iid)
|
|
|
|
assert.Equal(t, a.Value, "foo@ory.sh")
|
|
assert.Equal(t, a.Via, AddressTypeEmail)
|
|
assert.Equal(t, iid, a.IdentityID)
|
|
assert.Equal(t, uuid.Nil, a.ID)
|
|
}
|
|
|
|
// TestRecoveryAddress_Hash tests that the hash considers all fields that are
|
|
// written to the database (ignoring some well-known fields like the ID or
|
|
// timestamps).
|
|
func TestRecoveryAddress_Hash(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
a RecoveryAddress
|
|
}{
|
|
{
|
|
name: "full fields",
|
|
a: RecoveryAddress{
|
|
ID: x.NewUUID(),
|
|
Value: "foo@bar.me",
|
|
Via: AddressTypeEmail,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
IdentityID: x.NewUUID(),
|
|
NID: x.NewUUID(),
|
|
},
|
|
},
|
|
{
|
|
name: "empty fields",
|
|
a: RecoveryAddress{},
|
|
},
|
|
{
|
|
name: "email constructor",
|
|
a: *NewRecoveryEmailAddress("foo@ory.sh", x.NewUUID()),
|
|
},
|
|
{
|
|
name: "full fields",
|
|
a: RecoveryAddress{
|
|
ID: x.NewUUID(),
|
|
Value: "6502530000",
|
|
Via: AddressTypeSMS,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
IdentityID: x.NewUUID(),
|
|
NID: x.NewUUID(),
|
|
},
|
|
},
|
|
{
|
|
name: "SMS constructor",
|
|
a: *NewRecoverySMSAddress("6502530000", x.NewUUID()),
|
|
},
|
|
{
|
|
name: "break glass for organization",
|
|
a: RecoveryAddress{
|
|
ID: x.NewUUID(),
|
|
Value: "breakglass@ory.sh",
|
|
Via: AddressTypeEmail,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
IdentityID: x.NewUUID(),
|
|
NID: x.NewUUID(),
|
|
BreakGlassForOrganization: uuid.NullUUID{UUID: x.NewUUID(), Valid: true},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run("case="+tc.name, func(t *testing.T) {
|
|
assert.Equal(t,
|
|
reflectiveHash(tc.a),
|
|
tc.a.Signature(),
|
|
)
|
|
})
|
|
}
|
|
}
|