-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
260 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { test, expect, type TestInfo } from '@playwright/test'; | ||
import { MailDev } from 'maildev'; | ||
|
||
import * as utils from "../global-utils"; | ||
import { createAccount, logUser } from './setups/user'; | ||
|
||
let users = utils.loadEnv(); | ||
|
||
let mailserver, user1Mails, user2Mails, user3Mails; | ||
|
||
test.beforeAll('Setup', async ({ browser }, testInfo: TestInfo) => { | ||
mailserver = new MailDev({ | ||
port: process.env.MAILDEV_PORT | ||
}) | ||
|
||
await mailserver.listen(); | ||
|
||
await utils.startVaultwarden(browser, testInfo, { | ||
SMTP_HOST: process.env.MAILDEV_HOST, | ||
SMTP_FROM: process.env.VAULTWARDEN_SMTP_FROM, | ||
}); | ||
|
||
user1Mails = mailserver.iterator(users.user1.email); | ||
user2Mails = mailserver.iterator(users.user2.email); | ||
user3Mails = mailserver.iterator(users.user3.email); | ||
}); | ||
|
||
test.afterAll('Teardown', async ({}, testInfo: TestInfo) => { | ||
utils.stopVaultwarden(testInfo); | ||
if( mailserver ){ | ||
await mailserver.close(); | ||
|
||
[user1Mails, user2Mails, user3Mails].map((mails) => { | ||
if(mails){ | ||
mails.return(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
test('Create user3', async ({ page }) => { | ||
await createAccount(test, page, users.user3, user3Mails); | ||
}); | ||
|
||
test('Invite users', async ({ page }) => { | ||
await createAccount(test, page, users.user1, user1Mails); | ||
await logUser(test, page, users.user1, user1Mails); | ||
|
||
await test.step('Create Org', async () => { | ||
await page.getByRole('link', { name: 'New organization' }).click(); | ||
await page.getByLabel('Organization name (required)').fill('Test'); | ||
await page.getByRole('button', { name: 'Submit' }).click(); | ||
await page.locator('div').filter({ hasText: 'Members' }).nth(2).click(); | ||
}); | ||
|
||
await test.step('Invite user2', async () => { | ||
await page.getByRole('button', { name: 'Invite member' }).click(); | ||
await page.getByLabel('Email (required)').fill(users.user2.email); | ||
await page.getByRole('tab', { name: 'Collections' }).click(); | ||
await page.locator('label').filter({ hasText: 'Grant access to all current' }).click(); | ||
await page.getByRole('button', { name: 'Save' }).click(); | ||
await page.getByTestId("toast-message").getByLabel('Success User(s) invited') | ||
}); | ||
|
||
await test.step('Invite user3', async () => { | ||
await page.getByRole('button', { name: 'Invite member' }).click(); | ||
await page.getByLabel('Email (required)').fill(users.user3.email); | ||
await page.getByRole('tab', { name: 'Collections' }).click(); | ||
await page.locator('label').filter({ hasText: 'Grant access to all current' }).click(); | ||
await page.getByRole('button', { name: 'Save' }).click(); | ||
await page.getByTestId("toast-message").getByLabel('Success User(s) invited') | ||
}); | ||
}); | ||
|
||
test('invited with new account', async ({ page }) => { | ||
const { value: invited } = await user2Mails.next(); | ||
expect(invited.subject).toContain("Join Test") | ||
|
||
await test.step('Create account', async () => { | ||
await page.setContent(invited.html); | ||
const link = await page.getByTestId("invite").getAttribute("href"); | ||
await page.goto(link); | ||
await expect(page).toHaveTitle(/Create account | Vaultwarden Web/); | ||
|
||
await page.getByLabel('Name').fill(users.user2.name); | ||
await page.getByLabel('Master password\n (required)', { exact: true }).fill(users.user2.password); | ||
await page.getByLabel('Re-type master password').fill(users.user2.password); | ||
await page.getByRole('button', { name: 'Create account' }).click(); | ||
|
||
// Back to the login page | ||
await expect(page).toHaveTitle('Vaultwarden Web'); | ||
await page.getByTestId("toast-message").getByLabel('Your new account has been created') | ||
|
||
const { value: welcome } = await user2Mails.next(); | ||
expect(welcome.subject).toContain("Welcome") | ||
}); | ||
|
||
await test.step('Login', async () => { | ||
await page.getByLabel(/Email address/).fill(users.user2.email); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
|
||
// Unlock page | ||
await page.getByLabel('Master password').fill(users.user2.password); | ||
await page.getByRole('button', { name: 'Log in with master password' }).click(); | ||
|
||
// We are now in the default vault page | ||
await expect(page).toHaveTitle(/Vaults/); | ||
await page.getByTestId("toast-message").getByLabel('Invitation accepted'); | ||
|
||
const { value: logged } = await user2Mails.next(); | ||
expect(logged.subject).toContain("New Device Logged"); | ||
}); | ||
|
||
const { value: accepted } = await user1Mails.next(); | ||
expect(accepted.subject).toContain("Invitation to Test accepted") | ||
}); | ||
|
||
test('invited with existing account', async ({ page }) => { | ||
const { value: invited } = await user3Mails.next(); | ||
expect(invited.subject).toContain("Join Test") | ||
|
||
await page.setContent(invited.html); | ||
const link = await page.getByTestId("invite").getAttribute("href"); | ||
|
||
await page.goto(link); | ||
|
||
// We should be on login page with email prefilled | ||
await expect(page).toHaveTitle(/Vaultwarden Web/); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
|
||
// Unlock page | ||
await page.getByLabel('Master password').fill(users.user3.password); | ||
await page.getByRole('button', { name: 'Log in with master password' }).click(); | ||
|
||
// We are now in the default vault page | ||
await expect(page).toHaveTitle(/Vaults/); | ||
await page.getByTestId("toast-message").getByLabel('Invitation accepted'); | ||
|
||
const { value: logged } = await user3Mails.next(); | ||
expect(logged.subject).toContain("New Device Logged") | ||
|
||
const { value: accepted } = await user1Mails.next(); | ||
expect(accepted.subject).toContain("Invitation to Test accepted") | ||
}); | ||
|
||
test('Confirm invited user', async ({ page }) => { | ||
await logUser(test, page, users.user1, user1Mails); | ||
await page.getByLabel('Switch products').click(); | ||
await page.getByRole('link', { name: ' Admin Console' }).click(); | ||
await page.getByLabel('Members').click(); | ||
|
||
await test.step('Accept user2', async () => { | ||
await page.getByRole('row', { name: users.user2.name }).getByLabel('Options').click(); | ||
await page.getByRole('menuitem', { name: 'Confirm' }).click(); | ||
await page.getByRole('button', { name: 'Confirm' }).click(); | ||
await page.getByTestId("toast-message").getByLabel('Success'); | ||
|
||
const { value: logged } = await user2Mails.next(); | ||
expect(logged.subject).toContain("Invitation to Test confirmed"); | ||
}); | ||
}); | ||
|
||
test('Organization is visible', async ({ page }) => { | ||
await logUser(test, page, users.user2, user2Mails); | ||
await page.getByLabel('vault: Test').click(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect, type Browser,Page } from '@playwright/test'; | ||
|
||
export async function createAccount(test, page: Page, user: { email: string, name: string, password: string }, emails) { | ||
await test.step('Create user', async () => { | ||
// Landing page | ||
await page.goto('/'); | ||
await page.getByRole('link', { name: 'Create account' }).click(); | ||
|
||
// Back to Vault create account | ||
await expect(page).toHaveTitle(/Create account | Vaultwarden Web/); | ||
await page.getByLabel(/Email address/).fill(user.email); | ||
await page.getByLabel('Name').fill(user.name); | ||
await page.getByLabel('Master password\n (required)', { exact: true }).fill(user.password); | ||
await page.getByLabel('Re-type master password').fill(user.password); | ||
await page.getByRole('button', { name: 'Create account' }).click(); | ||
|
||
// Back to the login page | ||
await expect(page).toHaveTitle('Vaultwarden Web'); | ||
await page.getByTestId("toast-message").getByLabel('Your new account has been created'); | ||
|
||
if( emails ){ | ||
const { value: welcome } = await emails.next(); | ||
expect(welcome.subject).toContain("Welcome"); | ||
} | ||
}); | ||
} | ||
|
||
export async function logUser(test, page: Page, user: { email: string, password: string }, emails) { | ||
await test.step('Log user', async () => { | ||
// Landing page | ||
await page.goto('/'); | ||
await page.getByLabel(/Email address/).fill(user.email); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
|
||
// Unlock page | ||
await page.getByLabel('Master password').fill(user.password); | ||
await page.getByRole('button', { name: 'Log in with master password' }).click(); | ||
|
||
// We are now in the default vault page | ||
await expect(page).toHaveTitle(/Vaults/); | ||
|
||
if( emails ){ | ||
const { value: logged } = await emails.next(); | ||
expect(logged.subject).toContain("New Device Logged"); | ||
} | ||
}); | ||
} |
Oops, something went wrong.