@@ -7,7 +7,12 @@ import { alice, bob, mallory, service } from './fixtures.js'
7
7
import { test , assert } from './test.js'
8
8
import * as Access from './service/access.js'
9
9
import { Verifier } from '@ucanto/principal/ed25519'
10
- import { Schema , UnavailableProof } from '@ucanto/validator'
10
+ import {
11
+ Schema ,
12
+ UnavailableProof ,
13
+ Unauthorized ,
14
+ Revoked ,
15
+ } from '@ucanto/validator'
11
16
import { Absentee } from '@ucanto/principal'
12
17
import { capability } from '../src/server.js'
13
18
import { isLink , parseLink , fail } from '../src/lib.js'
@@ -31,6 +36,7 @@ const context = {
31
36
resolve : link => ( {
32
37
error : new UnavailableProof ( link ) ,
33
38
} ) ,
39
+ validateAuthorization : ( ) => ( { ok : { } } ) ,
34
40
}
35
41
36
42
test ( 'invocation' , async ( ) => {
@@ -113,6 +119,7 @@ test('checks service id', async () => {
113
119
id : w3 ,
114
120
service : { identity : Access } ,
115
121
codec : CAR . inbound ,
122
+ validateAuthorization : ( ) => ( { ok : { } } ) ,
116
123
} )
117
124
118
125
const client = Client . connect ( {
@@ -186,6 +193,7 @@ test('checks for single capability invocation', async () => {
186
193
id : w3 ,
187
194
service : { identity : Access } ,
188
195
codec : CAR . inbound ,
196
+ validateAuthorization : ( ) => ( { ok : { } } ) ,
189
197
} )
190
198
191
199
const client = Client . connect ( {
@@ -237,6 +245,7 @@ test('test access/claim provider', async () => {
237
245
id : w3 ,
238
246
service : { access : Access } ,
239
247
codec : CAR . inbound ,
248
+ validateAuthorization : ( ) => ( { ok : { } } ) ,
240
249
} )
241
250
242
251
/**
@@ -305,6 +314,7 @@ test('handle did:mailto audiences', async () => {
305
314
const result = await handler ( request , {
306
315
id : w3 ,
307
316
principal : Verifier ,
317
+ validateAuthorization : ( ) => ( { ok : { } } ) ,
308
318
} )
309
319
310
320
assert . equal ( result . error , undefined )
@@ -328,6 +338,7 @@ test('handle did:mailto audiences', async () => {
328
338
const badAudience = await handler ( badRequest , {
329
339
id : w3 ,
330
340
principal : Verifier ,
341
+ validateAuthorization : ( ) => ( { ok : { } } ) ,
331
342
} )
332
343
333
344
assert . containSubset ( badAudience , {
@@ -661,6 +672,37 @@ test('fx.ok API', () => {
661
672
)
662
673
} )
663
674
675
+ test ( 'invocation fails if proof is revoked' , async ( ) => {
676
+ const proof = await Client . delegate ( {
677
+ issuer : w3 ,
678
+ audience : alice ,
679
+ capabilities : [
680
+ {
681
+ can : 'identity/register' ,
682
+
683
+ } ,
684
+ ] ,
685
+ } )
686
+
687
+ const invocation = await Client . delegate ( {
688
+ issuer : alice ,
689
+ audience : w3 ,
690
+ capabilities : proof . capabilities ,
691
+ proofs : [ proof ] ,
692
+ } )
693
+
694
+ const result = await Access . register ( invocation , {
695
+ ...context ,
696
+ validateAuthorization : auth => {
697
+ assert . deepEqual ( auth . delegation . cid , invocation . cid )
698
+ assert . deepEqual ( auth . delegation . proofs , [ proof ] )
699
+ return { error : new Revoked ( proof ) }
700
+ } ,
701
+ } )
702
+
703
+ assert . match ( String ( result . error ) , / P r o o f b a f y .* h a s b e e n r e v o k e d / )
704
+ } )
705
+
664
706
/**
665
707
* @template {Record<string, any>} Service
666
708
* @param {Service } service
@@ -670,6 +712,7 @@ const setup = service => {
670
712
id : w3 ,
671
713
service,
672
714
codec : CAR . inbound ,
715
+ validateAuthorization : ( ) => ( { ok : { } } ) ,
673
716
} )
674
717
675
718
const consumer = Client . connect ( {
0 commit comments