Shuffle/e2e/tests/api/guards.spec.ts
cschlaefke aa421b12b0
Some checks failed
CI / flutter (pull_request) Successful in 1m15s
CI / web-build (pull_request) Successful in 53s
CI / supabase (pull_request) Successful in 3s
CI / supabase-tests (pull_request) Successful in 30s
CI / e2e (pull_request) Failing after 3m56s
test(auth): address review findings for e2e
Refs #38

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 10:55:27 +01:00

35 lines
1.7 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { assertLocalUrl } from '../../support/auth-config';
import { localDbConfig } from '../../support/db';
test.describe('E2E-Guards: Tests laufen nur gegen lokale Dienste', () => {
test('db.ts: lokale Hosts werden akzeptiert (inkl. IPv6 in Klammern)', () => {
for (const url of [
'postgresql://postgres:postgres@127.0.0.1:54322/postgres',
'postgresql://postgres:postgres@localhost:54322/postgres',
'postgresql://postgres:postgres@[::1]:54322/postgres',
]) {
expect(() => localDbConfig(url), url).not.toThrow();
}
});
test('db.ts: fremde Hosts werden abgelehnt', () => {
expect(() => localDbConfig('postgresql://u:p@db.example.com:5432/postgres')).toThrow(/nicht erlaubt/);
});
test('db.ts: ?host= kann den Guard nicht umgehen', () => {
expect(() => localDbConfig('postgresql://u:p@127.0.0.1:5432/postgres?host=db.example.com')).toThrow(/nicht erlaubt/);
expect(() => localDbConfig('postgresql://u:p@localhost/postgres?host=/var/run/postgresql,db.example.com')).toThrow();
});
test('db.ts: Host-Namen mit lokalem Praefix/Suffix gelten nicht als lokal', () => {
expect(() => localDbConfig('postgresql://u:p@localhost.evil.com:5432/postgres')).toThrow();
expect(() => localDbConfig('postgresql://u:p@127.0.0.1.evil.com:5432/postgres')).toThrow();
});
test('SUPABASE_URL/MAILPIT_URL: nur lokale Hosts', () => {
expect(() => assertLocalUrl('X', 'http://127.0.0.1:54321')).not.toThrow();
expect(() => assertLocalUrl('X', 'http://[::1]:54321')).not.toThrow();
expect(() => assertLocalUrl('X', 'https://abc.supabase.co')).toThrow(/nicht lokal/);
});
});