Files
supabase/apps/studio/tests/components/Auth/Auth.constants.test.ts
Vaibhav 804475fd3a fix: redirect urls (#47487)
## TL;DR

fixes redirect url  normalization..

## PS:

| Before | After |
| --- | --- |
| Broken: whitespace could make the same redirect URL appear as a
separate entry and break delete behavior | Fixed: equivalent redirect
URLs are normalized consistently, so display, save, and delete behavior
stay in sync |
| <img width="800" height="274" alt="Before redirect URLs behavior"
src="https://github.com/user-attachments/assets/47dbb1ca-7c7d-482b-a67e-08c2eb2cd030"
/> | ![After redirect URLs
behavior](https://github.com/user-attachments/assets/b90dfad3-9ec2-4431-8412-34d4faca62da)
|

## ref:
- closes https://github.com/supabase/supabase/issues/47478

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved redirect URL handling so saved and displayed URLs are
consistently trimmed, normalized, deduplicated, and parsed from
comma-separated allow lists.
* Tightened redirect URL validation to better catch invalid formats and
prevent duplicates both against the existing allow list and within a new
submission.
* Fixed redirect URL deletion to remove the exact set of URLs confirmed
by the user.
* **Tests**
* Added/updated tests to cover redirect URL normalization and parsing
behavior for stored comma-separated allow lists.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-01 08:24:17 -06:00

69 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
normalizeRedirectUrl,
parseRedirectUrls,
urlRegex,
} from '@/components/interfaces/Auth/Auth.constants'
describe('Auth.constants: urlRegex', () => {
it('should match valid URLs', () => {
const validUrls = [
'http://domain.com',
'https://supabase.io',
'https://new-domain-vercel.com',
'www.test-domain.com',
'exp://exp.host/some-app',
'exp://exp.host/some-app?release-channel=default',
'https://supabase.com/dashboard',
'http://localhost:3000',
'https://supabase.com?name=test',
'https://supabase.com?name=test&description=hello&page=2',
'https://supabase*.com',
'https://supabase.com/*',
'https://new-*-domain.com/*',
'https://new-*-domain.com/*/*/*',
'https://sub-*-domain.new-*-domain.com/*/*/*',
]
validUrls.forEach((url) => {
expect(urlRegex().test(url)).toBe(true)
})
})
it('should not match invalid URLs', () => {
const invalidUrls = ['supabase', 'mailto:test@gmail.com', 'hello world.com', 'email@domain.com']
const failingInvalidUrls = invalidUrls.filter((url) => urlRegex().test(url))
if (failingInvalidUrls.length > 0) {
console.log('Failing invalid URLs:', failingInvalidUrls)
}
invalidUrls.forEach((url) => {
expect(urlRegex().test(url)).toBe(false)
})
})
it('should not match simple domain URLs when excludeSimpleDomains is true', () => {
const simpleDomainUrl = 'smtp-pulse.com'
expect(urlRegex({ excludeSimpleDomains: true }).test(simpleDomainUrl)).toBe(false)
})
it('should match simple domain URLs when excludeSimpleDomains is false', () => {
const simpleDomainUrl = 'smtp-pulse.com'
expect(urlRegex({ excludeSimpleDomains: false }).test(simpleDomainUrl)).toBe(true)
})
it('normalizes redirect URLs before saving', () => {
expect(normalizeRedirectUrl(' https://example.com/path , ')).toBe('https://example.com/path')
})
it('parses stored redirect URLs into trimmed unique values', () => {
expect(
parseRedirectUrls(
'https://example.com/callback, https://example.com/callback , https://example.com/next'
)
).toEqual(['https://example.com/callback', 'https://example.com/next'])
})
})