Skip to content

Commit

Permalink
chore: add missing principal aligment test (#134)
Browse files Browse the repository at this point in the history
* chore: add missing principal aligment test

* chore: add another test
  • Loading branch information
Gozala authored Nov 17, 2022
1 parent 947e0f3 commit 5d04d16
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/validator/test/lib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,75 @@ test('authorize / resolve external proof', async () => {
],
})
})

test('invalid claim / principal aligment', async () => {
const proof = await storeAdd.delegate({
issuer: alice,
audience: bob,
with: alice.did(),
})

const nb = { link: Link.parse('bafkqaaa') }
const invocation = storeAdd.invoke({
issuer: mallory,
audience: w3,
with: alice.did(),
nb,
proofs: [proof],
})

const result = await access(await invocation.delegate(), {
principal: ed25519.Verifier,
capability: storeAdd,
})

assert.containSubset(result, {
name: 'Unauthorized',
cause: {
name: 'InvalidClaim',
message: `Claimed capability {"can":"store/add","with":"${alice.did()}","nb":${JSON.stringify(
nb
)}} is invalid
- Capability can not be (self) issued by '${mallory.did()}'
- Can not derive from prf:0 - ${proof.cid} because:
- Delegates to '${bob.did()}' instead of '${mallory.did()}'`,
},
})
})

test('invalid claim / invalid delegation chain', async () => {
const space = alice

const proof = await storeAdd.delegate({
issuer: space,
audience: w3,
with: space.did(),
})

const nb = { link: Link.parse('bafkqaaa') }
const invocation = storeAdd.invoke({
issuer: bob,
audience: w3,
with: space.did(),
nb,
proofs: [proof],
})

const result = await access(await invocation.delegate(), {
principal: ed25519.Verifier,
capability: storeAdd,
})

assert.containSubset(result, {
name: 'Unauthorized',
cause: {
name: 'InvalidClaim',
message: `Claimed capability {"can":"store/add","with":"${space.did()}","nb":${JSON.stringify(
nb
)}} is invalid
- Capability can not be (self) issued by '${bob.did()}'
- Can not derive from prf:0 - ${proof.cid} because:
- Delegates to '${w3.did()}' instead of '${bob.did()}'`,
},
})
})

0 comments on commit 5d04d16

Please # to comment.