Skip to content

Commit f43396b

Browse files
authored
fix: unable to find JSON Schema ID: default (#2393)
1 parent f09b1b3 commit f43396b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

identity/manager.go

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"reflect"
66

7+
"github.com/ory/kratos/driver/config"
8+
79
"github.com/gofrs/uuid"
810

911
"github.com/mohae/deepcopy"
@@ -21,6 +23,7 @@ var ErrProtectedFieldModified = herodot.ErrForbidden.
2123

2224
type (
2325
managerDependencies interface {
26+
config.Provider
2427
PoolProvider
2528
courier.Provider
2629
ValidationProvider
@@ -62,6 +65,10 @@ func newManagerOptions(opts []ManagerOption) *managerOptions {
6265
}
6366

6467
func (m *Manager) Create(ctx context.Context, i *Identity, opts ...ManagerOption) error {
68+
if i.SchemaID == "" {
69+
i.SchemaID = m.r.Config(ctx).DefaultIdentityTraitsSchemaID()
70+
}
71+
6572
o := newManagerOptions(opts)
6673
if err := m.validate(ctx, i, o); err != nil {
6774
return err

identity/manager_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"context"
55
"fmt"
66
"testing"
7+
"time"
8+
9+
"github.com/ory/x/sqlxx"
710

811
"github.com/ory/kratos/internal/testhelpers"
912

@@ -250,3 +253,23 @@ func TestManager(t *testing.T) {
250253
})
251254
})
252255
}
256+
257+
func TestManagerNoDefaultNamedSchema(t *testing.T) {
258+
conf, reg := internal.NewFastRegistryWithMocks(t)
259+
conf.MustSet(config.ViperKeyDefaultIdentitySchemaID, "user_v0")
260+
conf.MustSet(config.ViperKeyIdentitySchemas, config.Schemas{
261+
{ID: "user_v0", URL: "file://./stub/manager.schema.json"},
262+
})
263+
conf.MustSet(config.ViperKeyPublicBaseURL, "https://www.ory.sh/")
264+
265+
t.Run("case=should create identity with default schema", func(t *testing.T) {
266+
stateChangedAt := sqlxx.NullTime(time.Now().UTC())
267+
original := &identity.Identity{
268+
SchemaID: "",
269+
Traits: []byte(identity.Traits(`{"email":"[email protected]"}`)),
270+
State: identity.StateActive,
271+
StateChangedAt: &stateChangedAt,
272+
}
273+
require.NoError(t, reg.IdentityManager().Create(context.Background(), original))
274+
})
275+
}

0 commit comments

Comments
 (0)