Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow patching some /credentials sub-paths #4277

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ func (h *Handler) patch(w http.ResponseWriter, r *http.Request, ps httprouter.Pa

patchedIdentity := WithAdminMetadataInJSON(*identity)

if err := jsonx.ApplyJSONPatch(requestBody, &patchedIdentity, "/id", "/stateChangedAt", "/credentials", "/credentials/**"); err != nil {
if err := jsonx.ApplyJSONPatch(requestBody, &patchedIdentity, "/id", "/stateChangedAt", "/credentials", "/credentials/oidc/**"); err != nil {
jonas-jonas marked this conversation as resolved.
Show resolved Hide resolved
h.r.Writer().WriteError(w, r, errors.WithStack(
herodot.
ErrBadRequest.
Expand Down
9 changes: 6 additions & 3 deletions identity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ func TestHandler(t *testing.T) {
}
})

t.Run("case=PATCH should fail to update credential password", func(t *testing.T) {
t.Run("case=PATCH should allow to update credential password", func(t *testing.T) {
uuid := x.NewUUID().String()
email := uuid + "@ory.sh"
password := "ljanf123akf"
Expand All @@ -1247,9 +1247,12 @@ func TestHandler(t *testing.T) {
{"op": "replace", "path": "/credentials/password/config/hashed_password", "value": "foo"},
}

res := send(t, ts, "PATCH", "/identities/"+i.ID.String(), http.StatusBadRequest, &patch)
send(t, ts, "PATCH", "/identities/"+i.ID.String(), http.StatusOK, &patch)

assert.EqualValues(t, "patch includes denied path: /credentials/password/config/hashed_password", res.Get("error.message").String(), "%s", res.Raw)
updated, err := reg.PrivilegedIdentityPool().GetIdentityConfidential(ctx, i.ID)
require.NoError(t, err)
assert.Equal(t, "foo",
gjson.GetBytes(updated.Credentials[identity.CredentialsTypePassword].Config, "hashed_password").String())
})
}
})
Expand Down
Loading