organization.smtp.spec.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { test, expect, type TestInfo } from '@playwright/test';
  2. import { MailDev } from 'maildev';
  3. import * as utils from '../global-utils';
  4. import * as orgs from './setups/orgs';
  5. import { createAccount, logUser } from './setups/user';
  6. let users = utils.loadEnv();
  7. let mailServer, mail1Buffer, mail2Buffer, mail3Buffer;
  8. test.beforeAll('Setup', async ({ browser }, testInfo: TestInfo) => {
  9. mailServer = new MailDev({
  10. port: process.env.MAILDEV_SMTP_PORT,
  11. web: { port: process.env.MAILDEV_HTTP_PORT },
  12. })
  13. await mailServer.listen();
  14. await utils.startVault(browser, testInfo, {
  15. SMTP_HOST: process.env.MAILDEV_HOST,
  16. SMTP_FROM: process.env.PW_SMTP_FROM,
  17. });
  18. mail1Buffer = mailServer.buffer(users.user1.email);
  19. mail2Buffer = mailServer.buffer(users.user2.email);
  20. mail3Buffer = mailServer.buffer(users.user3.email);
  21. });
  22. test.afterAll('Teardown', async ({}, testInfo: TestInfo) => {
  23. utils.stopVault(testInfo);
  24. [mail1Buffer, mail2Buffer, mail3Buffer, mailServer].map((m) => m?.close());
  25. });
  26. test('Create user3', async ({ page }) => {
  27. await createAccount(test, page, users.user3, mail3Buffer);
  28. });
  29. test('Invite users', async ({ page }) => {
  30. await createAccount(test, page, users.user1, mail1Buffer);
  31. await orgs.create(test, page, 'Test');
  32. await orgs.members(test, page, 'Test');
  33. await orgs.invite(test, page, 'Test', users.user2.email);
  34. await orgs.invite(test, page, 'Test', users.user3.email, {
  35. navigate: false,
  36. });
  37. });
  38. test('invited with new account', async ({ page }) => {
  39. const invited = await mail2Buffer.expect((mail) => mail.subject === 'Join Test');
  40. await test.step('Create account', async () => {
  41. await page.setContent(invited.html);
  42. const link = await page.getByTestId('invite').getAttribute('href');
  43. await page.goto(link);
  44. await expect(page).toHaveTitle(/Create account | Vaultwarden Web/);
  45. //await page.getByLabel('Name').fill(users.user2.name);
  46. await page.getByLabel('New master password (required)', { exact: true }).fill(users.user2.password);
  47. await page.getByLabel('Confirm new master password (').fill(users.user2.password);
  48. await page.getByRole('button', { name: 'Create account' }).click();
  49. await utils.checkNotification(page, 'Your new account has been created');
  50. // Redirected to the vault
  51. await expect(page).toHaveTitle('Vaults | Vaultwarden Web');
  52. await utils.checkNotification(page, 'You have been logged in!');
  53. await utils.checkNotification(page, 'Invitation accepted');
  54. });
  55. await test.step('Check mails', async () => {
  56. await mail2Buffer.expect((m) => m.subject === 'Welcome');
  57. await mail2Buffer.expect((m) => m.subject === 'New Device Logged In From Firefox');
  58. await mail1Buffer.expect((m) => m.subject.includes('Invitation to Test accepted'));
  59. });
  60. });
  61. test('invited with existing account', async ({ page }) => {
  62. const invited = await mail3Buffer.expect((mail) => mail.subject === 'Join Test');
  63. await page.setContent(invited.html);
  64. const link = await page.getByTestId('invite').getAttribute('href');
  65. await page.goto(link);
  66. // We should be on login page with email prefilled
  67. await expect(page).toHaveTitle(/Vaultwarden Web/);
  68. await page.getByRole('button', { name: 'Continue' }).click();
  69. // Unlock page
  70. await page.getByLabel('Master password').fill(users.user3.password);
  71. await page.getByRole('button', { name: 'Log in with master password' }).click();
  72. // We are now in the default vault page
  73. await expect(page).toHaveTitle(/Vaultwarden Web/);
  74. await utils.checkNotification(page, 'Invitation accepted');
  75. await mail3Buffer.expect((m) => m.subject === 'New Device Logged In From Firefox');
  76. await mail1Buffer.expect((m) => m.subject.includes('Invitation to Test accepted'));
  77. });
  78. test('Confirm invited user', async ({ page }) => {
  79. await logUser(test, page, users.user1, mail1Buffer);
  80. await orgs.members(test, page, 'Test');
  81. await orgs.confirm(test, page, 'Test', users.user2.email);
  82. await mail2Buffer.expect((m) => m.subject.includes('Invitation to Test confirmed'));
  83. });
  84. test('Organization is visible', async ({ page }) => {
  85. await logUser(test, page, users.user2, mail2Buffer);
  86. await page.getByRole('button', { name: 'vault: Test', exact: true }).click();
  87. await expect(page.getByLabel('Filter: Default collection')).toBeVisible();
  88. });