@@ -1166,4 +1166,130 @@ describe('Cube Validation', () => {
11661166 }
11671167 } ) ;
11681168 } ) ;
1169+
1170+ describe ( 'Access Policy group/groups support:' , ( ) => {
1171+ const cubeValidator = new CubeValidator ( new CubeSymbols ( ) ) ;
1172+
1173+ it ( 'should allow group instead of role' , ( ) => {
1174+ const cube = {
1175+ name : 'TestCube' ,
1176+ fileName : 'test.js' ,
1177+ sql : ( ) => 'SELECT * FROM test' ,
1178+ accessPolicy : [ {
1179+ group : 'admin' ,
1180+ rowLevel : { allowAll : true }
1181+ } ]
1182+ } ;
1183+
1184+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1185+ expect ( result . error ) . toBeFalsy ( ) ;
1186+ } ) ;
1187+
1188+ it ( 'should allow groups as array' , ( ) => {
1189+ const cube = {
1190+ name : 'TestCube' ,
1191+ fileName : 'test.js' ,
1192+ sql : ( ) => 'SELECT * FROM test' ,
1193+ accessPolicy : [ {
1194+ groups : [ 'admin' , 'user' ] ,
1195+ rowLevel : { allowAll : true }
1196+ } ]
1197+ } ;
1198+
1199+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1200+ expect ( result . error ) . toBeFalsy ( ) ;
1201+ } ) ;
1202+
1203+ it ( 'should allow role as single string (existing behavior)' , ( ) => {
1204+ const cube = {
1205+ name : 'TestCube' ,
1206+ fileName : 'test.js' ,
1207+ sql : ( ) => 'SELECT * FROM test' ,
1208+ accessPolicy : [ {
1209+ role : 'admin' ,
1210+ rowLevel : { allowAll : true }
1211+ } ]
1212+ } ;
1213+
1214+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1215+ expect ( result . error ) . toBeFalsy ( ) ;
1216+ } ) ;
1217+
1218+ it ( 'should allow group: "*" syntax' , ( ) => {
1219+ const cube = {
1220+ name : 'TestCube' ,
1221+ fileName : 'test.js' ,
1222+ sql : ( ) => 'SELECT * FROM test' ,
1223+ accessPolicy : [ {
1224+ group : '*' ,
1225+ rowLevel : { allowAll : true }
1226+ } ]
1227+ } ;
1228+
1229+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1230+ expect ( result . error ) . toBeFalsy ( ) ;
1231+ } ) ;
1232+
1233+ it ( 'should reject role and group together' , ( ) => {
1234+ const cube = {
1235+ name : 'TestCube' ,
1236+ fileName : 'test.js' ,
1237+ sql : ( ) => 'SELECT * FROM test' ,
1238+ accessPolicy : [ {
1239+ role : 'admin' ,
1240+ group : 'admin' ,
1241+ rowLevel : { allowAll : true }
1242+ } ]
1243+ } ;
1244+
1245+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1246+ expect ( result . error ) . toBeTruthy ( ) ;
1247+ } ) ;
1248+
1249+ it ( 'should reject role and groups together' , ( ) => {
1250+ const cube = {
1251+ name : 'TestCube' ,
1252+ fileName : 'test.js' ,
1253+ sql : ( ) => 'SELECT * FROM test' ,
1254+ accessPolicy : [ {
1255+ role : 'admin' ,
1256+ groups : [ 'user' ] ,
1257+ rowLevel : { allowAll : true }
1258+ } ]
1259+ } ;
1260+
1261+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1262+ expect ( result . error ) . toBeTruthy ( ) ;
1263+ } ) ;
1264+
1265+ it ( 'should reject group and groups together' , ( ) => {
1266+ const cube = {
1267+ name : 'TestCube' ,
1268+ fileName : 'test.js' ,
1269+ sql : ( ) => 'SELECT * FROM test' ,
1270+ accessPolicy : [ {
1271+ group : 'admin' ,
1272+ groups : [ 'user' ] ,
1273+ rowLevel : { allowAll : true }
1274+ } ]
1275+ } ;
1276+
1277+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1278+ expect ( result . error ) . toBeTruthy ( ) ;
1279+ } ) ;
1280+
1281+ it ( 'should reject access policy without role/group/groups' , ( ) => {
1282+ const cube = {
1283+ name : 'TestCube' ,
1284+ fileName : 'test.js' ,
1285+ sql : ( ) => 'SELECT * FROM test' ,
1286+ accessPolicy : [ {
1287+ rowLevel : { allowAll : true }
1288+ } ]
1289+ } ;
1290+
1291+ const result = cubeValidator . validate ( cube , new ConsoleErrorReporter ( ) ) ;
1292+ expect ( result . error ) . toBeTruthy ( ) ;
1293+ } ) ;
1294+ } ) ;
11691295} ) ;
0 commit comments