auth-core-guard.test.ts23 lines · main
| 1 | import { describe, expect, test } from 'bun:test'; |
| 2 | import { Hono } from 'hono'; |
| 3 | |
| 4 | import { requireAuthCoreDashboard } from './auth-core-guard.js'; |
| 5 | |
| 6 | describe('briven-engine dashboard guard', () => { |
| 7 | test('rejects anonymous with engine brand', async () => { |
| 8 | const app = new Hono(); |
| 9 | app.use('*', async (c, next) => { |
| 10 | c.set('user', null); |
| 11 | c.set('session', null); |
| 12 | await next(); |
| 13 | }); |
| 14 | app.use('*', requireAuthCoreDashboard()); |
| 15 | app.get('/x', (c) => c.json({ ok: true })); |
| 16 | |
| 17 | const res = await app.request('http://localhost/x'); |
| 18 | expect(res.status).toBe(401); |
| 19 | const body = (await res.json()) as { engine?: string; code?: string }; |
| 20 | expect(body.engine).toBe('briven-engine'); |
| 21 | expect(body.code).toBe('unauthorized'); |
| 22 | }); |
| 23 | }); |