Skip to content

Commit

Permalink
fix: unable to find JSON Schema ID: default (#2393)
Browse files Browse the repository at this point in the history
  • Loading branch information
splaunov authored Jul 12, 2022
1 parent f09b1b3 commit f43396b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions identity/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"reflect"

"github.com/ory/kratos/driver/config"

"github.com/gofrs/uuid"

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

type (
managerDependencies interface {
config.Provider
PoolProvider
courier.Provider
ValidationProvider
Expand Down Expand Up @@ -62,6 +65,10 @@ func newManagerOptions(opts []ManagerOption) *managerOptions {
}

func (m *Manager) Create(ctx context.Context, i *Identity, opts ...ManagerOption) error {
if i.SchemaID == "" {
i.SchemaID = m.r.Config(ctx).DefaultIdentityTraitsSchemaID()
}

o := newManagerOptions(opts)
if err := m.validate(ctx, i, o); err != nil {
return err
Expand Down
23 changes: 23 additions & 0 deletions identity/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/ory/x/sqlxx"

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

Expand Down Expand Up @@ -250,3 +253,23 @@ func TestManager(t *testing.T) {
})
})
}

func TestManagerNoDefaultNamedSchema(t *testing.T) {
conf, reg := internal.NewFastRegistryWithMocks(t)
conf.MustSet(config.ViperKeyDefaultIdentitySchemaID, "user_v0")
conf.MustSet(config.ViperKeyIdentitySchemas, config.Schemas{
{ID: "user_v0", URL: "file://./stub/manager.schema.json"},
})
conf.MustSet(config.ViperKeyPublicBaseURL, "https://www.ory.sh/")

t.Run("case=should create identity with default schema", func(t *testing.T) {
stateChangedAt := sqlxx.NullTime(time.Now().UTC())
original := &identity.Identity{
SchemaID: "",
Traits: []byte(identity.Traits(`{"email":"[email protected]"}`)),
State: identity.StateActive,
StateChangedAt: &stateChangedAt,
}
require.NoError(t, reg.IdentityManager().Create(context.Background(), original))
})
}

0 comments on commit f43396b

Please sign in to comment.