58 lines
2.5 KiB
TypeScript
58 lines
2.5 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import { GoTrueClient, randomEmail, randomPassword, waitMailInterval } from '../../support/gotrue';
|
|
import { expectMailCount, extractTokenHash, waitForMail } from '../../support/mailpit';
|
|
|
|
const gotrue = new GoTrueClient();
|
|
|
|
test.describe('KTO-01 Kriterium 6: unbestaetigtes Konto (api)', () => {
|
|
test('KTO-01 Kriterium 6: richtiges Passwort -> email_not_confirmed, falsches Passwort -> invalid_credentials', async () => {
|
|
const email = randomEmail();
|
|
const password = randomPassword();
|
|
await gotrue.signUp(email, password);
|
|
|
|
const right = await gotrue.signIn(email, password);
|
|
expect(right.status).toBe(400);
|
|
expect(right.body.error_code).toBe('email_not_confirmed');
|
|
|
|
const wrong = await gotrue.signIn(email, `${password}-falsch`);
|
|
expect(wrong.status).toBe(400);
|
|
expect(wrong.body.error_code).toBe('invalid_credentials');
|
|
});
|
|
|
|
test('KTO-01 Kriterium 6: erneut senden -> zweite Mail, deren Link das Konto bestaetigt (AUTH-CFG-08: lokal 1 s)', async () => {
|
|
const email = randomEmail();
|
|
const password = randomPassword();
|
|
await gotrue.signUp(email, password);
|
|
await waitForMail(email);
|
|
await waitMailInterval();
|
|
|
|
const resend = await gotrue.resend(email);
|
|
expect(resend.status).toBe(200);
|
|
const second = await waitForMail(email, 2);
|
|
const { tokenHash } = extractTokenHash(second);
|
|
expect((await gotrue.verify(tokenHash, 'email')).status).toBe(200);
|
|
expect((await gotrue.signIn(email, password)).status).toBe(200);
|
|
});
|
|
|
|
test('KTO-01 Kriterium 6: erneut senden fuer unbekannte Adresse -> 200, keine Mail (keine Enumeration)', async () => {
|
|
const unknown = randomEmail('unknown');
|
|
const res = await gotrue.resend(unknown);
|
|
expect(res.status).toBe(200);
|
|
await expectMailCount(unknown, 0);
|
|
});
|
|
});
|
|
|
|
test.describe('KTO-01 Kriterium 7: keine Auskunft ueber Konten (api)', () => {
|
|
test('KTO-01 Kriterium 7: falsche E-Mail und falsches Passwort liefern identische Antworten', async () => {
|
|
const email = randomEmail();
|
|
const password = randomPassword();
|
|
await gotrue.createConfirmedUser(email, password);
|
|
|
|
const wrongPassword = await gotrue.signIn(email, `${password}-falsch`);
|
|
const wrongEmail = await gotrue.signIn(randomEmail('unknown'), password);
|
|
expect(wrongPassword.status).toBe(400);
|
|
expect(wrongEmail.status).toBe(wrongPassword.status);
|
|
expect(wrongEmail.body.error_code).toBe('invalid_credentials');
|
|
expect(wrongEmail.body).toEqual(wrongPassword.body);
|
|
});
|
|
});
|