From fed1e9309676aae95eac5e7c20324d8a45a6bd0f Mon Sep 17 00:00:00 2001 From: Liran Cohen Date: Sat, 10 Aug 2024 15:02:56 -0400 Subject: [PATCH] update connected permissions processing of grants, and tests --- packages/agent/src/permissions-api.ts | 1 - .../agent/tests/connected-permissions.spec.ts | 27 +++++-------------- packages/agent/tests/dwn-api.spec.ts | 12 --------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/packages/agent/src/permissions-api.ts b/packages/agent/src/permissions-api.ts index f6612fe59..4fcb441a8 100644 --- a/packages/agent/src/permissions-api.ts +++ b/packages/agent/src/permissions-api.ts @@ -185,7 +185,6 @@ export class AgentPermissionsApi implements PermissionsApi { protocol : PermissionsProtocol.uri, protocolPath : PermissionsProtocol.grantPath, dataFormat : 'application/json', - data : permissionsGrantBytes, tags }; diff --git a/packages/agent/tests/connected-permissions.spec.ts b/packages/agent/tests/connected-permissions.spec.ts index 8e95b69e3..94bb3c826 100644 --- a/packages/agent/tests/connected-permissions.spec.ts +++ b/packages/agent/tests/connected-permissions.spec.ts @@ -3,7 +3,7 @@ import { DwnInterfaceName, DwnMethodName, Jws, Message, ProtocolDefinition, Time import type { BearerIdentity } from '../src/bearer-identity.js'; import { TestAgent } from './utils/test-agent.js'; -import { DwnInterface, ProcessDwnRequest } from '../src/types/dwn.js'; +import { DwnInterface } from '../src/types/dwn.js'; import { testDwnUrl } from './utils/test-config.js'; import { PlatformAgentTestHarness } from '../src/test-harness.js'; @@ -101,25 +101,15 @@ describe('Connect Flow Permissions', () => { // alice creates a permission grant const messagesQueryGrant = await aliceAgent.agent.permissions.createGrant({ - store : false, + store : true, author : alice.did.uri, grantedTo : appX.did.uri, dateExpires : Time.createOffsetTimestamp({ seconds: 60 }), scope : { interface: DwnInterfaceName.Messages, method: DwnMethodName.Query } }); - // alice stores and processes the permission grant on her DWN - const { encodedData: messagesQueryGrantData, ...messagesQueryGrantMessage } = messagesQueryGrant.message; - const { reply: aliceGrantReply } = await aliceAgent.agent.dwn.processRequest({ - messageType : DwnInterface.RecordsWrite, - rawMessage : messagesQueryGrantMessage, - author : alice.did.uri, - target : alice.did.uri, - dataStream : new Blob([ Convert.base64Url(messagesQueryGrantData).toUint8Array() ]), - }); - expect(aliceGrantReply.status.code).to.equal(202); - // The App processes the permission grant given by Alice, so it can be accessible when using it + const { encodedData: messagesQueryGrantData, ...messagesQueryGrantMessage } = messagesQueryGrant.message; const { reply: appAgentGrantReply } = await appAgent.agent.dwn.processRequest({ messageType : DwnInterface.RecordsWrite, rawMessage : messagesQueryGrantMessage, @@ -129,28 +119,25 @@ describe('Connect Flow Permissions', () => { }); expect(appAgentGrantReply.status.code).to.equal(202); - const writeGrantToGrantee: ProcessDwnRequest = { + const { reply: importGrantReply } = await appAgent.agent.dwn.processRequest({ messageType : DwnInterface.RecordsWrite, rawMessage : messagesQueryGrantMessage, author : appX.did.uri, target : appX.did.uri, dataStream : new Blob([ Convert.base64Url(messagesQueryGrantData).toUint8Array() ]), signAsOwner : true - }; - - const { reply: importGrantReply } = await appAgent.agent.dwn.processRequest(writeGrantToGrantee); + }); expect(importGrantReply.status.code).to.equal(202); // Attempt to process the MessagesQuery locally using the permission grant. const { message: queryMessage, reply } = await appAgent.agent.dwn.processRequest({ - author : alice.did.uri, + author : appX.did.uri, target : alice.did.uri, messageType : DwnInterface.MessagesQuery, messageParams : { filters : [], permissionGrantId : messagesQueryGrant.message.recordId - }, - granteeDid: appX.did.uri, + } }); const messageSignature = queryMessage!.authorization.signature.signatures[0]; const signatureDid = Jws.getSignerDid(messageSignature); diff --git a/packages/agent/tests/dwn-api.spec.ts b/packages/agent/tests/dwn-api.spec.ts index 50def9719..9ab4aca3f 100644 --- a/packages/agent/tests/dwn-api.spec.ts +++ b/packages/agent/tests/dwn-api.spec.ts @@ -767,18 +767,6 @@ describe('AgentDwnApi', () => { scope : { interface: DwnInterfaceName.Records, method: DwnMethodName.Write, protocol: protocolDefinition.protocol } }); - // process the grant on alice's DWN - const { encodedData: recordsWriteGrantData, ...recordsWriteGrantMessage } = recordsWriteDelegateGrant.message; - let { reply: { status: grantStatus } } = await testHarness.agent.dwn.processRequest({ - author : alice.did.uri, - target : alice.did.uri, - messageType : DwnInterface.RecordsWrite, - rawMessage : recordsWriteGrantMessage, - dataStream : new Blob([ Convert.base64Url(recordsWriteGrantData).toUint8Array() ]), - }); - expect(grantStatus.code).to.equal(202, 'grant write'); - - // bob authors a public record to his dwn const dataStream = new Blob([ Convert.string('Hello, world!').toUint8Array() ]);