@@ -19,6 +19,7 @@ import env from './mocks/env.js';
1919import jose from './mocks/jose.js' ;
2020import fetch from './mocks/fetch.js' ;
2121import {
22+ configPermissionPath ,
2223 getAclCtx ,
2324 getChildRules ,
2425 getUserActions ,
@@ -531,6 +532,56 @@ describe('DA auth', () => {
531532 assert ( ! aclCtx . actionSet . has ( 'write' ) ) ;
532533 } ) ;
533534
535+ it ( 'configPermissionPath returns CONFIG for org config' , ( ) => {
536+ assert . strictEqual ( configPermissionPath ( { } ) , 'CONFIG' ) ;
537+ } ) ;
538+
539+ it ( 'configPermissionPath returns /{site}/CONFIG for site config' , ( ) => {
540+ assert . strictEqual ( configPermissionPath ( { site : 'mysite' } ) , '/mysite/CONFIG' ) ;
541+ } ) ;
542+
543+ it ( 'test site CONFIG governs site config read' , async ( ) => {
544+ const siteConfig = {
545+ test : {
546+ ':type' : 'sheet' ,
547+ ':sheetname' : 'permissions' ,
548+ data : [
549+ { path : '/mysite/CONFIG' , groups : 'reader@bloggs.org' , actions : 'read' } ,
550+ { path : 'CONFIG' , groups : 'orgadmin@bloggs.org' , actions : 'write' } ,
551+ ] ,
552+ } ,
553+ } ;
554+ const siteEnv = { DA_CONFIG : { get : ( name ) => siteConfig [ name ] } } ;
555+
556+ const reader = [ { email : 'reader@bloggs.org' } ] ;
557+ const aclCtx = await getAclCtx ( siteEnv , 'test' , reader , 'mysite/config.json' , 'config' ) ;
558+
559+ // The index.js gate always allows reaching the config route for config requests.
560+ assert ( aclCtx . actionSet . has ( 'read' ) ) ;
561+
562+ // The reader can read this site's config.
563+ assert ( hasPermission ( {
564+ users : reader , org : 'test' , aclCtx, key : 'mysite/config.json' , site : 'mysite' ,
565+ } , configPermissionPath ( { site : 'mysite' } ) , 'read' , true ) ) ;
566+
567+ // The reader cannot write this site's config.
568+ assert ( ! hasPermission ( {
569+ users : reader , org : 'test' , aclCtx, key : 'mysite/config.json' , site : 'mysite' ,
570+ } , configPermissionPath ( { site : 'mysite' } ) , 'write' , true ) ) ;
571+
572+ // A user without the site CONFIG permission cannot read this site's config.
573+ const stranger = [ { email : 'orgadmin@bloggs.org' } ] ;
574+ const strangerCtx = await getAclCtx ( siteEnv , 'test' , stranger , 'mysite/config.json' , 'config' ) ;
575+ assert ( ! hasPermission ( {
576+ users : stranger , org : 'test' , aclCtx : strangerCtx , key : 'mysite/config.json' , site : 'mysite' ,
577+ } , configPermissionPath ( { site : 'mysite' } ) , 'read' , true ) ) ;
578+
579+ // The site CONFIG permission does not grant read on a different site's config.
580+ assert ( ! hasPermission ( {
581+ users : reader , org : 'test' , aclCtx, key : 'other/config.json' , site : 'other' ,
582+ } , configPermissionPath ( { site : 'other' } ) , 'read' , true ) ) ;
583+ } ) ;
584+
534585 it ( 'test DA_OPS_IMS_ORG permissions' , async ( ) => {
535586 const opsOrg = 'MyOpsOrg' ;
536587 const envOps = {
0 commit comments