Files
accounted/lib/auth/__tests__/scopes.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

48 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { resolveRequiredScope } from '../scopes'
describe('resolveRequiredScope', () => {
it('returns public for the health endpoint', () => {
expect(resolveRequiredScope('GET', '/api/v1/health')).toBe('public')
})
it('returns public for openapi.json', () => {
expect(resolveRequiredScope('GET', '/api/v1/openapi.json')).toBe('public')
})
it('resolves the companies:read scope for GET /api/v1/companies', () => {
expect(resolveRequiredScope('GET', '/api/v1/companies')).toBe('companies:read')
})
it('resolves :param patterns to a single scope', () => {
expect(
resolveRequiredScope(
'GET',
'/api/v1/companies/8fd5b1f4-1111-2222-3333-444455556666/customers/0b6c7d8e-1111-2222-3333-444455556666',
),
).toBe('customers:read')
})
it('resolves the inbox-items stamp verb (previously unregistered: 404 with a valid key)', () => {
expect(
resolveRequiredScope(
'POST',
'/api/v1/companies/8fd5b1f4-1111-2222-3333-444455556666/inbox-items/0b6c7d8e-1111-2222-3333-444455556666/stamp',
),
).toBe('documents:write')
})
it('returns null for unknown paths', () => {
expect(resolveRequiredScope('GET', '/api/v1/non-existent')).toBeNull()
})
it('does not match the wrong HTTP method', () => {
expect(resolveRequiredScope('DELETE', '/api/v1/companies')).toBeNull()
})
it('does not let :param greedily consume slashes', () => {
// /companies/{companyId} should not match /companies/abc/extra
expect(resolveRequiredScope('GET', '/api/v1/companies/abc/extra')).toBeNull()
})
})