Lets the test build present itself under its own address
VITE_SITE_URL sets the origin used for canonical, og:url, og:image, JSON-LD and the sitemap. Only the test build sets it (https://test.andreaslop.nl); the production artifact keeps https://andreaslop.nl. Only a clean https origin (or http on localhost) is accepted, anything else falls back to production. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { PRODUCTION_SITE_URL, resolveSiteUrl } from './siteUrl';
|
||||
|
||||
describe('resolveSiteUrl', () => {
|
||||
it('uses the production address without a setting', () => {
|
||||
expect(resolveSiteUrl(undefined)).toBe(PRODUCTION_SITE_URL);
|
||||
expect(resolveSiteUrl('')).toBe(PRODUCTION_SITE_URL);
|
||||
expect(resolveSiteUrl(42)).toBe(PRODUCTION_SITE_URL);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['https://test.andreaslop.nl', 'https://test.andreaslop.nl'],
|
||||
['https://test.andreaslop.nl/', 'https://test.andreaslop.nl'],
|
||||
[' https://test.andreaslop.nl ', 'https://test.andreaslop.nl'],
|
||||
['HTTPS://Test.AndreaSlop.nl', 'https://test.andreaslop.nl'],
|
||||
['http://localhost:4173', 'http://localhost:4173'],
|
||||
])('accepts the origin %s', (value, expected) => {
|
||||
expect(resolveSiteUrl(value)).toBe(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'test.andreaslop.nl',
|
||||
'http://test.andreaslop.nl',
|
||||
'ftp://test.andreaslop.nl',
|
||||
'https://test.andreaslop.nl/pad',
|
||||
'https://test.andreaslop.nl/?a=1',
|
||||
'https://test.andreaslop.nl/#x',
|
||||
'https://gebruiker:wachtwoord@test.andreaslop.nl',
|
||||
'javascript:alert(1)',
|
||||
])('falls back to production for %s', (value) => {
|
||||
expect(resolveSiteUrl(value)).toBe(PRODUCTION_SITE_URL);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user