|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | +// |
| 3 | +// ADR-0056 D7 — app-declared DEFAULT PROFILE. A permission set marked |
| 4 | +// `isDefault: true` becomes the fallback for authenticated users with no explicit |
| 5 | +// grants — the app declares its default access posture instead of inheriting the |
| 6 | +// built-in `member_default`. Proven on the real showcase: a fresh sign-up governed |
| 7 | +// by a custom default profile that grants ONLY `showcase_announcement` can read it |
| 8 | +// but is DENIED `showcase_private_note` (which the wildcard `member_default` would |
| 9 | +// have allowed) — so the declared default is provably in effect. Foundation for |
| 10 | +// SSO/JIT provisioning. |
| 11 | + |
| 12 | +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; |
| 13 | +import showcaseStack from '@objectstack/example-showcase'; |
| 14 | +import { bootStack, type VerifyStack } from '@objectstack/verify'; |
| 15 | +import { SecurityPlugin, securityDefaultPermissionSets } from '@objectstack/plugin-security'; |
| 16 | +import { PermissionSetSchema } from '@objectstack/spec/security'; |
| 17 | + |
| 18 | +// App-declared default profile — grants ONLY announcement (no wildcard). |
| 19 | +const demoDefault = PermissionSetSchema.parse({ |
| 20 | + name: 'showcase_demo_default', |
| 21 | + label: 'Demo Default Profile', |
| 22 | + isProfile: true, |
| 23 | + isDefault: true, // ← the D7 marker: this is the fallback for unprovisioned users |
| 24 | + objects: { |
| 25 | + showcase_announcement: { allowRead: true, allowCreate: true, allowEdit: true, allowDelete: false }, |
| 26 | + }, |
| 27 | +}); |
| 28 | + |
| 29 | +describe('showcase: app-declared default profile (ADR-0056 D7)', () => { |
| 30 | + let stack: VerifyStack; |
| 31 | + let memberToken: string; |
| 32 | + |
| 33 | + beforeAll(async () => { |
| 34 | + stack = await bootStack(showcaseStack, { |
| 35 | + // NOTE: no `fallbackPermissionSet` passed — it MUST resolve from `isDefault`. |
| 36 | + security: new SecurityPlugin({ |
| 37 | + defaultPermissionSets: [...securityDefaultPermissionSets, demoDefault], |
| 38 | + }), |
| 39 | + }); |
| 40 | + await stack.signIn(); |
| 41 | + memberToken = await stack.signUp('d7-member@verify.test'); |
| 42 | + }, 60_000); |
| 43 | + |
| 44 | + afterAll(async () => { await stack?.stop(); }); |
| 45 | + |
| 46 | + it('a fresh sign-up is governed by the app-declared default (grants announcement)', async () => { |
| 47 | + const r = await stack.apiAs(memberToken, 'GET', '/data/showcase_announcement'); |
| 48 | + expect(r.status, 'default profile grants announcement read').toBe(200); |
| 49 | + }); |
| 50 | + |
| 51 | + it('and NOT by the built-in member_default wildcard (private_note is denied)', async () => { |
| 52 | + const r = await stack.apiAs(memberToken, 'GET', '/data/showcase_private_note'); |
| 53 | + // member_default has a wildcard grant → would be 200. The declared default |
| 54 | + // grants only announcement → this object is denied, proving D7 is in effect. |
| 55 | + expect(r.status, 'default profile does NOT grant private_note').not.toBe(200); |
| 56 | + }); |
| 57 | +}); |
0 commit comments