auth-next.test.ts 707 B

123456789101112131415161718192021
  1. import { describe, expect, it } from 'vitest';
  2. import { nextAuthSuccessState, safeInternalPath } from '../../src/frontend/auth/auth-model.js';
  3. describe('authentication next path', () => {
  4. it('restores a filtered internal deep link after login', () => {
  5. expect(nextAuthSuccessState('/api/login', {}, '/activity?status=failed&page=2').redirectTo)
  6. .toBe('/activity?status=failed&page=2');
  7. });
  8. it.each([
  9. 'https://attacker.example/path',
  10. '//attacker.example/path',
  11. '/\\attacker.example/path',
  12. '/login',
  13. '/api/events',
  14. 'javascript:alert(1)'
  15. ])('rejects unsafe destination %s', (value) => {
  16. expect(safeInternalPath(value, '/overview')).toBe('/overview');
  17. });
  18. });