Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed May 30, 2024
1 parent d2675dd commit bf768af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private class SystemUserAuthorizationDetails
public string? Type { get; set; }

[JsonPropertyName("systemuser_id")]
public string? SystemUserId { get; set; }
public string[]? SystemUserIds { get; set; }
}

public static bool TryGetSystemUserId(this ClaimsPrincipal claimsPrincipal, [NotNullWhen(true)] out string? systemUserId)
Expand All @@ -97,7 +97,7 @@ public static bool TryGetSystemUserId(this ClaimsPrincipal claimsPrincipal, [Not
var systemUserTypeDetails = systemUserAuthDetails?.FirstOrDefault(x => x.Type == AttributeIdSystemUser);
if (systemUserTypeDetails != null)
{
systemUserId = systemUserTypeDetails.SystemUserId;
systemUserId = systemUserTypeDetails.SystemUserIds?.FirstOrDefault();
}

return systemUserId is not null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static DialogSearchAuthorizationResult CreateDialogSearchResponse(
continue;
}

// Get the name of the resource. This may be either an app or an generic service resource.
// Get the name of the resource. This may be either an app or a generic service resource.
var resourceId = $"r{i + 1}";
var resourceList = xamlJsonRequestRoot.Request.Resource.First(r => r.Id == resourceId).Attribute;
var resource = resourceList.First(a => a.AttributeId is AttributeIdResource or AttributeIdApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class DecisionRequestHelperTests
{
private const string ConsumerClaimValue = /*lang=json,strict*/ "{\"authority\":\"iso6523-actorid-upis\",\"ID\":\"0192:991825827\"}";

private const string AuthorizationDetailsClaimValue = /*lang=json,strict*/"[{\"type\":\"urn:altinn:systemuser\",\"systemuser_id\":[\"unique_systemuser_id\"]}]";

[Fact]
public void CreateDialogDetailsRequestShouldReturnCorrectRequest()
{
Expand Down Expand Up @@ -108,6 +110,31 @@ public void CreateDialogDetailsRequestShouldReturnCorrectRequestForApp()
// Assert.Contains(resource1.Attribute, a => a.AttributeId == "urn:altinn:instance-id" && a.Value == dialogId.ToString());
}

[Fact]
public void CreateDialogDetailsRequestShouldReturnCorrectRequestForSystemUser()
{
// Arrange
var request = CreateDialogDetailsAuthorizationRequest(
GetAsClaims(
("authorization_details", AuthorizationDetailsClaimValue)
),
$"{NorwegianOrganizationIdentifier.PrefixWithSeparator}713330310"
);

// Act
var result = DecisionRequestHelper.CreateDialogDetailsRequest(request);

// Assert
Assert.NotNull(result);
Assert.NotNull(result.Request);
Assert.NotNull(result.Request.Resource);

var accessSubject = result.Request.AccessSubject.First();
Assert.Equal("s1", accessSubject.Id);
Assert.Contains(accessSubject.Attribute, a => a.AttributeId == "urn:altinn:foo" && a.Value == "bar");
Assert.Contains(accessSubject.Attribute, a => a.AttributeId == "urn:altinn:systemuser" && a.Value == "unique_systemuser_id");
}

[Fact]
public void CreateDialogDetailsRequestShouldReturnCorrectRequestForConsumerOrgAndPersonParty()
{
Expand Down

0 comments on commit bf768af

Please sign in to comment.