Skip to content

Commit a2a6fc9

Browse files
test: add joined cube reference in mask SQL test cases
Add sc_joined_mask_test cube with a mask.sql that references orders.id from a joined cube (orders). The mask replaces the order_id dimension with the joined orders.id — since the join condition equates them, the masked and unmasked values should match, verifying the join is correctly resolved when triggered by mask SQL. Tests added for SQL API and REST API, both non-Tesseract and Tesseract. Co-authored-by: Pavel Tiunov <pavel.tiunov@gmail.com>
1 parent 62f4bcd commit a2a6fc9

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

packages/cubejs-testing/birdbox-fixtures/rbac/model/cubes/security_context_test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,54 @@ cube('sc_cube_mask_test', {
144144
],
145145
});
146146

147+
cube('sc_joined_mask_test', {
148+
sql_table: 'public.line_items',
149+
150+
joins: {
151+
orders: {
152+
relationship: 'many_to_one',
153+
sql: `${orders}.id = ${sc_joined_mask_test}.order_id`,
154+
},
155+
},
156+
157+
dimensions: {
158+
id: {
159+
sql: 'id',
160+
type: 'number',
161+
primary_key: true,
162+
},
163+
order_id: {
164+
sql: `${CUBE}.order_id`,
165+
type: 'number',
166+
},
167+
masked_order_id: {
168+
sql: `${CUBE}.order_id`,
169+
type: 'number',
170+
mask: {
171+
sql: `${orders.id}`,
172+
},
173+
},
174+
},
175+
176+
measures: {
177+
count: {
178+
type: 'count',
179+
},
180+
},
181+
182+
accessPolicy: [
183+
{
184+
role: '*',
185+
memberLevel: {
186+
includes: [],
187+
},
188+
memberMasking: {
189+
includes: '*',
190+
},
191+
},
192+
],
193+
});
194+
147195
cube('sc_groups_shorthand_test', {
148196
sql_table: 'public.line_items',
149197

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,18 @@ describe('Cube RBAC Engine', () => {
855855
expect(row.masked_status).toBeGreaterThan(0);
856856
}
857857
});
858+
859+
test('joined cube reference in mask sql', async () => {
860+
const res = await connection.query(
861+
'SELECT * FROM sc_joined_mask_test LIMIT 5'
862+
);
863+
expect(res.rows.length).toBeGreaterThan(0);
864+
for (const row of res.rows) {
865+
// mask.sql is ${orders.id} which joins orders and returns orders.id
866+
// Since line_items.order_id = orders.id (join condition), the values should match
867+
expect(row.masked_order_id).toBe(row.order_id);
868+
}
869+
});
858870
});
859871

860872
describe('SECURITY_CONTEXT.cubeCloud features via REST API', () => {
@@ -958,6 +970,20 @@ describe('Cube RBAC Engine', () => {
958970
expect(row['yaml_ua_mask_test.masked_status']).toBeGreaterThan(0);
959971
}
960972
});
973+
974+
test('joined cube reference in mask sql via REST', async () => {
975+
const result = await scClient.load({
976+
measures: ['sc_joined_mask_test.count'],
977+
dimensions: ['sc_joined_mask_test.order_id', 'sc_joined_mask_test.masked_order_id'],
978+
});
979+
const rows = result.rawData();
980+
expect(rows.length).toBeGreaterThan(0);
981+
for (const row of rows) {
982+
expect(row['sc_joined_mask_test.masked_order_id']).toBe(
983+
row['sc_joined_mask_test.order_id']
984+
);
985+
}
986+
});
961987
});
962988

963989
describe('RBAC via REST API', () => {
@@ -1132,6 +1158,16 @@ describe('Cube RBAC Engine [Tesseract]', () => {
11321158
expect(row.masked_status).toBeGreaterThan(0);
11331159
}
11341160
});
1161+
1162+
test('joined cube reference in mask sql', async () => {
1163+
const res = await connection.query(
1164+
'SELECT * FROM sc_joined_mask_test LIMIT 5'
1165+
);
1166+
expect(res.rows.length).toBeGreaterThan(0);
1167+
for (const row of res.rows) {
1168+
expect(row.masked_order_id).toBe(row.order_id);
1169+
}
1170+
});
11351171
});
11361172

11371173
describe('Shorthand and mask tests via REST API [Tesseract]', () => {
@@ -1195,6 +1231,20 @@ describe('Cube RBAC Engine [Tesseract]', () => {
11951231
expect(row['yaml_ua_mask_test.masked_status']).toBeGreaterThan(0);
11961232
}
11971233
});
1234+
1235+
test('joined cube reference in mask sql via REST', async () => {
1236+
const result = await scClient.load({
1237+
measures: ['sc_joined_mask_test.count'],
1238+
dimensions: ['sc_joined_mask_test.order_id', 'sc_joined_mask_test.masked_order_id'],
1239+
});
1240+
const rows = result.rawData();
1241+
expect(rows.length).toBeGreaterThan(0);
1242+
for (const row of rows) {
1243+
expect(row['sc_joined_mask_test.masked_order_id']).toBe(
1244+
row['sc_joined_mask_test.order_id']
1245+
);
1246+
}
1247+
});
11981248
});
11991249
});
12001250

0 commit comments

Comments
 (0)