Put the feedback and tickets admin areas behind the shared identity
feedback.auth.ts and tickets.auth.ts each become one binding to requireAppAccess. Everything downstream was already written against requireAdminAuth and res.locals.admin, and both still mean what they meant, so no router or service changed. What changed is the policy: an activated @nachklang.art account is no longer sufficient, an explicit per-app permission is. Three things followed from that and are not obvious from the diff: - APP_ORIGINS gets a production default. It feeds better-auth's trustedOrigins, and this is the first time the tickets and feedback origins matter there - before, the only browser origin that ever reached /admin/auth was the admin app itself. An origin missing from that list fails in a way that is easy to misread: sign-in works, the app works, and only sign-out returns an origin error. - Nothing reads X-Session-* any more; these two files were the last readers, and the calendar module passes its session in query parameters. The headers stay in the CORS allowedHeaders only so a browser still running a pre-cutover bundle gets a clean 401 rather than a preflight failure, and can come out once both frontends are deployed. - 40 admin operations documented a required X-Session-Id/X-Session-Key in swagger. They now declare the AdminSessionCookie scheme the admin module already defined, and each documents a 403 next to its 401. The integration assertions flip as their own comment predicted: one admin cookie opens both /feedback/admin/me and /tickets/admin/me, a user holding only feedback gets 200 and 403 respectively, and a legacy header session gets 401. The unit test that covered the old header authenticator is replaced by one asserting each module is bound to its own app and that neither consults the calendar users service. 163 unit tests and 43 integration tests green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -221,16 +221,32 @@ describe('requireAppAccess', () => {
|
||||
expect(Array.isArray(res.body)).toBe(true);
|
||||
});
|
||||
|
||||
// Step 2 deliberately does NOT swap the feedback and tickets authenticators:
|
||||
// they still authenticate against the legacy calendar sessions, so an admin
|
||||
// cookie means nothing to them yet. This asserts that boundary rather than
|
||||
// the end state - when step 4 lands, these two expectations become 200/403
|
||||
// and this comment goes away.
|
||||
it('leaves the feedback and tickets admin areas on their legacy authenticator', async () => {
|
||||
// The step 4 cutover (2026-09-06): the feedback and tickets admin areas now
|
||||
// sit behind this same gate, so one sign-in reaches every app the user has a
|
||||
// permission for - and reaches no further. Until step 4 these two returned
|
||||
// 401 for an admin cookie, because each module still ran its own header
|
||||
// session against the calendar users table.
|
||||
it('lets an admin cookie into the feedback and tickets admin areas', async () => {
|
||||
const user = await createAndAcceptInvitation(app, 'o@nachklang.art', 'O', ['feedback', 'tickets']);
|
||||
|
||||
expect((await user.agent.get('/feedback/admin/me')).status).toBe(401);
|
||||
expect((await user.agent.get('/tickets/admin/me')).status).toBe(401);
|
||||
expect((await user.agent.get('/feedback/admin/me')).status).toBe(200);
|
||||
expect((await user.agent.get('/tickets/admin/me')).status).toBe(200);
|
||||
});
|
||||
|
||||
it('403s each app separately for a user who only holds the other one', async () => {
|
||||
const user = await createAndAcceptInvitation(app, 'q@nachklang.art', 'Q', ['feedback']);
|
||||
|
||||
expect((await user.agent.get('/feedback/admin/me')).status).toBe(200);
|
||||
expect((await user.agent.get('/tickets/admin/me')).status).toBe(403);
|
||||
});
|
||||
|
||||
it('401s the feedback and tickets admin areas for a legacy header session', async () => {
|
||||
const res = await request(app)
|
||||
.get('/feedback/admin/me')
|
||||
.set('X-Session-Id', '1')
|
||||
.set('X-Session-Key', 'whatever');
|
||||
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user