|
21 | 21 | * the gate meet: the gate admits exactly what the resolver grants. |
22 | 22 | */ |
23 | 23 |
|
24 | | -import { describe, it, expect, afterEach, vi } from 'vitest'; |
| 24 | +import { describe, it, expect, afterEach, beforeAll, vi } from 'vitest'; |
25 | 25 | import { ObjectQL } from '@objectstack/objectql'; |
26 | 26 | import { SqlDriver } from '@objectstack/driver-sql'; |
27 | 27 | import { resolveThrownHttpError } from '@objectstack/types'; |
@@ -875,21 +875,34 @@ describe("[ADR-0090 D12] a delegated answer about a user the caller cannot read |
875 | 875 | } |
876 | 876 | }); |
877 | 877 |
|
878 | | - it(`the ${STATES.length} states get, at every door, the answer the id naming no user gets`, async () => { |
879 | | - const answers = []; |
880 | | - for (const state of STATES) answers.push(await answersFor(posture, state)); |
881 | | - for (const [i, answer] of answers.entries()) expect(answer, STATES[i]).toEqual(answers[0]); |
882 | | - // The one answer: the write gate's scope violation, and each explain door's refusal of a user the caller may not describe. |
883 | | - const [none] = answers; |
884 | | - for (const [door, answer] of Object.entries(none)) { |
885 | | - const expected = door.startsWith('security/explain') || door.startsWith("the subject's effective") |
886 | | - ? [403, 'PERMISSION_DENIED', 'PermissionDeniedError'] |
887 | | - : [403, 'DELEGATION_SCOPE_VIOLATION', 'DelegationScopeViolationError']; |
888 | | - expect([answer.status, (answer as any).code, (answer as any).class], door).toEqual(expected); |
889 | | - } |
890 | | - expect((none['security/explain for the subject'] as any).details) |
891 | | - .toEqual({ object: 'sys_business_unit', operation: 'read', targetUserId: SUBJECT }); |
892 | | - expect((none["the subject's effective access"] as any).details).toBeUndefined(); |
| 878 | + // Every state boots a rig of its own, so each state is an `it` of its own: its own |
| 879 | + // time budget and its own failure line. Asked in one `it`, the states shared the |
| 880 | + // default 5 s budget, which a loaded CI shard used up. The reference, the id |
| 881 | + // naming no user, is asked once, and every other state is compared to it. |
| 882 | + describe(`the ${STATES.length} states get, at every door, the answer the id naming no user gets`, () => { |
| 883 | + let reference: Awaited<ReturnType<typeof answersFor>> | undefined; |
| 884 | + beforeAll(async () => { |
| 885 | + reference = await answersFor(posture, STATES[0]); |
| 886 | + }); |
| 887 | + |
| 888 | + it(`${STATES[0]}: the write gate's scope violation, and each explain door's refusal of a user the caller may not describe`, () => { |
| 889 | + expect(reference).toBeDefined(); |
| 890 | + const none = reference!; |
| 891 | + for (const [door, answer] of Object.entries(none)) { |
| 892 | + const expected = door.startsWith('security/explain') || door.startsWith("the subject's effective") |
| 893 | + ? [403, 'PERMISSION_DENIED', 'PermissionDeniedError'] |
| 894 | + : [403, 'DELEGATION_SCOPE_VIOLATION', 'DelegationScopeViolationError']; |
| 895 | + expect([answer.status, (answer as any).code, (answer as any).class], door).toEqual(expected); |
| 896 | + } |
| 897 | + expect((none['security/explain for the subject'] as any).details) |
| 898 | + .toEqual({ object: 'sys_business_unit', operation: 'read', targetUserId: SUBJECT }); |
| 899 | + expect((none["the subject's effective access"] as any).details).toBeUndefined(); |
| 900 | + }); |
| 901 | + |
| 902 | + it.each(STATES.slice(1))(`%s: every door answers exactly what ${STATES[0]} gets`, async (state) => { |
| 903 | + expect(reference).toBeDefined(); |
| 904 | + expect(await answersFor(posture, state), state).toEqual(reference); |
| 905 | + }); |
893 | 906 | }); |
894 | 907 |
|
895 | 908 | it('CONTROL: the same subject with a business unit inside the scope, read by the delegate, is served at every door', async () => { |
|
0 commit comments