Skip to content

Commit

Permalink
Bump DWN SDK 0.2.8 (#310)
Browse files Browse the repository at this point in the history
* bump dwn-sdk to v0.2.8, update ProtocolQuery tests

---------


Co-authored-by: Frank Hinek <[email protected]>
  • Loading branch information
LiranCohen and frankhinek authored Nov 22, 2023
1 parent da7786d commit c417ba0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 33 deletions.
26 changes: 6 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@tbd54566975/dwn-sdk-js": "0.2.6",
"@tbd54566975/dwn-sdk-js": "0.2.8",
"@web5/common": "0.2.1",
"@web5/crypto": "0.2.2",
"@web5/dids": "0.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@tbd54566975/dwn-sdk-js": "0.2.6",
"@tbd54566975/dwn-sdk-js": "0.2.8",
"@web5/agent": "0.2.4",
"@web5/crypto": "0.2.2",
"@web5/dids": "0.2.2",
Expand Down
72 changes: 62 additions & 10 deletions packages/api/tests/dwn-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,77 @@ describe('DwnApi', () => {
expect(response.protocols.length).to.equal(0);
});

it('returns a 401 when authorization fails', async () => {
/** Create a new DID to represent an external entity who has a remote
* DWN server defined in their DID document. */
const { did: bob } = await testAgent.createIdentity({ testDwnUrls });
it('returns published protocol definitions for requests from external DID', async () => {
// Configure a published protocol on Alice's local DWN.
const publicProtocol = await dwnAlice.protocols.configure({
message: {
definition: { ...emailProtocolDefinition, protocol: 'http://proto-published', published: true }
}
});
expect(publicProtocol.status.code).to.equal(202);

// Attempt to query for a protocol using Bob's DWN tenant.
const response = await dwnAlice.protocols.query({
from : bob.did,
// Configure the published protocol on Alice's remote DWN.
const sendPublic = await publicProtocol.protocol.send(aliceDid.did);
expect(sendPublic.status.code).to.equal(202);

// Attempt to query for the published protocol on Alice's remote DWN authored by Bob.
const publishedResponse = await dwnBob.protocols.query({
from : aliceDid.did,
message : {
filter: {
protocol: 'http://proto-published'
}
}
});

// Verify that one query result is returned.
expect(publishedResponse.status.code).to.equal(200);
expect(publishedResponse.protocols.length).to.equal(1);
expect(publishedResponse.protocols[0].definition.protocol).to.equal('http://proto-published');
});

it('does not return unpublished protocol definitions for requests from external DID', async () => {
// Configure an unpublished protocol on Alice's DWN.
const notPublicProtocol = await dwnAlice.protocols.configure({
message: {
definition: { ...emailProtocolDefinition, protocol: 'http://proto-not-published', published: false }
}
});
expect(notPublicProtocol.status.code).to.equal(202);

// Configure the unpublished protocol on Alice's remote DWN.
const sendNotPublic = await notPublicProtocol.protocol.send(aliceDid.did);
expect(sendNotPublic.status.code).to.equal(202);

// Attempt to query for the unpublished protocol on Alice's remote DWN authored by Bob.
const nonPublishedResponse = await dwnBob.protocols.query({
from : aliceDid.did,
message : {
filter: {
protocol: 'http://proto-not-published'
}
}
});

// Verify that no query results are returned.
expect(nonPublishedResponse.status.code).to.equal(200);
expect(nonPublishedResponse.protocols.length).to.equal(0);
});

it('returns a 401 with an invalid permissions grant', async () => {
// Attempt to query for a record using Bob's DWN tenant with an invalid grant.
const response = await dwnAlice.protocols.query({
from : bobDid.did,
message : {
permissionsGrantId : 'bafyreiduimprbncdo2oruvjrvmfmwuyz4xx3d5biegqd2qntlryvuuosem',
filter : {
protocol: 'https://doesnotexist.com/protocol'
}
}
});

/** Confirm that authorization failed because the test identity does not have
* permission to delete a record from Bob's DWN. */
expect(response.status.code).to.equal(401);
expect(response.status.detail).to.include('ProtocolsQuery failed authorization');
expect(response.status.detail).to.include('GrantAuthorizationGrantMissing');
expect(response.protocols).to.exist;
expect(response.protocols.length).to.equal(0);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-env/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ version: "3.98"
services:
dwn-server:
container_name: dwn-server
image: ghcr.io/tbd54566975/dwn-server:dwn-sdk-0.2.6
image: ghcr.io/tbd54566975/dwn-server:dwn-sdk-0.2.8
ports:
- "3000:3000"

0 comments on commit c417ba0

Please sign in to comment.