-
-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement password profile management flow
Closes #243
- Loading branch information
Showing
44 changed files
with
1,636 additions
and
1,021 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package driver | ||
|
||
import ( | ||
"github.com/ory/kratos/selfservice/flow/profile" | ||
) | ||
|
||
func (m *RegistryDefault) PostProfileManagementHooks(credentialsType string) []profile.PostHookExecutor { | ||
a := m.getHooks(credentialsType, m.c.SelfServiceProfileManagementAfterHooks(credentialsType)) | ||
|
||
var b []profile.PostHookExecutor | ||
for _, v := range a { | ||
if hook, ok := v.(profile.PostHookExecutor); ok { | ||
b = append(b, hook) | ||
} | ||
} | ||
|
||
return b | ||
} | ||
|
||
func (m *RegistryDefault) ProfileManagementExecutor() *profile.HookExecutor { | ||
if m.selfserviceProfileManagementExecutor == nil { | ||
m.selfserviceProfileManagementExecutor = profile.NewHookExecutor(m, m.c) | ||
} | ||
return m.selfserviceProfileManagementExecutor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ func TestManager(t *testing.T) { | |
require.NoError(t, reg.IdentityManager().Create(context.Background(), original)) | ||
|
||
original.Traits = identity.Traits(`{"email":"[email protected]"}`) | ||
require.NoError(t, reg.IdentityManager().Update(context.Background(), original)) | ||
require.NoError(t, reg.IdentityManager().Update(context.Background(), original, identity.ManagerAllowWriteProtectedTraits)) | ||
|
||
checkExtensionFieldsForIdentities(t, "[email protected]", original) | ||
}) | ||
|
@@ -101,40 +101,57 @@ func TestManager(t *testing.T) { | |
require.NoError(t, err) | ||
assert.JSONEq(t, `{"email":"[email protected]","email_verify":"[email protected]","email_creds":"[email protected]","unprotected": "bar"}`, string(actual.Traits)) | ||
}) | ||
|
||
t.Run("case=should not update protected traits without option", func(t *testing.T) { | ||
original := identity.NewIdentity(configuration.DefaultIdentityTraitsSchemaID) | ||
original.Traits = identity.Traits(`{"email":"[email protected]"}`) | ||
require.NoError(t, reg.IdentityManager().Create(context.Background(), original)) | ||
|
||
original.Traits = identity.Traits(`{"email":"[email protected]"}`) | ||
err := reg.IdentityManager().Update(context.Background(), original) | ||
require.Error(t, err) | ||
assert.Equal(t, identity.ErrProtectedFieldModified, errors.Cause(err)) | ||
|
||
fromStore, err := reg.PrivilegedIdentityPool().GetIdentityConfidential(context.Background(), original.ID) | ||
require.NoError(t, err) | ||
// As UpdateTraits takes only the ID as a parameter it cannot update the identity in place. | ||
// That is why we only check the identity in the store. | ||
checkExtensionFields(fromStore, "[email protected]")(t) | ||
}) | ||
}) | ||
|
||
t.Run("method=UpdateTraits", func(t *testing.T) { | ||
t.Run("case=should update protected traits with option", func(t *testing.T) { | ||
original := identity.NewIdentity(configuration.DefaultIdentityTraitsSchemaID) | ||
original.Traits = identity.Traits(`{"email":"email1@ory.sh"}`) | ||
original.Traits = identity.Traits(`{"email":"email-updatetraits-1@ory.sh"}`) | ||
require.NoError(t, reg.IdentityManager().Create(context.Background(), original)) | ||
|
||
require.NoError(t, reg.IdentityManager().UpdateTraits( | ||
context.Background(), original.ID, identity.Traits(`{"email":"email2@ory.sh"}`), | ||
context.Background(), original.ID, identity.Traits(`{"email":"email-updatetraits-2@ory.sh"}`), | ||
identity.ManagerAllowWriteProtectedTraits)) | ||
|
||
fromStore, err := reg.PrivilegedIdentityPool().GetIdentityConfidential(context.Background(), original.ID) | ||
require.NoError(t, err) | ||
// As UpdateTraits takes only the ID as a parameter it cannot update the identity in place. | ||
// That is why we only check the identity in the store. | ||
checkExtensionFields(fromStore, "email2@ory.sh")(t) | ||
checkExtensionFields(fromStore, "email-updatetraits-2@ory.sh")(t) | ||
}) | ||
|
||
t.Run("case=should not update protected traits without option", func(t *testing.T) { | ||
original := identity.NewIdentity(configuration.DefaultIdentityTraitsSchemaID) | ||
original.Traits = identity.Traits(`{"email":"email1@ory.sh"}`) | ||
original.Traits = identity.Traits(`{"email":"email-updatetraits-1@ory.sh"}`) | ||
require.NoError(t, reg.IdentityManager().Create(context.Background(), original)) | ||
|
||
err := reg.IdentityManager().UpdateTraits( | ||
context.Background(), original.ID, identity.Traits(`{"email":"email2@ory.sh"}`)) | ||
context.Background(), original.ID, identity.Traits(`{"email":"email-updatetraits-2@ory.sh"}`)) | ||
require.Error(t, err) | ||
assert.Equal(t, identity.ErrProtectedFieldModified, errors.Cause(err)) | ||
|
||
fromStore, err := reg.PrivilegedIdentityPool().GetIdentityConfidential(context.Background(), original.ID) | ||
require.NoError(t, err) | ||
// As UpdateTraits takes only the ID as a parameter it cannot update the identity in place. | ||
// That is why we only check the identity in the store. | ||
checkExtensionFields(fromStore, "email1@ory.sh")(t) | ||
checkExtensionFields(fromStore, "email-updatetraits-1@ory.sh")(t) | ||
}) | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.