30 lines
972 B
TypeScript
30 lines
972 B
TypeScript
|
|
import { describe, expect, it } from 'vitest'
|
||
|
|
|
||
|
|
import {
|
||
|
|
buildOAuthCallbackReturnTo,
|
||
|
|
parseOAuthCallbackHash,
|
||
|
|
sanitizeAuthRedirect,
|
||
|
|
} from './oauth'
|
||
|
|
|
||
|
|
describe('oauth auth helpers', () => {
|
||
|
|
it('sanitizes redirect paths to internal routes only', () => {
|
||
|
|
expect(sanitizeAuthRedirect('/users')).toBe('/users')
|
||
|
|
expect(sanitizeAuthRedirect('https://evil.example.com')).toBe('/dashboard')
|
||
|
|
expect(sanitizeAuthRedirect('//evil.example.com')).toBe('/dashboard')
|
||
|
|
expect(sanitizeAuthRedirect('users')).toBe('/dashboard')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('builds oauth callback return url on current origin', () => {
|
||
|
|
expect(buildOAuthCallbackReturnTo('/users')).toBe('http://localhost:3000/login/oauth/callback?redirect=%2Fusers')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('parses oauth callback hash payload', () => {
|
||
|
|
expect(parseOAuthCallbackHash('#status=success&code=abc&provider=github')).toEqual({
|
||
|
|
status: 'success',
|
||
|
|
code: 'abc',
|
||
|
|
provider: 'github',
|
||
|
|
message: '',
|
||
|
|
})
|
||
|
|
})
|
||
|
|
})
|