From 0408c230184166c93b3fbc1cbe2c2586effb00c0 Mon Sep 17 00:00:00 2001 From: jonkjetiloye <40996230+jonkjetiloye@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:14:39 +0100 Subject: [PATCH] Chore: Fix for failing Bruno tests (#121) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jon Kjetil Øye --- ...InstDelg_DelgChk_AppWithDelegableRights_Ok.bru} | 10 ++++++---- ..._DelgChk_AppWithoutDelegableRights_OkEmpty.bru} | 14 ++++++++------ ...nstDelg_DelgChk_MissingToken_NotAuthorized.bru} | 12 ++++++++---- ...stDelg_DelgChk_PlatformAccessToken_OkEmpty.bru} | 14 ++++++++------ 4 files changed, 30 insertions(+), 20 deletions(-) rename src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/{AppWithDelegableRights_Ok.bru => InstDelg_DelgChk_AppWithDelegableRights_Ok.bru} (82%) rename src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/{AppWithoutDelegableRights_BadRequest.bru => InstDelg_DelgChk_AppWithoutDelegableRights_OkEmpty.bru} (69%) rename src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/{MissingToken_NotAuthorized.bru => InstDelg_DelgChk_MissingToken_NotAuthorized.bru} (61%) rename src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/{PlatformAccessToken_BadRequest.bru => InstDelg_DelgChk_PlatformAccessToken_OkEmpty.bru} (69%) diff --git a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/AppWithDelegableRights_Ok.bru b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_AppWithDelegableRights_Ok.bru similarity index 82% rename from src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/AppWithDelegableRights_Ok.bru rename to src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_AppWithDelegableRights_Ok.bru index 6f01c5c8..5ec7c3f9 100644 --- a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/AppWithDelegableRights_Ok.bru +++ b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_AppWithDelegableRights_Ok.bru @@ -1,5 +1,5 @@ meta { - name: AppWithDelegableRights_Ok + name: InstDelg_DelgChk_AppWithDelegableRights_Ok type: http seq: 1 } @@ -43,9 +43,11 @@ script:pre-request { } tests { - test("AppsInstanceDelegation DelegationCheck GET AppWithDelegableRights_Ok", function() { - var body = res.getBody(); - var data = body.data; + // Should be the same as the .bru request file. Used as prefix in test name which also shows in test result in pipeline. + const requestName = "InstDelg_DelgChk_AppWithDelegableRights_Ok"; + const data = res.getBody().data; + + test(requestName, function() { expect(res.status).to.equal(200); expect(data[0]).to.have.property('rightKey', 'app_ttd_authz-bruno-instancedelegation,task_1:read') expect(data[0]).to.have.property('status', 'Delegable') diff --git a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/AppWithoutDelegableRights_BadRequest.bru b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_AppWithoutDelegableRights_OkEmpty.bru similarity index 69% rename from src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/AppWithoutDelegableRights_BadRequest.bru rename to src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_AppWithoutDelegableRights_OkEmpty.bru index 7c2a3d98..42fe0b3f 100644 --- a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/AppWithoutDelegableRights_BadRequest.bru +++ b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_AppWithoutDelegableRights_OkEmpty.bru @@ -1,5 +1,5 @@ meta { - name: AppWithoutDelegableRights_BadRequest + name: InstDelg_DelgChk_AppWithoutDelegableRights_OkEmpty type: http seq: 2 } @@ -43,10 +43,12 @@ script:pre-request { } tests { - test("AppsInstanceDelegation DelegationCheck GET AppWithoutDelegableRights_Forbidden", function() { - var body = res.getBody(); - expect(res.status).to.equal(400); - expect(body.validationErrors[0].code).to.equal("AM.VLD-00004"); - expect(body.validationErrors[0].paths[0]).to.equal("appInstanceDelegationRequest.Resource"); + // Should be the same as the .bru request file. Used as prefix in test name which also shows in test result in pipeline. + const requestName = "InstDelg_DelgChk_AppWithoutDelegableRights_OkEmpty"; + const body = res.getBody(); + + test(requestName + "|HttpStatus.OK and Body.Data empty", function() { + expect(res.status).to.equal(200); + assert.isEmpty(body.data, `Expected data in body to be empty.`); }); } diff --git a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/MissingToken_NotAuthorized.bru b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_MissingToken_NotAuthorized.bru similarity index 61% rename from src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/MissingToken_NotAuthorized.bru rename to src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_MissingToken_NotAuthorized.bru index 04c6f39e..5afb711a 100644 --- a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/MissingToken_NotAuthorized.bru +++ b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_MissingToken_NotAuthorized.bru @@ -1,5 +1,5 @@ meta { - name: MissingToken_NotAuthorized + name: InstDelg_DelgChk_MissingToken_NotAuthorized type: http seq: 4 } @@ -18,7 +18,7 @@ params:path { headers { Accept: application/json PlatformAccessToken: {{platformAccessToken}} - Ocp-Apim-Subscription-Key: {{apimSubscriptionKey}} + ~Ocp-Apim-Subscription-Key: {{apimSubscriptionKey}} } script:pre-request { @@ -30,8 +30,12 @@ script:pre-request { } tests { - test("AppsInstanceDelegation DelegationCheck GET MissingToken_NotAuthorized", function() { - var body = res.getBody(); + // Should be the same as the .bru request file. Used as prefix in test name which also shows in test result in pipeline. + const requestName = "InstDelg_DelgChk_MissingToken_NotAuthorized"; + const body = res.getBody(); + + test(requestName, function() { expect(res.status).to.equal(401); + assert.isNotOk(body, `Expected body to be empty. Actual: ${JSON.stringify(body)}`); }); } diff --git a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/PlatformAccessToken_BadRequest.bru b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_PlatformAccessToken_OkEmpty.bru similarity index 69% rename from src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/PlatformAccessToken_BadRequest.bru rename to src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_PlatformAccessToken_OkEmpty.bru index 3b52d93a..fe433926 100644 --- a/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/PlatformAccessToken_BadRequest.bru +++ b/src/apps/Altinn.AccessManagement/test/Bruno/Altinn.AccessManagement/Automatic Test Collection/AppsInstanceDelegation/DelegationCheck/InstDelg_DelgChk_PlatformAccessToken_OkEmpty.bru @@ -1,5 +1,5 @@ meta { - name: PlatformAccessToken_BadRequest + name: InstDelg_DelgChk_PlatformAccessToken_OkEmpty type: http seq: 3 } @@ -43,10 +43,12 @@ script:pre-request { } tests { - test("AppsInstanceDelegation DelegationCheck GET PlatformAccessToken_Forbidden", function() { - var body = res.getBody(); - expect(res.status).to.equal(400); - expect(body.validationErrors[0].code).to.equal("AM.VLD-00004"); - expect(body.validationErrors[0].paths[0]).to.equal("appInstanceDelegationRequest.Resource"); + // Should be the same as the .bru request file. Used as prefix in test name which also shows in test result in pipeline. + const requestName = "InstDelg_DelgChk_PlatformAccessToken_OkEmpty"; + const body = res.getBody(); + + test(requestName + "|HttpStatus.OK and Body.Data empty", function() { + expect(res.status).to.equal(200); + assert.isEmpty(body.data, `Expected data in body to be empty.`); }); }