@@ -335,3 +335,124 @@ describe('WAC Integration', () => {
335335 } ) ;
336336 } ) ;
337337} ) ;
338+
339+ describe ( 'WAC Conditions' , ( ) => {
340+ describe ( 'parseAcl with conditions' , ( ) => {
341+ it ( 'should parse a PaymentCondition' , async ( ) => {
342+ const acl = {
343+ '@context' : { 'acl' : 'http://www.w3.org/ns/auth/acl#' } ,
344+ '@graph' : [ {
345+ '@id' : '#paid' ,
346+ '@type' : 'acl:Authorization' ,
347+ 'acl:agentClass' : { '@id' : 'acl:AuthenticatedAgent' } ,
348+ 'acl:accessTo' : { '@id' : 'https://alice.example/premium/article.jsonld' } ,
349+ 'acl:mode' : [ { '@id' : 'acl:Read' } ] ,
350+ 'acl:condition' : {
351+ '@type' : 'PaymentCondition' ,
352+ 'amount' : '1000' ,
353+ 'currency' : 'sats'
354+ }
355+ } ]
356+ } ;
357+
358+ const auths = await parseAcl ( JSON . stringify ( acl ) , 'https://alice.example/premium/.acl' ) ;
359+
360+ assert . strictEqual ( auths . length , 1 ) ;
361+ assert . strictEqual ( auths [ 0 ] . conditions . length , 1 ) ;
362+ assert . strictEqual ( auths [ 0 ] . conditions [ 0 ] . type , 'PaymentCondition' ) ;
363+ assert . strictEqual ( auths [ 0 ] . conditions [ 0 ] . amount , '1000' ) ;
364+ assert . strictEqual ( auths [ 0 ] . conditions [ 0 ] . currency , 'sats' ) ;
365+ } ) ;
366+
367+ it ( 'should parse multiple conditions' , async ( ) => {
368+ const acl = {
369+ '@context' : { 'acl' : 'http://www.w3.org/ns/auth/acl#' } ,
370+ '@graph' : [ {
371+ '@id' : '#restricted' ,
372+ '@type' : 'acl:Authorization' ,
373+ 'acl:agent' : { '@id' : 'https://bob.example/#me' } ,
374+ 'acl:accessTo' : { '@id' : 'https://alice.example/resource' } ,
375+ 'acl:mode' : [ { '@id' : 'acl:Read' } ] ,
376+ 'acl:condition' : [
377+ { '@type' : 'PaymentCondition' , 'amount' : '500' , 'currency' : 'sats' } ,
378+ { '@type' : 'ClientCondition' , 'client' : 'https://trusted.app/pane.js' }
379+ ]
380+ } ]
381+ } ;
382+
383+ const auths = await parseAcl ( JSON . stringify ( acl ) , 'https://alice.example/.acl' ) ;
384+
385+ assert . strictEqual ( auths [ 0 ] . conditions . length , 2 ) ;
386+ assert . strictEqual ( auths [ 0 ] . conditions [ 0 ] . type , 'PaymentCondition' ) ;
387+ assert . strictEqual ( auths [ 0 ] . conditions [ 1 ] . type , 'ClientCondition' ) ;
388+ } ) ;
389+
390+ it ( 'should parse authorization without conditions' , async ( ) => {
391+ const acl = {
392+ '@context' : { 'acl' : 'http://www.w3.org/ns/auth/acl#' } ,
393+ '@graph' : [ {
394+ '@id' : '#public' ,
395+ '@type' : 'acl:Authorization' ,
396+ 'acl:agentClass' : { '@id' : 'http://xmlns.com/foaf/0.1/Agent' } ,
397+ 'acl:accessTo' : { '@id' : 'https://alice.example/public/' } ,
398+ 'acl:mode' : [ { '@id' : 'acl:Read' } ]
399+ } ]
400+ } ;
401+
402+ const auths = await parseAcl ( JSON . stringify ( acl ) , 'https://alice.example/.acl' ) ;
403+
404+ assert . strictEqual ( auths [ 0 ] . conditions . length , 0 ) ;
405+ } ) ;
406+ } ) ;
407+
408+ describe ( 'fail-closed conditions' , ( ) => {
409+ it ( 'should parse unsupported condition types' , async ( ) => {
410+ const acl = {
411+ '@context' : { 'acl' : 'http://www.w3.org/ns/auth/acl#' } ,
412+ '@graph' : [ {
413+ '@id' : '#restricted' ,
414+ '@type' : 'acl:Authorization' ,
415+ 'acl:agent' : { '@id' : 'https://bob.example/#me' } ,
416+ 'acl:accessTo' : { '@id' : 'https://alice.example/resource' } ,
417+ 'acl:mode' : [ { '@id' : 'acl:Read' } ] ,
418+ 'acl:condition' : {
419+ '@type' : 'UnknownFutureCondition' ,
420+ 'foo' : 'bar'
421+ }
422+ } ]
423+ } ;
424+
425+ const auths = await parseAcl ( JSON . stringify ( acl ) , 'https://alice.example/.acl' ) ;
426+
427+ assert . strictEqual ( auths [ 0 ] . conditions . length , 1 ) ;
428+ assert . strictEqual ( auths [ 0 ] . conditions [ 0 ] . type , 'UnknownFutureCondition' ) ;
429+ } ) ;
430+
431+ it ( 'should parse PaymentCondition with all fields' , async ( ) => {
432+ const acl = {
433+ '@context' : { 'acl' : 'http://www.w3.org/ns/auth/acl#' } ,
434+ '@graph' : [ {
435+ '@id' : '#paid' ,
436+ '@type' : 'acl:Authorization' ,
437+ 'acl:agentClass' : { '@id' : 'acl:AuthenticatedAgent' } ,
438+ 'acl:accessTo' : { '@id' : 'https://alice.example/premium/article.jsonld' } ,
439+ 'acl:mode' : [ { '@id' : 'acl:Read' } ] ,
440+ 'acl:condition' : {
441+ '@type' : 'PaymentCondition' ,
442+ 'amount' : '1000' ,
443+ 'currency' : 'sats' ,
444+ 'protocol' : 'lightning'
445+ }
446+ } ]
447+ } ;
448+
449+ const auths = await parseAcl ( JSON . stringify ( acl ) , 'https://alice.example/premium/.acl' ) ;
450+ const condition = auths [ 0 ] . conditions [ 0 ] ;
451+
452+ assert . strictEqual ( condition . type , 'PaymentCondition' ) ;
453+ assert . strictEqual ( condition . amount , '1000' ) ;
454+ assert . strictEqual ( condition . currency , 'sats' ) ;
455+ assert . strictEqual ( condition . protocol , 'lightning' ) ;
456+ } ) ;
457+ } ) ;
458+ } ) ;
0 commit comments