Files
accounted/extensions/general/cloud-backup/lib/__tests__/callback-origin.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

64 lines
2.0 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { resolveCallbackOrigin } from '../callback-origin'
const originalAppUrl = process.env.NEXT_PUBLIC_APP_URL
beforeEach(() => {
delete process.env.NEXT_PUBLIC_APP_URL
})
afterEach(() => {
if (originalAppUrl === undefined) delete process.env.NEXT_PUBLIC_APP_URL
else process.env.NEXT_PUBLIC_APP_URL = originalAppUrl
})
describe('resolveCallbackOrigin', () => {
it('falls back to the request origin when no canonical URL is configured', () => {
expect(resolveCallbackOrigin('https://self-hosted.example')).toBe(
'https://self-hosted.example'
)
})
it('prefers the canonical app origin over the request origin', () => {
process.env.NEXT_PUBLIC_APP_URL = 'https://app.accounted.se'
expect(resolveCallbackOrigin('https://app.gnubok.se')).toBe(
'https://app.accounted.se'
)
})
it('normalizes a trailing slash so the redirect URI stays byte-identical', () => {
process.env.NEXT_PUBLIC_APP_URL = 'https://app.accounted.se/'
expect(resolveCallbackOrigin('https://other.example')).toBe(
'https://app.accounted.se'
)
})
it('strips any path from the configured URL', () => {
process.env.NEXT_PUBLIC_APP_URL = 'https://app.accounted.se/dashboard'
expect(resolveCallbackOrigin('https://other.example')).toBe(
'https://app.accounted.se'
)
})
it('ignores a blank value', () => {
process.env.NEXT_PUBLIC_APP_URL = ' '
expect(resolveCallbackOrigin('https://other.example')).toBe(
'https://other.example'
)
})
it('falls back to the request origin when the configured URL is malformed', () => {
process.env.NEXT_PUBLIC_APP_URL = 'not a url'
expect(resolveCallbackOrigin('https://other.example')).toBe(
'https://other.example'
)
})
it('falls back to the request origin for a non-web URL scheme', () => {
process.env.NEXT_PUBLIC_APP_URL = 'mailto:backup@example.com'
expect(resolveCallbackOrigin('https://other.example')).toBe(
'https://other.example'
)
})
})