Skip to content

Commit 6c0ebe5

Browse files
Ticket #928 : Patch user unique userName violation
1 parent 346c373 commit 6c0ebe5

4 files changed

Lines changed: 686 additions & 411 deletions

File tree

src/Scim/SimpleIdServer.Scim/Commands/Handlers/PatchRepresentationCommandHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ private async Task<GenericResult<PatchRepresentationResult>> UpdateRepresentatio
6262
var oldDisplayName = existingRepresentation.DisplayName;
6363
var patchResult = await _representationHelper.Apply(existingRepresentation, patchRepresentationCommand.PatchRepresentation.Operations, attributeMappings, _options.IgnoreUnsupportedCanonicalValues, CancellationToken.None);
6464
var patchResultLst = patchResult.Patches.Where(p => p.Attr != null).ToList();
65+
var modifiedAttributes = patchResultLst.Where(p => p.Operation != SCIMPatchOperations.REMOVE && p.Attr != null && p.Attr.SchemaAttribute.MultiValued == false).Select(p => p.Attr);
66+
await _representationHelper.CheckUniqueness(existingRepresentation.RealmName, modifiedAttributes);
6567
_representationHelper.CheckMutability(patchResultLst);
6668
var displayNameDifferent = existingRepresentation.DisplayName != oldDisplayName;
6769
if (!patchResult.Patches.Any()) return GenericResult<PatchRepresentationResult>.Ok(PatchRepresentationResult.NoPatch());

src/Scim/SimpleIdServer.Scim/Commands/Handlers/ReplaceRepresentationCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async virtual Task<GenericResult<ReplaceRepresentationResult>> Handle(Rep
5757
if (!patchResult.Patches.Any()) return GenericResult<ReplaceRepresentationResult>.Ok(ReplaceRepresentationResult.NoReplacement());
5858
var patchOperations = patchResult.Patches.Where(p => p.Attr != null).ToList();
5959
var displayNameDifferent = existingRepresentation.DisplayName != oldDisplayName;
60-
var modifiedAttributes = patchOperations.Where(p => p.Operation != SCIMPatchOperations.REMOVE && p.Attr != null && !p.Attr.IsLeaf() && p.Attr.SchemaAttribute.MultiValued == false).Select(p => p.Attr);
60+
var modifiedAttributes = patchOperations.Where(p => p.Operation != SCIMPatchOperations.REMOVE && p.Attr != null && p.Attr.SchemaAttribute.MultiValued == false).Select(p => p.Attr);
6161
await _representationHelper.CheckUniqueness(replaceRepresentationCommand.Realm, modifiedAttributes);
6262
_representationHelper.CheckMutability(patchOperations);
6363
var references = await _representationReferenceSync.Sync(existingRepresentation.ResourceType, existingRepresentation, patchOperations, replaceRepresentationCommand.Location, schema, displayNameDifferent);

tests/SimpleIdServer.Scim.Host.Acceptance.Tests/Features/UsersErrors.feature

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,69 @@ Scenario: Error is returned when schema is not valid (HTTP POST)
249249
Then JSON 'scimType'='invalidSyntax'
250250
Then JSON 'detail'='the required schemas urn:ietf:params:scim:schemas:core:2.0:User,urn:ietf:params:scim:schemas:extension:enterprise:2.0:User are missing'
251251

252+
Scenario: Error is returned when trying to update the username with HTTP PATCH but this username already exists
253+
When execute HTTP POST JSON request 'http://localhost/Users'
254+
| Key | Value |
255+
| schemas | [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" ] |
256+
| userName | bjen |
257+
| name | { "formatted" : "formatted", "familyName": "familyName", "givenName": "givenName" } |
258+
| employeeNumber | number |
259+
260+
261+
When execute HTTP POST JSON request 'http://localhost/Users'
262+
| Key | Value |
263+
| schemas | [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" ] |
264+
| userName | bjen2 |
265+
| name | { "formatted" : "formatted", "familyName": "familyName", "givenName": "givenName" } |
266+
| employeeNumber | number |
267+
268+
And extract JSON from body
269+
And extract 'id' from JSON body
270+
And execute HTTP PATCH JSON request 'http://localhost/Users/$id$'
271+
| Key | Value |
272+
| schemas | [ "urn:ietf:params:scim:api:messages:2.0:PatchOp" ] |
273+
| Operations | [ { "op": "replace", "path": "userName", "value" : "bjen" } ] |
274+
And extract JSON from body
275+
276+
277+
Then HTTP status code equals to '409'
278+
Then JSON 'schemas[0]'='urn:ietf:params:scim:api:messages:2.0:Error'
279+
Then JSON 'status'='409'
280+
Then JSON 'scimType'='uniqueness'
281+
Then JSON 'detail'='attribute userName must be unique'
282+
283+
Scenario: Error is returned when trying to update the username with HTTP PUT but this username already exists
284+
When execute HTTP POST JSON request 'http://localhost/Users'
285+
| Key | Value |
286+
| schemas | [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" ] |
287+
| userName | bjen |
288+
| name | { "formatted" : "formatted", "familyName": "familyName", "givenName": "givenName" } |
289+
| employeeNumber | number |
290+
291+
292+
When execute HTTP POST JSON request 'http://localhost/Users'
293+
| Key | Value |
294+
| schemas | [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" ] |
295+
| userName | bjen2 |
296+
| name | { "formatted" : "formatted", "familyName": "familyName", "givenName": "givenName" } |
297+
| employeeNumber | number |
298+
299+
And extract JSON from body
300+
And extract 'id' from JSON body
301+
And execute HTTP PUT JSON request 'http://localhost/Users/$id$'
302+
| Key | Value |
303+
| schemas | [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" ] |
304+
| userName | bjen |
305+
| name | { "formatted" : "formatted", "familyName": "familyName", "givenName": "givenName" } |
306+
| employeeNumber | number |
307+
And extract JSON from body
308+
309+
Then HTTP status code equals to '409'
310+
Then JSON 'schemas[0]'='urn:ietf:params:scim:api:messages:2.0:Error'
311+
Then JSON 'status'='409'
312+
Then JSON 'scimType'='uniqueness'
313+
Then JSON 'detail'='attribute userName must be unique'
314+
252315
Scenario: Error is returned when trying to add two resources with the same unique attribute
253316
When execute HTTP POST JSON request 'http://localhost/Users'
254317
| Key | Value |

0 commit comments

Comments
 (0)