Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IsAccessListModeApplicable Check #173

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ public async Task<DelegationActionResult> DelegateRights(int authenticatedUserId
List<Right> rightsUserCantDelegate = new List<Right>();
foreach (Right rightToDelegate in delegation.Rights)
{
if (usersDelegableRights.Contains(rightToDelegate))
Right delegableRight = usersDelegableRights.Find(r => r.RightKey == rightToDelegate.RightKey);
if (delegableRight != null)
{
// If delegable and serviceResource.AccessListMode is enabled, call accessListAuthorizationClient
AccessListAuthorizationResult accessListAuthorizationResult = AccessListAuthorizationResult.NotApplicable;
if (DelegationHelper.IsAccessListModeEnabledAndApplicable(rightToDelegate, resource, fromParty))
if (DelegationHelper.IsAccessListModeEnabledAndApplicable(delegableRight, resource, fromParty))
{
AccessListAuthorizationRequest accessListAuthorizationRequest = new AccessListAuthorizationRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
meta {
name: AccessListDelegationCheck_Dagl_OrgPartialAccess
type: http
seq: 1
}

post {
url: {{baseUrl}}/accessmanagement/api/v1/internal/{{party}}/rights/delegation/delegationcheck
body: json
auth: inherit
}

body:json {
{
"resource": [
{
"id": "urn:altinn:resource",
"value": "{{resource}}"
}
]
}
}

script:pre-request {
const testdata = require(`./Testdata/accesslist-delegation/${bru.getEnvVar("tokenEnv")}.json`);
const sharedtestdata = require(`./Testdata/sharedtestdata.json`);
bru.setVar("party", testdata.OrdentligUlasteligStruts.partyid);
bru.setVar("resource", testdata.resource);

var getTokenParameters = {
auth_tokenType: sharedtestdata.authTokenType.personal,
auth_userId: testdata.OrdentligUlasteligStruts.dagl.userid,
auth_partyId: testdata.OrdentligUlasteligStruts.dagl.partyid,
auth_ssn: testdata.OrdentligUlasteligStruts.dagl.pid
}

const token = await testTokenGenerator.getToken(getTokenParameters);
bru.setVar("bearerToken", token);
}

tests {
// 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 = "AccessListDelegationCheck_Dagl_OrgPartialAccess";
const body = res.getBody();

test(requestName + "|HttpStatus.OK", function() {
expect(res.status).to.equal(200);
});

test(requestName + "|Read_IsDelegable", function() {
const right = body.find(right => right.rightKey === "devtest_gar_bruno_accesslist_actionfilter:read");
assert.equal(right.status, "Delegable", `Expected read to be: Delegable`);
});

test(requestName + "|Write_IsNotDelegable", function() {
const right = body.find(right => right.rightKey === "devtest_gar_bruno_accesslist_actionfilter:write");
assert.equal(right.status, "NotDelegable", `Expected write to be; NotDelegable`);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
meta {
name: AccessListDelegation_Dagl_OrgPartialAccessRead
type: http
seq: 2
}

post {
url: {{baseUrl}}/accessmanagement/api/v1/internal/{{party}}/rights/delegation/offered
body: json
auth: inherit
}

body:json {
{
"to": [
{
"id": "urn:altinn:person:identifier-no",
"value": "{{toSsn}}"
},
{
"id": "urn:altinn:person:lastname",
"value": "{{toLastName}}"
}
],
"rights": [
{
"resource": [
{
"id": "urn:altinn:resource",
"value": "{{resource}}"
}
],
"action": "read"
},
{
"resource": [
{
"id": "urn:altinn:resource",
"value": "{{resource}}"
}
],
"action": "write"
}
]
}
}

script:pre-request {
const testdata = require(`./Testdata/accesslist-delegation/${bru.getEnvVar("tokenEnv")}.json`);
const sharedtestdata = require(`./Testdata/sharedtestdata.json`);
bru.setVar("party", testdata.SvenskGeniærklertTiger.partyid);
bru.setVar("resource", testdata.resource);
bru.setVar("toSsn", testdata.SvenskGeniærklertTiger.dagl.pid);
bru.setVar("toLastName", "KRYDDERMÅL");

var getTokenParameters = {
auth_tokenType: sharedtestdata.authTokenType.personal,
auth_userId: testdata.SvenskGeniærklertTiger.dagl.userid,
auth_partyId: testdata.SvenskGeniærklertTiger.dagl.partyid,
auth_ssn: testdata.SvenskGeniærklertTiger.dagl.pid
}

const token = await testTokenGenerator.getToken(getTokenParameters);
bru.setVar("bearerToken", token);
}

tests {
// 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 = "AccessListDelegation_Dagl_OrgPartialAccess";
const body = res.getBody();

test(requestName + "|HttpStatus.OK", function() {
expect(res.status).to.equal(200);
});

test(requestName + "|Read_IsDelegable", function() {
const right = body.rightDelegationResults.find(right => right.rightKey === "devtest_gar_bruno_accesslist_actionfilter:read");
assert.equal(right.status, "Delegated", `Expected read to be: Delegated`);
});

test(requestName + "|Write_IsNotDelegable", function() {
const right = body.rightDelegationResults.find(right => right.rightKey === "devtest_gar_bruno_accesslist_actionfilter:write");
assert.equal(right.status, "NotDelegated", `Expected read to be: NotDelegated`);
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: non-tilgangsstyrer cannot see offered delegations
type: http
seq: 41
seq: 42
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: non-tilgangsstyrer cannot see received delegations
type: http
seq: 42
seq: 43
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o cannot delegate to itself
type: http
seq: 36
seq: 37
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o delegate org2org (again)
type: http
seq: 25
seq: 26
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o delegate org2org
type: http
seq: 21
seq: 22
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o org attempts to delegate to itself
type: http
seq: 35
seq: 36
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o org2org delegation successful
type: http
seq: 22
seq: 23
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o receiving org no longer has delegation (again)
type: http
seq: 27
seq: 28
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o receiving org no longer has delegation
type: http
seq: 24
seq: 25
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o receiving org revokes delegation from org
type: http
seq: 23
seq: 24
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2o sending org revokes delegation to org
type: http
seq: 26
seq: 27
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2p delegate org2person (again)
type: http
seq: 18
seq: 19
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2p delegate org2person
type: http
seq: 14
seq: 15
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2p org2person delegation successful
type: http
seq: 15
seq: 16
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2p receiving person has no delegation (again)
type: http
seq: 20
seq: 21
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2p receiving person no longer has delegation
type: http
seq: 17
seq: 18
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2p receiving person revokes delegation from org
type: http
seq: 16
seq: 17
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: o2p sending org revokes delegation to person
type: http
seq: 19
seq: 20
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o delegate person2org (again)
type: http
seq: 32
seq: 33
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o delegate person2org
type: http
seq: 28
seq: 29
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o person2org delegation successful
type: http
seq: 29
seq: 30
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o receiving org no longer has delegation (again)
type: http
seq: 34
seq: 35
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o receiving org no longer has delegation
type: http
seq: 31
seq: 32
}

get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o receiving org revokes delegation from person
type: http
seq: 30
seq: 31
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o sending person revokes delegation to org
type: http
seq: 33
seq: 34
}

post {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: p2o testdata cleanup (revoke delegation)
type: http
seq: 4
seq: 5
}

post {
Expand Down
Loading
Loading