78 lines
3.6 KiB
TypeScript
78 lines
3.6 KiB
TypeScript
/**
|
|
* SPIKE (Issue #37), NICHT blockierend: Verhalten von /recover, /signup und /resend, wenn der
|
|
* SMTP-Server nicht erreichbar ist, fuer bekannte vs. unbekannte Adressen.
|
|
*
|
|
* Laeuft gegen einen dritten GoTrue-Container, dessen SMTP-Port 1 die Verbindung ablehnt
|
|
* (`e2e/support/start-throttle-gotrue.sh start smtp-down`, SPIKE_GOTRUE_URL). Mailpit bleibt fuer
|
|
* die anderen Projekte unberuehrt.
|
|
*
|
|
* Die Tests pruefen NICHTS ausser dem Ablauf; sie erfassen Status, Body, Dauer und den Zustand in
|
|
* der DB je Fall und schreiben ihn in die Konsole und als Anhang `smtp-down-<fall>.json`. Eine
|
|
* Auswertung steht in docs/auth-konfiguration.md (Abschnitt „SMTP-Ausfall (Spike #37)“).
|
|
*/
|
|
import { test } from '@playwright/test';
|
|
import { env } from '../../support/auth-config';
|
|
import { userByEmail } from '../../support/db';
|
|
import { GoTrueClient, randomEmail, randomPassword, validMetadata } from '../../support/gotrue';
|
|
import { countMails } from '../../support/mailpit';
|
|
|
|
const base = env.spikeGotrueUrl;
|
|
test.skip(!base, 'SPIKE_GOTRUE_URL nicht gesetzt (start-throttle-gotrue.sh start smtp-down)');
|
|
|
|
const spike = () => new GoTrueClient({ baseUrl: base!, apikey: null });
|
|
const cli = new GoTrueClient();
|
|
|
|
async function record(info: typeof test.info extends () => infer R ? R : never, name: string, data: unknown) {
|
|
const json = JSON.stringify(data, null, 2);
|
|
console.log(`[SPIKE smtp-down] ${name}: ${json}`);
|
|
await info.attach(`smtp-down-${name}.json`, { body: json, contentType: 'application/json' });
|
|
}
|
|
|
|
const summarize = (r: { status: number; body: any; ms: number }) => ({
|
|
status: r.status,
|
|
error_code: r.body?.error_code ?? null,
|
|
msg: r.body?.msg ?? r.body?.message ?? null,
|
|
hasUserId: Boolean(r.body?.id),
|
|
ms: r.ms,
|
|
});
|
|
|
|
test.describe('Spike #37: SMTP nicht erreichbar', () => {
|
|
test('recover: bekannte (bestaetigte) vs. unbekannte Adresse', async () => {
|
|
const known = randomEmail();
|
|
await cli.createConfirmedUser(known, randomPassword());
|
|
const unknown = randomEmail('unknown');
|
|
const a = await spike().recover(known);
|
|
const b = await spike().recover(unknown);
|
|
await record(test.info(), 'recover', { known: summarize(a), unknown: summarize(b) });
|
|
});
|
|
|
|
test('signup: neue vs. bestaetigte vs. unbestaetigte Adresse', async () => {
|
|
const confirmed = randomEmail();
|
|
await cli.createConfirmedUser(confirmed, randomPassword());
|
|
const unconfirmed = randomEmail();
|
|
await cli.signUp(unconfirmed, randomPassword());
|
|
const fresh = randomEmail();
|
|
|
|
const rFresh = await spike().signUp(fresh, randomPassword());
|
|
const rConfirmed = await spike().signUp(confirmed, randomPassword());
|
|
// AUTH-CFG-08: sonst antwortet GoTrue mit 429 statt dem SMTP-Fehler.
|
|
await new Promise((r) => setTimeout(r, 1300));
|
|
const rUnconfirmed = await spike().signUp(unconfirmed, randomPassword());
|
|
await record(test.info(), 'signup', {
|
|
newAddress: { ...summarize(rFresh), userInDbAfterwards: Boolean(await userByEmail(fresh)) },
|
|
confirmedAddress: summarize(rConfirmed),
|
|
unconfirmedAddress: summarize(rUnconfirmed),
|
|
mailsToFresh: await countMails(fresh),
|
|
});
|
|
});
|
|
|
|
test('resend: unbestaetigte vs. unbekannte Adresse', async () => {
|
|
const unconfirmed = randomEmail();
|
|
await cli.signUp(unconfirmed, randomPassword(), validMetadata());
|
|
await new Promise((r) => setTimeout(r, 1300));
|
|
const unknown = randomEmail('unknown');
|
|
const a = await spike().resend(unconfirmed);
|
|
const b = await spike().resend(unknown);
|
|
await record(test.info(), 'resend', { unconfirmed: summarize(a), unknown: summarize(b) });
|
|
});
|
|
});
|