From ae7863e51924a628cd66218b2a43a3b2074eba2b Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Thu, 6 Jul 2023 12:05:30 +0200 Subject: [PATCH] u --- .../sql/identity/persister_identity.go | 18 +++++--------- session/handler_test.go | 18 +++++++++++++- session/stub/identity.schema.json | 24 ++++++++++++++++++- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/persistence/sql/identity/persister_identity.go b/persistence/sql/identity/persister_identity.go index b276b0552f9b..e2f1d23a882f 100644 --- a/persistence/sql/identity/persister_identity.go +++ b/persistence/sql/identity/persister_identity.go @@ -482,11 +482,8 @@ func (p *IdentityPersister) HydrateIdentityAssociations(ctx context.Context, i * defer otelx.End(span, &err) var ( - con = p.GetConnection(ctx) - nid = p.NetworkID(ctx) - credentials map[identity.CredentialsType]identity.Credentials - verifiableAddresses []identity.VerifiableAddress - recoveryAddresses []identity.RecoveryAddress + con = p.GetConnection(ctx) + nid = p.NetworkID(ctx) ) eg, ctx := errgroup.WithContext(ctx) @@ -499,7 +496,7 @@ func (p *IdentityPersister) HydrateIdentityAssociations(ctx context.Context, i * if err := con.WithContext(ctx). Where("identity_id = ? AND nid = ?", i.ID, nid). Order("id ASC"). - All(&recoveryAddresses); err != nil { + All(&i.RecoveryAddresses); err != nil { return sqlcon.HandleError(err) } return nil @@ -514,7 +511,8 @@ func (p *IdentityPersister) HydrateIdentityAssociations(ctx context.Context, i * // https://github.com/gobuffalo/pop/issues/723 if err := con.WithContext(ctx). Order("id ASC"). - Where("identity_id = ? AND nid = ?", i.ID, nid).All(&verifiableAddresses); err != nil { + Where("identity_id = ? AND nid = ?", i.ID, nid). + All(&i.VerifiableAddresses); err != nil { return sqlcon.HandleError(err) } return nil @@ -533,7 +531,7 @@ func (p *IdentityPersister) HydrateIdentityAssociations(ctx context.Context, i * if err != nil { return err } - credentials = creds[i.ID] + i.Credentials = creds[i.ID] return }) } @@ -542,10 +540,6 @@ func (p *IdentityPersister) HydrateIdentityAssociations(ctx context.Context, i * return err } - i.VerifiableAddresses = verifiableAddresses - i.RecoveryAddresses = recoveryAddresses - i.Credentials = credentials - if err := i.Validate(); err != nil { return err } diff --git a/session/handler_test.go b/session/handler_test.go index 0cf4df728bfb..938f772a3c6d 100644 --- a/session/handler_test.go +++ b/session/handler_test.go @@ -67,6 +67,7 @@ func TestSessionWhoAmI(t *testing.T) { // set this intermediate because kratos needs some valid url for CRUDE operations conf.MustSet(ctx, config.ViperKeyPublicBaseURL, "http://example.com") + email := "foo" + uuid.Must(uuid.NewV4()).String() + "@bar.sh" i := &identity.Identity{ ID: x.NewUUID(), State: identity.StateActive, @@ -76,9 +77,21 @@ func TestSessionWhoAmI(t *testing.T) { Config: []byte(`{"hashed_password":"$argon2id$v=19$m=32,t=2,p=4$cm94YnRVOW5jZzFzcVE4bQ$MNzk5BtR2vUhrp6qQEjRNw"}`), }, }, - Traits: identity.Traits(`{"baz":"bar","foo":true,"bar":2.5}`), + Traits: identity.Traits(`{"email": "` + email + `","baz":"bar","foo":true,"bar":2.5}`), MetadataAdmin: []byte(`{"admin":"ma"}`), MetadataPublic: []byte(`{"public":"mp"}`), + RecoveryAddresses: []identity.RecoveryAddress{ + { + Value: email, + Via: identity.AddressTypeEmail, + }, + }, + VerifiableAddresses: []identity.VerifiableAddress{ + { + Value: email, + Via: identity.AddressTypeEmail, + }, + }, } h, _ := testhelpers.MockSessionCreateHandlerWithIdentity(t, reg, i) @@ -182,6 +195,9 @@ func TestSessionWhoAmI(t *testing.T) { assert.Empty(t, gjson.GetBytes(body, "identity.credentials")) assert.Equal(t, "mp", gjson.GetBytes(body, "identity.metadata_public.public").String(), "%s", body) assert.False(t, gjson.GetBytes(body, "identity.metadata_admin").Exists()) + + assert.NotEmpty(t, gjson.GetBytes(body, "identity.recovery_addresses").String(), "%s", body) + assert.NotEmpty(t, gjson.GetBytes(body, "identity.verifiable_addresses").String(), "%s", body) }) } } diff --git a/session/stub/identity.schema.json b/session/stub/identity.schema.json index 558106d35900..da89843091ed 100644 --- a/session/stub/identity.schema.json +++ b/session/stub/identity.schema.json @@ -3,5 +3,27 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Person", "type": "object", - "properties": {} + "properties": { + "traits": { + "type": "object", + "properties": { + "email": { + "type": "string", + "ory.sh/kratos": { + "credentials": { + "password": { + "identifier": true + } + }, + "verification": { + "via": "email" + }, + "recovery": { + "via": "email" + } + } + } + } + } + } }