@@ -13,40 +13,40 @@ import {
1313 JEST_BEFORE_ALL_DEFAULT_TIMEOUT ,
1414} from './smoke-tests' ;
1515
16+ const PG_PORT = 5656 ;
17+ let connectionId = 0 ;
18+
19+ async function createPostgresClient ( user : string , password : string ) {
20+ connectionId ++ ;
21+ const currentConnId = connectionId ;
22+
23+ console . debug ( `[pg] new connection ${ currentConnId } ` ) ;
24+
25+ const conn = new PgClient ( {
26+ database : 'db' ,
27+ port : PG_PORT ,
28+ host : '127.0.0.1' ,
29+ user,
30+ password,
31+ ssl : false ,
32+ } ) ;
33+ conn . on ( 'error' , ( err ) => {
34+ console . log ( err ) ;
35+ } ) ;
36+ conn . on ( 'end' , ( ) => {
37+ console . debug ( `[pg] end ${ currentConnId } ` ) ;
38+ } ) ;
39+
40+ await conn . connect ( ) ;
41+
42+ return conn ;
43+ }
44+
1645describe ( 'Cube RBAC Engine' , ( ) => {
1746 jest . setTimeout ( 60 * 5 * 1000 ) ;
1847 let db : StartedTestContainer ;
1948 let birdbox : BirdBox ;
2049
21- const pgPort = 5656 ;
22- let connectionId = 0 ;
23-
24- async function createPostgresClient ( user : string , password : string ) {
25- connectionId ++ ;
26- const currentConnId = connectionId ;
27-
28- console . debug ( `[pg] new connection ${ currentConnId } ` ) ;
29-
30- const conn = new PgClient ( {
31- database : 'db' ,
32- port : pgPort ,
33- host : '127.0.0.1' ,
34- user,
35- password,
36- ssl : false ,
37- } ) ;
38- conn . on ( 'error' , ( err ) => {
39- console . log ( err ) ;
40- } ) ;
41- conn . on ( 'end' , ( ) => {
42- console . debug ( `[pg] end ${ currentConnId } ` ) ;
43- } ) ;
44-
45- await conn . connect ( ) ;
46-
47- return conn ;
48- }
49-
5050 beforeAll ( async ( ) => {
5151 db = await PostgresDBRunner . startContainer ( { } ) ;
5252 await PostgresDBRunner . loadEcom ( db ) ;
@@ -64,7 +64,7 @@ describe('Cube RBAC Engine', () => {
6464 CUBEJS_DB_USER : 'test' ,
6565 CUBEJS_DB_PASS : 'test' ,
6666 //
67- CUBEJS_PG_SQL_PORT : `${ pgPort } ` ,
67+ CUBEJS_PG_SQL_PORT : `${ PG_PORT } ` ,
6868 } ,
6969 {
7070 schemaDir : 'rbac/model' ,
@@ -345,3 +345,60 @@ describe('Cube RBAC Engine [dev mode]', () => {
345345 }
346346 } ) ;
347347} ) ;
348+
349+ describe ( 'Cube RBAC Engine [Python config]' , ( ) => {
350+ jest . setTimeout ( 60 * 5 * 1000 ) ;
351+ let db : StartedTestContainer ;
352+ let birdbox : BirdBox ;
353+
354+ beforeAll ( async ( ) => {
355+ db = await PostgresDBRunner . startContainer ( { } ) ;
356+ await PostgresDBRunner . loadEcom ( db ) ;
357+ birdbox = await getBirdbox (
358+ 'postgres' ,
359+ {
360+ ...DEFAULT_CONFIG ,
361+ CUBEJS_DEV_MODE : 'false' ,
362+ NODE_ENV : 'production' ,
363+ //
364+ CUBEJS_DB_TYPE : 'postgres' ,
365+ CUBEJS_DB_HOST : db . getHost ( ) ,
366+ CUBEJS_DB_PORT : `${ db . getMappedPort ( 5432 ) } ` ,
367+ CUBEJS_DB_NAME : 'test' ,
368+ CUBEJS_DB_USER : 'test' ,
369+ CUBEJS_DB_PASS : 'test' ,
370+ //
371+ CUBEJS_PG_SQL_PORT : `${ PG_PORT } ` ,
372+ } ,
373+ {
374+ schemaDir : 'rbac-python/model' ,
375+ cubejsConfig : 'rbac-python/cube.py' ,
376+ }
377+ ) ;
378+ } , JEST_BEFORE_ALL_DEFAULT_TIMEOUT ) ;
379+
380+ afterAll ( async ( ) => {
381+ await birdbox . stop ( ) ;
382+ await db . stop ( ) ;
383+ } , JEST_AFTER_ALL_DEFAULT_TIMEOUT ) ;
384+
385+ describe ( 'RBAC via SQL API [python config]' , ( ) => {
386+ let connection : PgClient ;
387+
388+ beforeAll ( async ( ) => {
389+ connection = await createPostgresClient ( 'admin' , 'admin_password' ) ;
390+ } ) ;
391+
392+ afterAll ( async ( ) => {
393+ await connection . end ( ) ;
394+ } , JEST_AFTER_ALL_DEFAULT_TIMEOUT ) ;
395+
396+ test ( 'SELECT * from users' , async ( ) => {
397+ const res = await connection . query ( 'SELECT COUNT(city) as count from "users" HAVING (COUNT(1) > 0)' ) ;
398+ // const res = await connection.query('SELECT * FROM users limit 10');
399+ // This query should return all rows because of the `allow_all` statement
400+ // It should also exclude the `created_at` dimension as per memberLevel policy
401+ expect ( res . rows ) . toMatchSnapshot ( 'users_python' ) ;
402+ } ) ;
403+ } ) ;
404+ } ) ;
0 commit comments