You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
4.3 KiB
115 lines
4.3 KiB
import { expect, type Page, Test } from '@playwright/test';
|
|
import { type MailBuffer, MailServer } from 'maildev';
|
|
|
|
import * as utils from '../../global-utils';
|
|
import { submitTwoFactor, type TwoFactor } from './2fa';
|
|
import { fillNewMasterPassword } from './user';
|
|
|
|
/**
|
|
* If a MailBuffer is passed it will be used and consume the expected emails
|
|
*/
|
|
export async function logNewUser(
|
|
test: Test,
|
|
page: Page,
|
|
user: { email: string, name: string, password: string },
|
|
options: { mailBuffer?: MailBuffer } = {}
|
|
) {
|
|
await test.step(`Create user ${user.name}`, async () => {
|
|
await page.context().clearCookies();
|
|
|
|
await test.step('Landing page', async () => {
|
|
await utils.cleanLanding(page);
|
|
|
|
await page.locator("input[type=email].vw-email-sso").fill(user.email);
|
|
await page.getByRole('button', { name: /Use single sign-on/ }).click();
|
|
});
|
|
|
|
await test.step('Keycloak login', async () => {
|
|
await expect(page.getByRole('heading', { name: 'Sign in to your account' })).toBeVisible();
|
|
await page.getByLabel(/Username/).fill(user.name);
|
|
await page.getByLabel('Password', { exact: true }).fill(user.password);
|
|
await page.getByRole('button', { name: 'Sign In' }).click();
|
|
});
|
|
|
|
await test.step('Create Vault account', async () => {
|
|
await expect(page.getByRole('heading', { name: 'Join organisation' })).toBeVisible();
|
|
await fillNewMasterPassword(page, user.password);
|
|
await page.getByRole('button', { name: 'Create account' }).click();
|
|
});
|
|
|
|
await utils.checkNotification(page, 'Account successfully created!');
|
|
await utils.checkNotification(page, 'Invitation accepted');
|
|
|
|
await utils.ignoreExtension(page);
|
|
|
|
await test.step('Default vault page', async () => {
|
|
await expect(page).toHaveTitle(/Vaultwarden Web/);
|
|
await expect(page.getByTitle('All vaults', { exact: true })).toBeVisible();
|
|
});
|
|
|
|
if( options.mailBuffer ){
|
|
let mailBuffer = options.mailBuffer;
|
|
await test.step('Check emails', async () => {
|
|
await mailBuffer.expect((m) => m.subject === "Welcome");
|
|
await mailBuffer.expect((m) => m.subject.includes("New Device Logged"));
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* If a MailBuffer is passed it will be used and consume the expected emails
|
|
*/
|
|
export async function logUser(
|
|
test: Test,
|
|
page: Page,
|
|
user: { email: string, password: string },
|
|
options: {
|
|
mailBuffer?: MailBuffer,
|
|
twoFactor?: TwoFactor,
|
|
} = {}
|
|
) {
|
|
let mailBuffer = options.mailBuffer;
|
|
|
|
await test.step(`Log user ${user.email}`, async () => {
|
|
await page.context().clearCookies();
|
|
|
|
await test.step('Landing page', async () => {
|
|
await utils.cleanLanding(page);
|
|
|
|
await page.locator("input[type=email].vw-email-sso").fill(user.email);
|
|
await page.getByRole('button', { name: /Use single sign-on/ }).click();
|
|
});
|
|
|
|
await test.step('Keycloak login', async () => {
|
|
await expect(page.getByRole('heading', { name: 'Sign in to your account' })).toBeVisible();
|
|
await page.getByLabel(/Username/).fill(user.name);
|
|
await page.getByLabel('Password', { exact: true }).fill(user.password);
|
|
await page.getByRole('button', { name: 'Sign In' }).click();
|
|
});
|
|
|
|
if( options.twoFactor ){
|
|
await submitTwoFactor(test, page, options.twoFactor);
|
|
}
|
|
|
|
await test.step('Unlock vault', async () => {
|
|
await expect(page).toHaveTitle('Vaultwarden Web');
|
|
await expect(page.getByRole('heading', { name: 'Your vault is locked' })).toBeVisible();
|
|
await page.getByLabel('Master password').fill(user.password);
|
|
await page.getByRole('button', { name: 'Unlock' }).click();
|
|
});
|
|
|
|
await utils.ignoreExtension(page);
|
|
|
|
await test.step('Default vault page', async () => {
|
|
await expect(page).toHaveTitle(/Vaultwarden Web/);
|
|
await expect(page.getByTitle('All vaults', { exact: true })).toBeVisible();
|
|
});
|
|
|
|
if( mailBuffer ){
|
|
await test.step('Check email', async () => {
|
|
await mailBuffer.expect((m) => m.subject.includes("New Device Logged"));
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|