From 0dfea2163b86e0a18023d0590399f84fcfd19e93 Mon Sep 17 00:00:00 2001 From: Henry Tsai Date: Mon, 30 Sep 2024 15:27:57 -0700 Subject: [PATCH] Minor tweak to test to show nested-role authorized query + minor typo fixes. (#808) The same test already does a nested-role authorized query on messages within a channel, but adding this to reenforce the same point. --- tests/features/author-delegated-grant.spec.ts | 4 ++-- tests/scenarios/nested-roles.spec.ts | 17 ++++++++++++++++- tests/vectors/protocol-definitions/slack.json | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/features/author-delegated-grant.spec.ts b/tests/features/author-delegated-grant.spec.ts index 79469b183..f93076158 100644 --- a/tests/features/author-delegated-grant.spec.ts +++ b/tests/features/author-delegated-grant.spec.ts @@ -95,7 +95,7 @@ export function testAuthorDelegatedGrant(): void { protocolDefinition : emailProtocolDefinition, }); - // Bob should be abel to configure a protocol on behalf of alice + // Bob should be able to configure a protocol on behalf of alice const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message); expect(protocolConfigureReply.status.code).to.equal(202); @@ -147,7 +147,7 @@ export function testAuthorDelegatedGrant(): void { protocolDefinition : emailProtocolDefinition, }); - // Bob should be abel to configure a protocol on behalf of alice + // Bob should be able to configure a protocol on behalf of alice const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message); expect(protocolConfigureReply.status.code).to.equal(202); diff --git a/tests/scenarios/nested-roles.spec.ts b/tests/scenarios/nested-roles.spec.ts index 563d39ddb..a40ce4b6a 100644 --- a/tests/scenarios/nested-roles.spec.ts +++ b/tests/scenarios/nested-roles.spec.ts @@ -65,10 +65,11 @@ export function testNestedRoleScenarios(): void { // 4. Bob can invoke his `admin` role to perform actions: // 4a. Bob can read the community record // 4b. Bob can create gated-channels 1 & 2 in the community + // 4c. Bob can query all gated-channels in the community // 5. Bob as the creator/author of the channels can add participants in the gated-channels // 5a. Bob can add himself and Carol as participants in the gated-channel 1 // 5b. Bob can add himself and Daniel as participants in the gated-channel 2 - // 6. Carol can read the gated channel 2 record by invoking her child participant role to the gated channel 2 + // 6. Carol can read the gated channel 1 record by invoking her child participant role to the gated channel 1 // 7. Carol CANNOT add anyone as a participant in the gated-channel 2 since she is not a participant in the channel // 8. Carol CANNOT add Daniel as another participant in the gated-channel without invoking her role // 9. Carol can invoke her participant role to add Daniel as another participant in the gated-channel @@ -151,6 +152,20 @@ export function testNestedRoleScenarios(): void { const channel2RecordReply = await dwn.processMessage(alice.did, channel2Record.message, { dataStream: channel2Record.dataStream }); expect(channel2RecordReply.status.code).to.equal(202); + // 4c. Bob can query all gated-channels in the community + const bobQuery = await RecordsQuery.create({ + signer : Jws.createSigner(bob), + protocolRole : 'community/admin', + filter : { + protocol : protocolDefinition.protocol, + protocolPath : 'community/gatedChannel', + contextId : communityRecord.message.contextId + } + }); + const bobQueryReply = await dwn.processMessage(alice.did, bobQuery.message); + expect(bobQueryReply.status.code).to.equal(200); + expect(bobQueryReply.entries?.length).to.equal(2); + // 5. Bob as the creator/author of the channels can add participants in the gated-channels // 5a. Bob can add himself and Carol as participants in the gated-channel 1 const channel1ParticipantBobRecord = await TestDataGenerator.generateRecordsWrite({ diff --git a/tests/vectors/protocol-definitions/slack.json b/tests/vectors/protocol-definitions/slack.json index 38a618940..a1407d7ba 100644 --- a/tests/vectors/protocol-definitions/slack.json +++ b/tests/vectors/protocol-definitions/slack.json @@ -156,6 +156,7 @@ "can": [ "create", "update", + "query", "co-delete" ] },