Skip to content

Commit 0b381cd

Browse files
committed
test(service-automation): a user-identity flow below datasource administration is served no stored datasource row
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwurKjbb54r3yD6yJg
1 parent de1f609 commit 0b381cd

2 files changed

Lines changed: 60 additions & 7 deletions

File tree

‎packages/services/service-automation/src/builtin/get-record-stored-metadata-family.integration.test.ts‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* row, not a withheld one);
1818
* - the served hash equal to the one the door serves for the same row.
1919
*
20-
* Two exits are pinned, under BOTH run identities (`runAs: 'system'`, which
21-
* reads elevated, and `runAs: 'user'`, which reads as the triggering user):
20+
* Two exits are pinned, under the system run identity (`runAs: 'system'`,
21+
* which reads elevated):
2222
* - the run's declared OUTPUT (the node's `outputVariable`, declared
2323
* `isOutput` on the flow), which a flow caller is handed back;
2424
* - an ordinary RECORD the same flow writes from what the node read (a
@@ -29,6 +29,11 @@
2929
* provider (the process-scoped ephemeral key) and with one registered on the
3030
* engine (the provider's keyed digest), the node's hash equals the door's.
3131
*
32+
* [#27884] A datasource definition's stored row is served only to holders of
33+
* the capability the `/meta` type gate names for it (`manage_platform_settings`).
34+
* The triggering user here holds none, so under `runAs: 'user'` both branches
35+
* pin the other side of that rule: the node is served no row at all.
36+
*
3237
* Composition: the real stack the other `*.integration.test.ts` files in this
3338
* package boot: `ObjectKernel`, `ObjectQLPlugin` (which registers the
3439
* family's two tables), `driver-sql` on better-sqlite3 `:memory:`, and the
@@ -127,7 +132,23 @@ function familyReadFlow(name: string, object: string, runAs: RunAs, branch: Bran
127132
};
128133
}
129134

130-
/** The trigger a user-identity run needs: a real acting user. */
135+
/**
136+
* start → get_record(family) → end: the read alone, for a run whose node is
137+
* served no row (nothing downstream can copy what was not served).
138+
*/
139+
function familyReadOnlyFlow(name: string, object: string, runAs: RunAs, branch: Branch) {
140+
const def = familyReadFlow(name, object, runAs, branch);
141+
return {
142+
...def,
143+
nodes: def.nodes.filter((n) => n.id !== 'copy'),
144+
edges: [
145+
{ id: 'e1', source: 'start', target: 'read' },
146+
{ id: 'e2', source: 'read', target: 'end' },
147+
],
148+
};
149+
}
150+
151+
/** The trigger a user-identity run needs: a real acting user, below datasource administration. */
131152
const TRIGGER = { userId: 'usr_flow_reader', tenantId: 'org_1', positions: [] as string[], permissions: [] as string[] };
132153

133154
describe('flow get_record serves the stored-metadata family the way the data door does (#21519)', () => {
@@ -206,7 +227,7 @@ describe('flow get_record serves the stored-metadata family the way the data doo
206227
}
207228
});
208229

209-
for (const runAs of ['system', 'user'] as const) {
230+
for (const runAs of ['system'] as const) {
210231
for (const branch of ['one', 'list'] as const) {
211232
it(`runAs:'${runAs}', ${branch === 'one' ? 'findOne' : 'find'} branch: the output and the written record carry the projected body and the door's keyed hash`, async () => {
212233
const control = await doorRow('sys_metadata');
@@ -229,6 +250,24 @@ describe('flow get_record serves the stored-metadata family the way the data doo
229250
}
230251
}
231252

253+
// [#27884] The user-identity run of a caller below datasource administration.
254+
for (const branch of ['one', 'list'] as const) {
255+
it(`runAs:'user' below datasource administration, ${branch === 'one' ? 'findOne' : 'find'} branch: the node is served no datasource row`, async () => {
256+
for (const object of ['sys_metadata', 'sys_metadata_history']) {
257+
const def = familyReadOnlyFlow(`fam_user_${branch}_${object}`, object, 'user', branch);
258+
automation.registerFlow(def.name, def as any);
259+
const res: any = await automation.execute(def.name, { ...TRIGGER });
260+
expect(res.success, `run failed: ${JSON.stringify(res.error ?? res)}`).toBe(true);
261+
const rec = res.output?.rec;
262+
if (branch === 'one') expect(rec ?? null, `${object}: findOne served a row`).toBeNull();
263+
else expect(rec ?? [], `${object}: find served a row`).toEqual([]);
264+
const text = JSON.stringify(res);
265+
expect(text.includes(SENTINEL), `${object}: the stored credential reached the run`).toBe(false);
266+
expect(text.includes(DS_URL), `${object}: the row's configuration reached the run`).toBe(false);
267+
}
268+
});
269+
}
270+
232271
it('the history table is served the same way, its parent hash included', async () => {
233272
const control = await doorRow('sys_metadata_history');
234273
const { output, copy } = await runFlow(familyReadFlow('fam_history', 'sys_metadata_history', 'system', 'one'));
@@ -259,7 +298,7 @@ describe('flow get_record serves the stored-metadata family the way the data doo
259298
ql.setCryptoProvider({ keyedDigest } as any);
260299
const control = await doorRow('sys_metadata');
261300
expect(control.checksum, 'control: the door serves the provider digest').toBe(await keyedDigest(STORED_HASH));
262-
const { output, copy } = await runFlow(familyReadFlow('fam_provider', 'sys_metadata', 'user', 'one'));
301+
const { output, copy } = await runFlow(familyReadFlow('fam_provider', 'sys_metadata', 'system', 'one'));
263302
expectServedLikeTheDoor(output, control, 'the run output');
264303
expect(output.checksum).toBe(control.checksum);
265304
expect(copy.hash).toBe(control.checksum);

‎packages/services/service-automation/src/builtin/get-record-stored-metadata-filter-refusal.integration.test.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
* when the resolved list reads the body.
3131
*
3232
* Controls: the data door refuses the same filters; a scalar-column filter on
33-
* a family table is served projected, as #21519 serves it; and an ordinary
33+
* a family table is served projected to a system run, as #21519 serves it, and
34+
* no row to a user-identity run below datasource administration (#27884: a
35+
* datasource definition's stored row is served only to holders of
36+
* `manage_platform_settings`, which this triggering user is not); and an ordinary
3437
* object whose columns share the family's column names is filtered and served
3538
* exactly as stored.
3639
*
@@ -334,7 +337,18 @@ describe("flow get_record refuses a filter that evaluates the stored-metadata fa
334337
});
335338
}
336339

337-
for (const runAs of ['system', 'user'] as const) {
340+
it("runAs:'user' below datasource administration: a scalar-column filter on a family read runs and is served no datasource row (#27884)", async () => {
341+
const run = await runWatched(readThenCopyFlow(`scalar_${seq++}`, 'sys_metadata', 'user', 'one', { name: DS_NAME, type: 'datasource' }));
342+
expect(run.res.success, `run failed: ${JSON.stringify(run.res.error)}`).toBe(true);
343+
expect(run.familyReads).toBeGreaterThan(0);
344+
expect(run.copy, 'the node downstream of the read ran').toBeTruthy();
345+
expect(run.res.output?.rec ?? null, 'the node served a row').toBeNull();
346+
const text = JSON.stringify(run.res);
347+
expect(text.includes(SENTINEL), 'the stored credential reached the run').toBe(false);
348+
expect(text.includes(DS_URL), "the row's configuration reached the run").toBe(false);
349+
});
350+
351+
for (const runAs of ['system'] as const) {
338352
it(`runAs:'${runAs}': a scalar-column filter on a family read is served projected, with the door's keyed hash`, async () => {
339353
const control: any = await door.findData({ object: 'sys_metadata', query: { where: { name: DS_NAME } } });
340354
expect(control.records).toHaveLength(1);

0 commit comments

Comments
 (0)