-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { receiptsEndpoint } from './helpers/utils.js' | |
import { Absentee } from '@ucanto/principal' | ||
import { DIDMailto } from '../src/capability/access.js' | ||
import { confirmConfirmationUrl } from '../../upload-api/test/helpers/utils.js' | ||
import * as SpaceCapability from '@web3-storage/capabilities/space' | ||
|
||
/** @type {Test.Suite} */ | ||
export const testClient = { | ||
|
@@ -528,6 +529,45 @@ export const testClient = { | |
) | ||
}, | ||
}), | ||
authorizeGateway: Test.withContext({ | ||
'should authorize a gateway to serve content from a space': async ( | ||
assert, | ||
{ client, mail, grantAccess } | ||
) => { | ||
// Step 1: Create a client for Alice and login | ||
const aliceEmail = '[email protected]' | ||
const aliceLogin = client.login(aliceEmail) | ||
const message = await mail.take() | ||
assert.deepEqual(message.to, aliceEmail) | ||
await grantAccess(message) | ||
const aliceAccount = await aliceLogin | ||
|
||
// Step 2: Alice creates a space | ||
const spaceA = await client.createSpace('authorize-gateway-space', { | ||
account: aliceAccount, | ||
}) | ||
assert.ok(spaceA) | ||
await client.setCurrentSpace(spaceA.did()) | ||
|
||
// Step 3: Authorize the gateway to serve content from the space | ||
const delegation = await client.authorizeGateway(spaceA, { | ||
gateway: 'did:web:staging.w3s.link', | ||
expiration: Infinity, | ||
}) | ||
assert.ok(delegation) | ||
|
||
// Step 4: Find the delegation for the default gateway | ||
assert.equal(delegation.audience.did(), 'did:web:staging.w3s.link') | ||
assert.ok( | ||
delegation.capabilities.some( | ||
// @ts-expect-error | ||
(c) => | ||
c.can === SpaceCapability.contentServe.can && | ||
c.with === spaceA.did() | ||
) | ||
) | ||
}, | ||
}), | ||
proofs: { | ||
'should get proofs': async (assert) => { | ||
const alice = new Client(await AgentData.create()) | ||
|