Skip to content

Commit d168562

Browse files
test: add Tesseract-enabled smoke tests for userAttributes shorthand and CUBE context in mask SQL
Add a new 'Cube RBAC Engine [Tesseract]' describe block that runs with CUBESQL_SQL_PUSH_DOWN=true to exercise the Tesseract/native SQL planner path for mask SQL features. Co-authored-by: Pavel Tiunov <pavel.tiunov@gmail.com>
1 parent a2a9bce commit d168562

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

packages/cubejs-testing/test/smoke-rbac.test.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,127 @@ describe('Cube RBAC Engine', () => {
10301030
});
10311031
});
10321032

1033+
describe('Cube RBAC Engine [Tesseract]', () => {
1034+
jest.setTimeout(60 * 5 * 1000);
1035+
let db: StartedTestContainer;
1036+
let birdbox: BirdBox;
1037+
1038+
beforeAll(async () => {
1039+
db = await PostgresDBRunner.startContainer({});
1040+
await PostgresDBRunner.loadEcom(db);
1041+
birdbox = await getBirdbox(
1042+
'postgres',
1043+
{
1044+
...DEFAULT_CONFIG,
1045+
CUBEJS_DEV_MODE: 'false',
1046+
NODE_ENV: 'production',
1047+
//
1048+
CUBEJS_DB_TYPE: 'postgres',
1049+
CUBEJS_DB_HOST: db.getHost(),
1050+
CUBEJS_DB_PORT: `${db.getMappedPort(5432)}`,
1051+
CUBEJS_DB_NAME: 'test',
1052+
CUBEJS_DB_USER: 'test',
1053+
CUBEJS_DB_PASS: 'test',
1054+
//
1055+
CUBEJS_PG_SQL_PORT: `${PG_PORT}`,
1056+
CUBESQL_SQL_PUSH_DOWN: 'true',
1057+
},
1058+
{
1059+
schemaDir: 'rbac/model',
1060+
cubejsConfig: 'rbac/cube.js',
1061+
}
1062+
);
1063+
}, JEST_BEFORE_ALL_DEFAULT_TIMEOUT);
1064+
1065+
afterAll(async () => {
1066+
await birdbox.stop();
1067+
await db.stop();
1068+
}, JEST_AFTER_ALL_DEFAULT_TIMEOUT);
1069+
1070+
describe('Shorthand and mask tests via SQL API [Tesseract]', () => {
1071+
let connection: PgClient;
1072+
1073+
beforeAll(async () => {
1074+
connection = await createPostgresClient('sc_test', 'sc_test_password');
1075+
});
1076+
1077+
afterAll(async () => {
1078+
await connection.end();
1079+
}, JEST_AFTER_ALL_DEFAULT_TIMEOUT);
1080+
1081+
test('userAttributes shorthand in mask sql', async () => {
1082+
const res = await connection.query(
1083+
'SELECT * FROM sc_ua_mask_test LIMIT 5'
1084+
);
1085+
expect(res.rows.length).toBeGreaterThan(0);
1086+
for (const row of res.rows) {
1087+
expect(row.masked_price).toBe(1);
1088+
}
1089+
});
1090+
1091+
test('CUBE context in mask sql', async () => {
1092+
const res = await connection.query(
1093+
'SELECT * FROM sc_cube_mask_test LIMIT 5'
1094+
);
1095+
expect(res.rows.length).toBeGreaterThan(0);
1096+
for (const row of res.rows) {
1097+
expect(row.masked_product).toBeLessThan(0);
1098+
}
1099+
});
1100+
});
1101+
1102+
describe('Shorthand and mask tests via REST API [Tesseract]', () => {
1103+
let scClient: CubeApi;
1104+
1105+
const SC_TEST_TOKEN = sign({
1106+
cubeCloud: {
1107+
userAttributes: {
1108+
tenantId: '1',
1109+
},
1110+
groups: ['1', '2'],
1111+
},
1112+
auth: {
1113+
username: 'sc_test',
1114+
userAttributes: {},
1115+
roles: [],
1116+
groups: [],
1117+
},
1118+
}, DEFAULT_CONFIG.CUBEJS_API_SECRET, {
1119+
expiresIn: '2 days'
1120+
});
1121+
1122+
beforeAll(async () => {
1123+
scClient = cubejs(async () => SC_TEST_TOKEN, {
1124+
apiUrl: birdbox.configuration.apiUrl,
1125+
});
1126+
});
1127+
1128+
test('userAttributes shorthand in mask sql via REST', async () => {
1129+
const result = await scClient.load({
1130+
measures: ['sc_ua_mask_test.count'],
1131+
dimensions: ['sc_ua_mask_test.masked_price'],
1132+
});
1133+
const rows = result.rawData();
1134+
expect(rows.length).toBeGreaterThan(0);
1135+
for (const row of rows) {
1136+
expect(row['sc_ua_mask_test.masked_price']).toBe(1);
1137+
}
1138+
});
1139+
1140+
test('CUBE context in mask sql via REST', async () => {
1141+
const result = await scClient.load({
1142+
measures: ['sc_cube_mask_test.count'],
1143+
dimensions: ['sc_cube_mask_test.masked_product'],
1144+
});
1145+
const rows = result.rawData();
1146+
expect(rows.length).toBeGreaterThan(0);
1147+
for (const row of rows) {
1148+
expect(row['sc_cube_mask_test.masked_product']).toBeLessThan(0);
1149+
}
1150+
});
1151+
});
1152+
});
1153+
10331154
describe('Cube RBAC Engine [dev mode]', () => {
10341155
jest.setTimeout(60 * 5 * 1000);
10351156
let db: StartedTestContainer;

0 commit comments

Comments
 (0)