-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add single test for authorized parties returning instance delegations
- Loading branch information
1 parent
a1699a9
commit 6ff5fc2
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
test/Altinn.AccessManagement.Tests/Controllers/V2AuthorizedPartiesControllerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Net.Http.Json; | ||
using Altinn.AccessManagement.Controllers; | ||
using Altinn.AccessManagement.Core.Helpers.Extensions; | ||
using Altinn.AccessManagement.Core.Models; | ||
using Altinn.AccessManagement.Models; | ||
using Altinn.AccessManagement.Tests.Fixtures; | ||
using Altinn.AccessManagement.Tests.Scenarios; | ||
using Altinn.AccessManagement.Tests.Seeds; | ||
using Docker.DotNet.Models; | ||
|
||
namespace Altinn.AccessManagement.Tests.Controllers; | ||
|
||
/// <summary> | ||
/// <see cref="AuthorizedPartiesController"/> | ||
/// </summary> | ||
public class V2AuthorizedPartiesControllerTest(WebApplicationFixture fixture) : IClassFixture<WebApplicationFixture> | ||
{ | ||
private WebApplicationFixture Fixture { get; } = fixture; | ||
|
||
private static Action<AcceptanceCriteriaComposer> WithAssertDbContainsDelegations(IParty from, IAccessManagementResource resource) => test => | ||
{ | ||
test.ApiAssertions.Add(async host => | ||
{ | ||
var delegations = await host.Repository.DelegationMetadataRepository.GetAllCurrentAppDelegationChanges(from.Party.PartyId.SingleToList(), resource.DbResource.ResourceRegistryId.SingleToList()); | ||
Assert.True( | ||
delegations.Count > 0, | ||
$"Couldn't find any delegations from {from.Party.PartyId} to app {resource.DbResource.ResourceRegistryId}"); | ||
}); | ||
}; | ||
|
||
private static Action<AcceptanceCriteriaComposer> WithAssertResponseContainsInstance(string resourceId, string instanceId) => test => | ||
{ | ||
test.ResponseAssertions.Add(async response => | ||
{ | ||
var delegations = await response.Content.ReadFromJsonAsync<IEnumerable<AuthorizedPartyExternal>>(); | ||
var result = delegations.Any(delegation => delegation.AuthorizedInstances.Any(instance => instance.ResourceId == resourceId && instance.InstanceId == instanceId)); | ||
Assert.True(result, $"Response don't contains instance delegations with resource Id {resourceId} and instance id {instanceId}"); | ||
}); | ||
}; | ||
|
||
/// <summary> | ||
/// Seeds for <see cref="GET_AuthorizedParties"/> | ||
/// </summary> | ||
/// <param name="acceptanceCriteria">Acceptance Criteria</param> | ||
/// <param name="actions">modifiers for <see cref="AcceptanceCriteriaComposer"/></param> | ||
public class GetAuthorizedParties(string acceptanceCriteria, params Action<AcceptanceCriteriaComposer>[] actions) : AcceptanceCriteriaComposer( | ||
acceptanceCriteria, | ||
actions, | ||
WithRequestRoute("accessmanagement", "api", "v1", "authorizedparties"), | ||
WithRequestVerb(HttpMethod.Get)) | ||
{ | ||
/// <summary> | ||
/// Seeds | ||
/// </summary> | ||
public static TheoryData<GetAuthorizedParties> Seeds() => [ | ||
new( | ||
/* Acceptance Critieria */ @" | ||
GIVEN that organization Voss has shared an instance with DAGL Olav for Orstad Accounting | ||
WHEN DAGL Olav for Orstad Accounting requests authorized parties | ||
THEN Organization should be in the list of authorized parties | ||
AND the instance and resource iod should be included in list containing instances", | ||
|
||
WithScenarios( | ||
DelegationScenarios.Defaults, | ||
DelegationScenarios.WithInstanceDelegation(OrganizationSeeds.VossAccounting.Defaults, PersonSeeds.Paula.Defaults, ResourceSeeds.ChalkboardResource.Defaults, "1337"), | ||
TokenScenario.PersonToken(PersonSeeds.Olav.Defaults)), | ||
|
||
WithAssertResponseStatusCodeSuccessful, | ||
WithAssertResponseContainsInstance(ResourceSeeds.ChalkboardResource.Defaults.Identifier, "1337")), | ||
]; | ||
} | ||
|
||
/// <summary> | ||
/// <see cref="AuthorizedPartiesController.GetAuthorizedParties(bool, CancellationToken)"/> | ||
/// </summary> | ||
/// <param name="acceptanceCriteria">acceptance test</param> | ||
[Theory] | ||
[MemberData(nameof(GetAuthorizedParties.Seeds), MemberType = typeof(GetAuthorizedParties))] | ||
public async Task GET_AuthorizedParties(GetAuthorizedParties acceptanceCriteria) => await acceptanceCriteria.Test(Fixture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters