Skip to content

Commit

Permalink
fix: provider/add test to (hopefully) properly create authorization (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gobengo authored Mar 7, 2023
1 parent dc0eb51 commit 811fa09
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions packages/access-api/test/provider-add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,38 @@ for (const accessApiVariant of /** @type {const} */ ([
) {
it('provider/add allows for access/delegate', async () => {
const space = await principal.ed25519.generate()
const issuer = await accessApiVariant.issuer
const agent = await accessApiVariant.issuer
const service = await accessApiVariant.audience
const accountDid = /** @type {const} */ ('did:mailto:example.com:foo')
const serviceSessionAttest = await ucanto.delegate({
issuer: service,
audience: issuer,

const accountAuthorizesIssuerClaim = await ucanto.delegate({
issuer: principal.Absentee.from({ id: accountDid }),
audience: agent,
capabilities: [
{
can: 'provider/add',
with: accountDid,
with: 'ucan:*',
can: '*',
},
],
})
const serviceAttestsThatAccountAuthorizesIssuer = await ucanto.delegate({
issuer: service,
audience: agent,
capabilities: [
{
can: 'access/delegate',
with: space.did(),
with: service.did(),
can: 'ucan/attest',
nb: { proof: accountAuthorizesIssuerClaim.cid },
},
],
})
const sessionProofs = [
await ucanto.delegate({
issuer: service,
audience: issuer,
capabilities: [
{
can: 'ucan/attest',
with: accountDid,
nb: {
// note: whole delegation is also included in 'proofs'
proof: serviceSessionAttest.cid,
},
},
],
}),
serviceSessionAttest,
accountAuthorizesIssuerClaim,
serviceAttestsThatAccountAuthorizesIssuer,
]
const addStorageProvider = await ucanto
.invoke({
issuer,
issuer: agent,
audience: service,
capability: {
can: 'provider/add',
Expand All @@ -154,18 +149,18 @@ for (const accessApiVariant of /** @type {const} */ ([
},
},
proofs: [
...sessionProofs,
// space says issuer can provider/add with this account
await ucanto.delegate({
issuer: space,
audience: issuer,
audience: agent,
capabilities: [
{
can: 'provider/add',
with: accountDid,
},
],
}),
...sessionProofs,
],
})
.delegate()
Expand All @@ -177,7 +172,7 @@ for (const accessApiVariant of /** @type {const} */ ([
// storage provider added. So we should be able to delegate now
const accessDelegate = await ucanto
.invoke({
issuer,
issuer: agent,
audience: service,
capability: {
can: 'access/delegate',
Expand All @@ -186,7 +181,19 @@ for (const accessApiVariant of /** @type {const} */ ([
delegations: {},
},
},
proofs: [...sessionProofs],
proofs: [
...sessionProofs,
await ucanto.delegate({
issuer: space,
audience: agent,
capabilities: [
{
can: 'access/delegate',
with: space.did(),
},
],
}),
],
})
.delegate()
const accessDelegateResult = await accessApiVariant.invoke(accessDelegate)
Expand Down

0 comments on commit 811fa09

Please # to comment.