Skip to content

Commit

Permalink
Fix(SCIMMY.Messages.PatchOp): correctly wrap multi-value string compa…
Browse files Browse the repository at this point in the history
…risons in remove ops
  • Loading branch information
sleelin committed Jul 24, 2024
1 parent 6071bad commit ecd44c6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/lib/messages/patchop.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ export class PatchOp {
// Get rid of any empty values from the filter
.filter(([, value]) => value !== undefined)
// Turn it into an equity filter string
.map(([key, value]) => (`${key} eq ${value}`)).join(" and "))
.join(" or ")
)
.map(([key, value]) => (`${key} eq ${typeof value === "string" ? `"${value}"` : value}`))
// Join all comparisons into one logical expression
.join(" and ")).join(" or "))
// Get any matching values from the filter
.match(target[property])
));
Expand Down
8 changes: 7 additions & 1 deletion test/lib/messages/patchop.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ const TestSchema = createSchemaClass({
new Attribute("string", "nickName"), new Attribute("string", "password", {direction: "in", returned: false}),
new Attribute("complex", "name", {}, [new Attribute("string", "formatted"), new Attribute("string", "honorificPrefix")]),
new Attribute("complex", "emails", {multiValued: true}, [new Attribute("string", "value"), new Attribute("string", "type")]),
new Attribute("string", "throws"), new Attribute("dateTime", "date")
new Attribute("string", "throws"), new Attribute("dateTime", "date"),
new Attribute("complex", "members", {multiValued: true, uniqueness: false}, [
new Attribute("string", "value", {mutable: "immutable"}),
new Attribute("string", "display", {mutable: "immutable"}),
new Attribute("reference", "$ref", {mutable: "immutable", referenceTypes: ["User", "Group"]}),
new Attribute("string", "type", {mutable: "immutable", canonicalValues: ["User", "Group"]})
])
]
});

Expand Down
78 changes: 69 additions & 9 deletions test/lib/messages/patchop.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,115 @@
"ops": [
{"op": "add", "path": "name", "value": {"formatted": "Test"}}
]
},
{
"source": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}, {"value": "123abc"}]},
"target": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}, {"value": "123abc", "$ref": "User"}]},
"ops": [
{"op": "add", "path": "members[value eq 123abc].$ref", "value": "User"}
]
}
],
"remove": [
{
"source": {"id": "1234", "userName": "asdf", "name": {"honorificPrefix": "Mr"}},
"target": {"id": "1234", "userName": "asdf"},
"ops": [{"op": "remove", "path": "name"}]
"ops": [
{"op": "remove", "path": "name"}
]
},
{
"source": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}, {"type": "home", "value": "[email protected]"}]},
"target": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}]},
"ops": [{"op": "remove", "path": "emails", "value": {"type": "home"}}]
"ops": [
{"op": "remove", "path": "emails", "value": {"type": "home"}}
]
},
{
"source": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}]},
"target": {"id": "1234", "userName": "asdf"},
"ops": [{"op": "remove", "path": "emails[type eq \"work\"]"}]
"ops": [
{"op": "remove", "path": "emails[type eq \"work\"]"}
]
},
{
"source": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}, {"$ref": "User", "value": "f648f8d5ea4e4cd38e9c"}]},
"target": {"id": "1234", "userName": "asdf", "members": [{"$ref": "User", "value": "f648f8d5ea4e4cd38e9c"}]},
"ops": [
{"op": "remove", "path": "members", "value": [{"$ref": null, "value": "f648f8d5ea4e4cd38e9c"}]}
]
},
{
"source": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}, {"$ref": "User", "value": "f648f8d5ea4e4cd38e9c"}]},
"target": {"id": "1234", "userName": "asdf", "members": [{"$ref": "User", "value": "f648f8d5ea4e4cd38e9c"}]},
"ops": [
{"op": "remove", "path": "members[$ref eq null and value eq \"f648f8d5ea4e4cd38e9c\"]"}
]
},
{
"source": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}, {"value": "123abc"}]},
"target": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}]},
"ops": [
{"op": "remove", "path": "members", "value": [{"value": "123abc"}]}
]
},
{
"source": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}, {"value": "123abc"}]},
"target": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}]},
"ops": [
{"op": "remove", "path": "members[value eq \"123abc\"]"}
]
},
{
"source": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}, {"value": "123abc"}]},
"target": {"id": "1234", "userName": "asdf", "members": [{"value": "f648f8d5ea4e4cd38e9c"}]},
"ops": [
{"op": "Remove", "path": "members[value eq 123abc]"}
]
}
],
"replace": [
{
"source": {"id": "1234", "userName": "asdf", "name": {"honorificPrefix": "Mr"}},
"target": {"id": "1234", "userName": "ghjk", "name": {"honorificPrefix": "Mr"}},
"ops": [{"op": "replace", "path": "userName", "value": "ghjk"}]
"ops": [
{"op": "replace", "path": "userName", "value": "ghjk"}
]
},
{
"source": {"id": "1234", "userName": "asdf", "name": {"honorificPrefix": "Mr"}},
"target": {"id": "1234", "userName": "asdf", "name": {"formatted": "Test"}},
"ops": [{"op": "replace", "path": "name", "value": {"formatted": "Test"}}]
"ops": [
{"op": "replace", "path": "name", "value": {"formatted": "Test"}}
]
},
{
"source": {"id": "1234", "userName": "asdf", "emails": [{"type": "home", "value": "[email protected]"}]},
"target": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}]},
"ops": [{"op": "replace", "path": "emails", "value": {"type": "work", "value": "[email protected]"}}]
"ops": [
{"op": "replace", "path": "emails", "value": {"type": "work", "value": "[email protected]"}}
]
},
{
"source": {"id": "1234", "userName": "asdf", "emails": [{"type": "home", "value": "[email protected]"}]},
"target": {"id": "1234", "userName": "asdf", "emails": [{"type": "home", "value": "[email protected]"}, {"type": "work", "value": "[email protected]"}]},
"ops": [{"op": "replace", "path": "emails[type eq \"work\"]", "value": {"type": "work", "value": "[email protected]"}}]
"ops": [
{"op": "replace", "path": "emails[type eq \"work\"]", "value": {"type": "work", "value": "[email protected]"}}
]
},
{
"source": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}]},
"target": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}]},
"ops": [{"op": "replace", "path": "emails[type eq \"work\"]", "value": {"type": "work", "value": "[email protected]"}}]
"ops": [
{"op": "replace", "path": "emails[type eq \"work\"]", "value": {"type": "work", "value": "[email protected]"}}
]
},
{
"source": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}]},
"target": {"id": "1234", "userName": "asdf", "emails": [{"type": "work", "value": "[email protected]"}]},
"ops": [{"op": "replace", "path": "emails[type eq \"work\"].value", "value": "[email protected]"}]
"ops": [
{"op": "replace", "path": "emails[type eq \"work\"].value", "value": "[email protected]"}
]
}
]
}
Expand Down

0 comments on commit ecd44c6

Please sign in to comment.