Files
logbuch/tests/lib/auth-routes.test.ts
Matthias Giesselmann b90ff252d1 Add Logbuch: project update blog with admin, media and API
Public archive with sidebar navigation, project pages, month archive,
search and entry pages with image blocks. Admin area for brands,
projects, post types, users, api clients, media and the entry editor
with drag and drop images, preview per audience, scheduling and
publish checks. Read and write API with bearer tokens, audience
scoping, idempotent creation, OpenAPI document and editorial guide.
Magic link login with configurable allowed domains, whole app behind
the session gate. 456 tests including design rule checks.
2026-07-31 21:33:42 +02:00

36 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { internalTarget, loginPath, overviewTarget } from '~/lib/auth-routes'
describe('internalTarget', () => {
it('behält ein Ziel innerhalb der Verwaltung', () => {
expect(internalTarget('/admin/posts/neu', overviewTarget)).toBe('/admin/posts/neu')
})
it('fällt auf die Verwaltungsübersicht zurück', () => {
expect(internalTarget(undefined, overviewTarget)).toBe('/')
expect(internalTarget('', overviewTarget)).toBe('/')
expect(internalTarget('/search', overviewTarget)).toBe('/search')
})
it('lässt keine fremde Adresse durch', () => {
expect(internalTarget('//example.test/admin', overviewTarget)).toBe('/')
expect(internalTarget('https://example.test/admin', overviewTarget)).toBe('/')
expect(internalTarget('/admin\\@example.test', overviewTarget)).toBe('/')
})
})
describe('loginPath', () => {
it('bleibt ohne Ziel schlicht', () => {
expect(loginPath()).toBe('/login')
expect(loginPath('/')).toBe('/login')
})
it('hängt ein erlaubtes Ziel an', () => {
expect(loginPath('/admin/posts/neu')).toBe('/login?next=%2Fadmin%2Fposts%2Fneu')
})
it('verwirft ein fremdes Ziel', () => {
expect(loginPath('https://example.test')).toBe('/login')
})
})