Skip to content

Commit

Permalink
TIcket #808 : Fix duplicate parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
thabart committed Nov 11, 2024
1 parent 91b3258 commit 2f6aa24
Show file tree
Hide file tree
Showing 8 changed files with 1,511 additions and 1,375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected virtual ICollection<SCIMRepresentationAttribute> InternalBuildEmptyAtt
var result = new SCIMRepresentationAttribute
{
SchemaAttribute = SchemaAttribute,
SchemaAttributeId = SchemaAttribute?.Id,
FullPath = SchemaAttribute.FullPath,
Namespace = SchemaAttribute.SchemaId,
Id = Guid.NewGuid().ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ public async Task BulkInsert(IEnumerable<SCIMRepresentationAttribute> scimRepres
{
scimRepresentationAttributes = scimRepresentationAttributes.Where(r => !string.IsNullOrWhiteSpace(r.RepresentationId)).ToList();
foreach (var attr in scimRepresentationAttributes)
{
attr.SchemaAttributeId = attr.SchemaAttribute?.Id;
attr.SchemaAttribute = null;
}

await _scimDbContext.AddRangeAsync(scimRepresentationAttributes);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Scim/SimpleIdServer.Scim.Startup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ void ConfigureEFStorage(StorageConfiguration conf)

IMessageDataRepository ConfigureMassTransitConfiguration(IServiceCollection services, MassTransitStorageConfiguration conf)
{
if (!conf.IsEnabled) return null;
if (!conf.IsEnabled)
{
services.AddSingleton<IMessageDataRepository>(new InMemoryMessageDataRepository());
return null;
}

IMessageDataRepository repository = null;
switch (conf.Type)
{
Expand Down
12 changes: 11 additions & 1 deletion src/Scim/SimpleIdServer.Scim/Helpers/RepresentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace SimpleIdServer.Scim.Helpers
{
Expand Down Expand Up @@ -105,7 +106,16 @@ public async Task<SCIMRepresentationPatchResult> Apply(SCIMRepresentation repres
if (scimFilter != null)
{
filteredAttributes = await _scimRepresentationCommandRepository.FindAttributes(representation.Id, scimExpr, cancellationToken);
hierarchicalFilteredAttributes = SCIMRepresentation.BuildHierarchicalAttributes(filteredAttributes);
if(hierarchicalNewAttributes != null && !filteredAttributes.Any())
{
hierarchicalFilteredAttributes = scimFilter.EvaluateAttributes(SCIMRepresentation.BuildHierarchicalAttributes(result.Patches.Select(p => p.Attr)).AsQueryable(), false).ToList();
filteredAttributes = SCIMRepresentation.BuildFlatAttributes(hierarchicalNewAttributes);
}
else
{
hierarchicalFilteredAttributes = SCIMRepresentation.BuildHierarchicalAttributes(filteredAttributes);
}

var complexAttr = scimFilter as SCIMComplexAttributeExpression;
if (complexAttr != null && !hierarchicalFilteredAttributes.Any() && complexAttr.GroupingFilter != null && patch.Operation == SCIMPatchOperations.REPLACE) throw new SCIMNoTargetException(Global.PatchMissingAttribute);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
Feature: Users
Check the /Users endpoint

Scenario: Pass multiple add operation for multiple fields to emails and check there is no duplicate
When execute HTTP POST JSON request 'http://localhost/Users'
| Key | Value |
| schemas | [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" ] |
| userName | bjen |
| externalId | externalid |
| name | { "formatted" : "formatted", "familyName": "familyName", "givenName": "givenName" } |
| urn:ietf:params:scim:schemas:extension:enterprise:2.0:User | { "employeeNumber" : "number" } |
| eidCertificate | aGVsbG8= |
| immutable | immutable |

And extract JSON from body
And extract 'id' from JSON body
And execute HTTP PATCH JSON request 'http://localhost/Users/$id$'
| Key | Value |
| schemas | [ "urn:ietf:params:scim:api:messages:2.0:PatchOp" ] |
| Operations | [ { "op": "add", "path": "emails[type eq work].display", "value" : "display" }, { "op": "add", "path": "emails[type eq work].value", "value" : "value" } ] |

And execute HTTP GET request 'http://localhost/Users/$id$'
And extract JSON from body

Then HTTP status code equals to '200'
Then JSON 'emails[0].display'='display'
Then JSON 'emails[0].value'='value'

Scenario: Check immutable property can be updated twice with the same value
When execute HTTP POST JSON request 'http://localhost/Users'
| Key | Value |
Expand Down
Loading

0 comments on commit 2f6aa24

Please sign in to comment.