File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 4
4
"context"
5
5
"reflect"
6
6
7
+ "github.com/ory/kratos/driver/config"
8
+
7
9
"github.com/gofrs/uuid"
8
10
9
11
"github.com/mohae/deepcopy"
@@ -21,6 +23,7 @@ var ErrProtectedFieldModified = herodot.ErrForbidden.
21
23
22
24
type (
23
25
managerDependencies interface {
26
+ config.Provider
24
27
PoolProvider
25
28
courier.Provider
26
29
ValidationProvider
@@ -62,6 +65,10 @@ func newManagerOptions(opts []ManagerOption) *managerOptions {
62
65
}
63
66
64
67
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
+
65
72
o := newManagerOptions (opts )
66
73
if err := m .validate (ctx , i , o ); err != nil {
67
74
return err
Original file line number Diff line number Diff line change 4
4
"context"
5
5
"fmt"
6
6
"testing"
7
+ "time"
8
+
9
+ "github.com/ory/x/sqlxx"
7
10
8
11
"github.com/ory/kratos/internal/testhelpers"
9
12
@@ -250,3 +253,23 @@ func TestManager(t *testing.T) {
250
253
})
251
254
})
252
255
}
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
+ }
You can’t perform that action at this time.
0 commit comments