From 207a5f6c6dacb1ee72569cfb3adc7e6113aceecf Mon Sep 17 00:00:00 2001 From: Martin Gunnerud Date: Fri, 22 Nov 2024 12:16:07 +0100 Subject: [PATCH] Allow ttd org to migrate delegations for link service owned by acn org (#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 --- .../Controllers/Altinn2ExportController.cs | 4 +- .../Altinn2ExportControllerTest.cs | 27 +++++++ .../Resources/altinn_delegation_resource.json | 72 +++++++++++++++++++ .../ResourceControllerTest.cs | 10 +-- 4 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 test/Altinn.ResourceRegistry.Tests/Data/Resources/altinn_delegation_resource.json diff --git a/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs b/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs index 72755f67..f3b49868 100644 --- a/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs +++ b/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs @@ -138,7 +138,9 @@ private async Task 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; } diff --git a/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs b/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs index a71bba0c..53fa3944 100644 --- a/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs +++ b/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs @@ -261,5 +261,32 @@ public async Task Trigger_Batch_NoMatchingORg() Assert.Equal(System.Net.HttpStatusCode.BadRequest, response.StatusCode); } + + /// + /// Triggers batch with a ttd resource to migrate delegations for an acn Altinn 2 service + /// + [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); + } } } diff --git a/test/Altinn.ResourceRegistry.Tests/Data/Resources/altinn_delegation_resource.json b/test/Altinn.ResourceRegistry.Tests/Data/Resources/altinn_delegation_resource.json new file mode 100644 index 00000000..63f69419 --- /dev/null +++ b/test/Altinn.ResourceRegistry.Tests/Data/Resources/altinn_delegation_resource.json @@ -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" + } + ] +} diff --git a/test/Altinn.ResourceRegistry.Tests/ResourceControllerTest.cs b/test/Altinn.ResourceRegistry.Tests/ResourceControllerTest.cs index 5614bda9..25adf5fe 100644 --- a/test/Altinn.ResourceRegistry.Tests/ResourceControllerTest.cs +++ b/test/Altinn.ResourceRegistry.Tests/ResourceControllerTest.cs @@ -83,7 +83,7 @@ public async Task Search_Get() List? resource = JsonSerializer.Deserialize>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List; Assert.NotNull(resource); - Assert.Equal(2, resource.Count); + Assert.Equal(3, resource.Count); } [Fact] @@ -102,7 +102,7 @@ public async Task ResourceList() List? resource = JsonSerializer.Deserialize>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List; 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); @@ -128,7 +128,7 @@ public async Task ResourceList_NoApps() List? resource = JsonSerializer.Deserialize>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List; Assert.NotNull(resource); - Assert.Equal(312, resource.Count); + Assert.Equal(313, resource.Count); } [Fact] @@ -147,7 +147,7 @@ public async Task ResourceList_NoAltinn2() List? resource = JsonSerializer.Deserialize>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List; Assert.NotNull(resource); - Assert.Equal(130, resource.Count); + Assert.Equal(131, resource.Count); } [Fact] @@ -166,7 +166,7 @@ public async Task ResourceList_NoAltinn2AndNoApps() List? resource = JsonSerializer.Deserialize>(responseContent, new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) as List; Assert.NotNull(resource); - Assert.Equal(3, resource.Count); + Assert.Equal(4, resource.Count); } [Fact]