Skip to content

Commit

Permalink
Allow ttd org to migrate delegations for link service owned by acn org (
Browse files Browse the repository at this point in the history
#524)

* allow ttd to migrate delegations for link service owned by acn

* remove unneeded test file

* update result count in tests after adding new resource to test data
  • Loading branch information
mgunnerud authored Nov 22, 2024
1 parent c9bf639 commit 207a5f6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ private async Task<bool> ValidateMatchingOrgForDelegaton(ExportDelegationsReques
{
if (resource.Identifier.Equals($"se_{exportRequest.ServiceCode}_{exportRequest.ServiceEditionCode}"))
{
if (resource.HasCompetentAuthority.Orgcode.Equals(org, StringComparison.OrdinalIgnoreCase))
bool isMatchingOrg = resource.HasCompetentAuthority.Orgcode.Equals(org, StringComparison.OrdinalIgnoreCase) ||
(org.Equals("ttd", StringComparison.OrdinalIgnoreCase) && resource.HasCompetentAuthority.Orgcode.Equals("acn", StringComparison.OrdinalIgnoreCase));
if (isMatchingOrg)
{
return true;
}
Expand Down
27 changes: 27 additions & 0 deletions test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,32 @@ public async Task Trigger_Batch_NoMatchingORg()

Assert.Equal(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
}

/// <summary>
/// Triggers batch with a ttd resource to migrate delegations for an acn Altinn 2 service
/// </summary>
[Fact]
public async Task Trigger_Batch_MigrateAcnServiceForTtd_OK()
{
HttpClient client = CreateClient();
string token = PrincipalUtil.GetOrgToken("ttd", "991825827", "altinn:resourceregistry/resource.admin");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
string requestUri = "resourceregistry/api/v1/altinn2export/exportdelegations";

ExportDelegationsRequestBE exportDelegationsRequestBE = new ExportDelegationsRequestBE()
{
ResourceId = "altinn_delegation_resource",
DateTimeForExport = DateTime.Now,
ServiceCode = "3225",
ServiceEditionCode = 1596
};

using HttpContent content = JsonContent.Create(exportDelegationsRequestBE);
HttpResponseMessage response = await client.PostAsync(requestUri, content);

string responseContent = await response.Content.ReadAsStringAsync();

Assert.Equal(System.Net.HttpStatusCode.NoContent, response.StatusCode);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"identifier": "altinn_delegation_resource",
"version": "1",
"title": {
"en": "Text in english",
"nb": "ABCtest",
"nn": "tekst i nynorsk"
},
"description": {
"en": "ABCtest",
"nb": "ABCtest",
"nn": "ABCtest"
},
"rightDescription": {
"en": "ABCtest",
"nb": "ABCtest",
"nn": "ABCtest"
},
"homepage": "https://www.vg.no",
"status": "UnderDevelopment",
"spatial": [],
"contactPoints": [
{
"category": "ABCtest",
"email": "",
"telephone": "",
"contactPage": ""
}
],
"produces": [],
"resourceReferences": [
{
"referenceSource": "Altinn2",
"reference": "3225",
"referenceType": "ServiceCode"
},
{
"referenceSource": "Altinn2",
"reference": "1596",
"referenceType": "ServiceEditionCode"
}
],
"delegable": true,
"visible": true,
"hasCompetentAuthority": {
"name": {
"en": "Test Ministry",
"nb": "Testdepartementet",
"nn": "Testdepartementet"
},
"organization": "",
"orgcode": "ttd"
},
"keywords": [],
"accessListMode": "Disabled",
"selfIdentifiedUserEnabled": false,
"enterpriseUserEnabled": true,
"resourceType": "GenericAccessResource",
"availableForType": [
"LegalEntityEnterprise",
"Company",
"PrivatePerson",
"BankruptcyEstate",
"SelfRegisteredUser"
],
"authorizationReference": [
{
"id": "urn:altinn:resource",
"value": "altinn_delegation_resource"
}
]
}
10 changes: 5 additions & 5 deletions test/Altinn.ResourceRegistry.Tests/ResourceControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task Search_Get()
List<ServiceResource>? resource = JsonSerializer.Deserialize<List<ServiceResource>>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List<ServiceResource>;

Assert.NotNull(resource);
Assert.Equal(2, resource.Count);
Assert.Equal(3, resource.Count);
}

[Fact]
Expand All @@ -102,7 +102,7 @@ public async Task ResourceList()
List<ServiceResource>? resource = JsonSerializer.Deserialize<List<ServiceResource>>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List<ServiceResource>;

Assert.NotNull(resource);
Assert.Equal(439, resource.Count);
Assert.Equal(440, resource.Count);

ServiceResource? altinn2resourcewithdescription = resource.FirstOrDefault(r => r.ResourceReferences != null && r.ResourceReferences.Any(r => r.Reference != null && r.Reference.Contains("5563")));
Assert.NotNull(altinn2resourcewithdescription);
Expand All @@ -128,7 +128,7 @@ public async Task ResourceList_NoApps()
List<ServiceResource>? resource = JsonSerializer.Deserialize<List<ServiceResource>>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List<ServiceResource>;

Assert.NotNull(resource);
Assert.Equal(312, resource.Count);
Assert.Equal(313, resource.Count);
}

[Fact]
Expand All @@ -147,7 +147,7 @@ public async Task ResourceList_NoAltinn2()
List<ServiceResource>? resource = JsonSerializer.Deserialize<List<ServiceResource>>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List<ServiceResource>;

Assert.NotNull(resource);
Assert.Equal(130, resource.Count);
Assert.Equal(131, resource.Count);
}

[Fact]
Expand All @@ -166,7 +166,7 @@ public async Task ResourceList_NoAltinn2AndNoApps()
List<ServiceResource>? resource = JsonSerializer.Deserialize<List<ServiceResource>>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List<ServiceResource>;

Assert.NotNull(resource);
Assert.Equal(3, resource.Count);
Assert.Equal(4, resource.Count);
}

[Fact]
Expand Down

0 comments on commit 207a5f6

Please sign in to comment.