Skip to content
45 changes: 21 additions & 24 deletions apps/meteor/tests/e2e/access-security-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Users } from './fixtures/userStates';
import { AccountProfile } from './page-objects';
import { setSettingValueById } from './utils/setSettingValueById';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });

test.describe.serial('access-security-page', () => {
let poAccountProfile: AccountProfile;

test.beforeAll(async ({ api }) => {
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([
setSettingValueById(api, 'Accounts_AllowPasswordChange', false),
setSettingValueById(api, 'Accounts_TwoFactorAuthentication_Enabled', false),
setSettingValueById(api, 'E2E_Enable', false),
updateSetting('Accounts_AllowPasswordChange', false, true),
updateSetting('Accounts_TwoFactorAuthentication_Enabled', false, true),
updateSetting('E2E_Enable', false, false),
]);
});

Expand All @@ -22,13 +21,9 @@ test.describe.serial('access-security-page', () => {
await page.waitForSelector('.main-content');
});

test.afterAll(async ({ api }) =>
Promise.all([
setSettingValueById(api, 'Accounts_AllowPasswordChange', true),
setSettingValueById(api, 'Accounts_TwoFactorAuthentication_Enabled', true),
setSettingValueById(api, 'E2E_Enable', false),
]),
);
test.afterAll(async ({ restoreSettings }) => {
await restoreSettings();
});

test('security tab is invisible when password change, 2FA and E2E are disabled', async ({ page }) => {
const securityTab = poAccountProfile.sidenav.linkSecurity;
Expand All @@ -38,11 +33,11 @@ test.describe.serial('access-security-page', () => {
});

test.describe.serial('can access account security sections', () => {
test.beforeAll(async ({ api }) => {
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([
setSettingValueById(api, 'Accounts_AllowPasswordChange', true),
setSettingValueById(api, 'Accounts_TwoFactorAuthentication_Enabled', false),
setSettingValueById(api, 'E2E_Enable', false),
updateSetting('Accounts_AllowPasswordChange', true),
updateSetting('Accounts_TwoFactorAuthentication_Enabled', false),
updateSetting('E2E_Enable', false),
]);
});

Expand All @@ -60,21 +55,23 @@ test.describe.serial('access-security-page', () => {
await expect(poAccountProfile.securityPasswordSection).toBeVisible();
});

test('can access 2FA setting when enabled but password change and E2E are disabled', async ({ api }) => {
test('can access 2FA setting when enabled but password change and E2E are disabled', async ({ updateSetting }) => {
await Promise.all([
setSettingValueById(api, 'Accounts_AllowPasswordChange', false),
setSettingValueById(api, 'Accounts_TwoFactorAuthentication_Enabled', true),
setSettingValueById(api, 'E2E_Enable', false),
updateSetting('Accounts_AllowPasswordChange', false),
updateSetting('Accounts_TwoFactorAuthentication_Enabled', true),
updateSetting('E2E_Enable', false),
]);

await expect(poAccountProfile.security2FASection).toBeVisible();
});

test('can access E2E setting when enabled but password change and 2FA are disabled', async ({ api }) => {
test('can access E2E setting when enabled but password change and 2FA are disabled', async ({ updateSetting }) => {
await Promise.all([
setSettingValueById(api, 'Accounts_AllowPasswordChange', false),
setSettingValueById(api, 'Accounts_TwoFactorAuthentication_Enabled', false),
setSettingValueById(api, 'E2E_Enable', true),
updateSetting('Accounts_AllowPasswordChange', false),
updateSetting('Accounts_TwoFactorAuthentication_Enabled', false),
updateSetting('E2E_Enable', true),
]);

await expect(poAccountProfile.securityE2EEncryptionSection).toBeVisible();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ test.describe.serial('Forget session on window close setting', () => {
});

test.describe('Setting off', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
test.beforeAll(async ({ updateSetting }) => {
await updateSetting('Accounts_ForgetUserSessionOnWindowClose', false, false);
});

test('Login using credentials and reload to stay logged in', async ({ page, context }) => {
Expand All @@ -32,12 +32,12 @@ test.describe.serial('Forget session on window close setting', () => {

// TODO: Fix this test
test.describe.skip('Setting on', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true });
test.beforeAll(async ({ updateSetting }) => {
await updateSetting('Accounts_ForgetUserSessionOnWindowClose', true);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false });
test.afterAll(async ({ restoreSettings }) => {
await restoreSettings();
});

test('Login using credentials and reload to get logged out', async ({ page, context }) => {
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/tests/e2e/administration-settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Users } from './fixtures/userStates';
import { Admin } from './page-objects';
import { getSettingValueById, setSettingValueById } from './utils';
import { getSettingValueById } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });
Expand Down Expand Up @@ -42,9 +42,9 @@ test.describe.parallel('administration-settings', () => {
await page.goto('/admin/settings/Layout');
});

test.afterAll(async ({ api }) => setSettingValueById(api, 'theme-custom-css', ''));
test.afterAll(async ({ updateSetting }) => updateSetting('theme-custom-css', ''));

test('should display the code mirror correctly', async ({ page, api }) => {
test('should display the code mirror correctly', async ({ page, updateSetting }) => {
await poAdmin.getAccordionBtnByName('Custom CSS').click();

await test.step('should render only one code mirror element', async () => {
Expand All @@ -60,7 +60,7 @@ test.describe.parallel('administration-settings', () => {

await test.step('should reflect updated value when valueProp changes after server update', async () => {
const codeValue = `.test-class-${Date.now()} { background-color: red; }`;
await setSettingValueById(api, 'theme-custom-css', codeValue);
await updateSetting('theme-custom-css', codeValue);

const codeMirrorParent = page.getByRole('code');
await expect(codeMirrorParent.locator('.CodeMirror-line')).toHaveText(codeValue);
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/tests/e2e/administration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { faker } from '@faker-js/faker';
import { IS_EE } from './config/constants';
import { Users } from './fixtures/userStates';
import { Admin, Utils } from './page-objects';
import { createTargetChannel, setSettingValueById } from './utils';
import { createTargetChannel } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });
Expand Down Expand Up @@ -282,16 +282,16 @@ test.describe.parallel('administration', () => {
'javascript,css,markdown,dockerfile,json,go,rust,clean,bash,plaintext,powershell,scss,shell,yaml,vim';
const incomingIntegrationName = faker.string.uuid();

test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Message_Code_highlight', '');
test.beforeAll(async ({ updateSetting }) => {
await updateSetting('Message_Code_highlight', '', messageCodeHighlightDefault);
});

test.beforeEach(async ({ page }) => {
await page.goto('/admin/integrations');
});

test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'Message_Code_highlight', messageCodeHighlightDefault);
test.afterAll(async ({ restoreSettings }) => {
await restoreSettings();
});

test('should display the example payload correctly', async () => {
Expand Down
14 changes: 7 additions & 7 deletions apps/meteor/tests/e2e/anonymous-user.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { faker } from '@faker-js/faker';

import { HomeChannel, Registration } from './page-objects';
import { setSettingValueById } from './utils/setSettingValueById';
import { expect, test } from './utils/test';

test.describe('anonymous-user', () => {
let poHomeChannel: HomeChannel;

test.beforeAll(async ({ api }) => {
await expect((await setSettingValueById(api, 'Accounts_AllowAnonymousRead', true)).status()).toBe(200);
await expect((await setSettingValueById(api, 'Accounts_AllowAnonymousWrite', true)).status()).toBe(200);
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([
updateSetting('Accounts_AllowAnonymousRead', true, false),
updateSetting('Accounts_AllowAnonymousWrite', true, false),
]);
});

test.afterAll(async ({ api }) => {
await expect((await setSettingValueById(api, 'Accounts_AllowAnonymousRead', false)).status()).toBe(200);
await expect((await setSettingValueById(api, 'Accounts_AllowAnonymousWrite', false)).status()).toBe(200);
test.afterAll(async ({ restoreSettings }) => {
await restoreSettings();
});

test.beforeEach(async ({ page }) => {
Expand Down
14 changes: 7 additions & 7 deletions apps/meteor/tests/e2e/avatar-settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { createTargetChannel, createTargetPrivateChannel, createDirectMessage } from './utils';
import { setSettingValueById } from './utils/setSettingValueById';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });
Expand Down Expand Up @@ -34,14 +33,15 @@ test.describe('avatar-settings', () => {
test.describe('external avatar provider', () => {
const providerUrlPrefix = 'https://example.com/avatar/';

test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', `${providerUrlPrefix}{username}`);
await setSettingValueById(api, 'Accounts_AvatarExternalUrl', `${providerUrlPrefix}{username}`);
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([
updateSetting('Accounts_RoomAvatarExternalUrl', `${providerUrlPrefix}{username}`, ''),
updateSetting('Accounts_AvatarExternalUrl', `${providerUrlPrefix}{username}`, ''),
]);
});

test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', '');
await setSettingValueById(api, 'Accounts_AvatarExternalUrl', '');
test.afterAll(async ({ restoreSettings }) => {
await restoreSettings();
});

test.describe('public channels', () => {
Expand Down
78 changes: 29 additions & 49 deletions apps/meteor/tests/e2e/e2e-encryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ test.describe.serial('e2e-encryption initial setup', () => {
poHomeChannel = new HomeChannel(page);
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: true });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: true });
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([updateSetting('E2E_Enable', true, false), updateSetting('E2E_Allow_Unencrypted_Messages', true, false)]);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
test.afterAll(async ({ restoreSettings }) => {
await restoreSettings();
});

test.afterEach(async ({ api }) => {
Expand Down Expand Up @@ -252,20 +250,19 @@ test.describe.serial('e2e-encryption', () => {

test.use({ storageState: Users.userE2EE.state });

test.beforeEach(async ({ page, api }) => {
await api.post('/settings/E2E_Enable', { value: true });
test.beforeEach(async ({ page, updateSetting }) => {
await updateSetting('E2E_Enable', true, false);

poHomeChannel = new HomeChannel(page);
await page.goto('/home');
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: true });
test.beforeAll(async ({ updateSetting }) => {
await updateSetting('E2E_Allow_Unencrypted_Messages', true, false);
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
test.afterAll(async ({ restoreSettings }) => {
await restoreSettings();
});

test('expect create a private channel encrypted and send an encrypted message', async ({ page }) => {
Expand Down Expand Up @@ -517,9 +514,11 @@ test.describe.serial('e2e-encryption', () => {
});

test.describe('File Encryption', async () => {
test.afterAll(async ({ api }) => {
await api.post('/settings/FileUpload_MediaTypeWhiteList', { value: '' });
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'image/svg+xml' });
test.afterAll(async ({ updateSetting }) => {
await Promise.all([
updateSetting('FileUpload_MediaTypeWhiteList', ''),
updateSetting('FileUpload_MediaTypeBlackList', 'image/svg+xml'),
]);
});

test('File and description encryption', async ({ page }) => {
Expand Down Expand Up @@ -551,7 +550,7 @@ test.describe.serial('e2e-encryption', () => {
});
});

test('File encryption with whitelisted and blacklisted media types', async ({ page, api }) => {
test('File encryption with whitelisted and blacklisted media types', async ({ page, updateSetting }) => {
await test.step('create an encrypted room', async () => {
const channelName = faker.string.uuid();

Expand Down Expand Up @@ -580,7 +579,7 @@ test.describe.serial('e2e-encryption', () => {
});

await test.step('set whitelisted media type setting', async () => {
await api.post('/settings/FileUpload_MediaTypeWhiteList', { value: 'text/plain' });
await updateSetting('FileUpload_MediaTypeWhiteList', 'text/plain', '');
});

await test.step('send text file again with whitelist setting set', async () => {
Expand All @@ -595,7 +594,7 @@ test.describe.serial('e2e-encryption', () => {
});

await test.step('set blacklisted media type setting to not accept application/octet-stream media type', async () => {
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'application/octet-stream' });
await updateSetting('FileUpload_MediaTypeBlackList', 'application/octet-stream', 'image/svg+xml');
});

await test.step('send text file again with blacklisted setting set, file upload should fail', async () => {
Expand All @@ -611,14 +610,11 @@ test.describe.serial('e2e-encryption', () => {
});

test.describe('File encryption setting disabled', async () => {
test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable_Encrypt_Files', { value: false });
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'application/octet-stream' });
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable_Encrypt_Files', { value: true });
await api.post('/settings/FileUpload_MediaTypeBlackList', { value: 'image/svg+xml' });
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([
updateSetting('E2E_Enable_Encrypt_Files', false, true),
updateSetting('FileUpload_MediaTypeBlackList', 'application/octet-stream', 'image/svg+xml'),
]);
});

test('Upload file without encryption in e2ee room', async ({ page }) => {
Expand Down Expand Up @@ -695,12 +691,8 @@ test.describe.serial('e2e-encryption', () => {
poHomeChannel = new HomeChannel(page);
await page.goto('/home');
});
test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: true });
test.beforeAll(async ({ updateSetting }) => {
await updateSetting('E2E_Allow_Unencrypted_Messages', false, true);
});

test('expect slash commands to be disabled in an e2ee room', async ({ page }) => {
Expand Down Expand Up @@ -858,14 +850,8 @@ test.describe.serial('e2ee room setup', () => {
poHomeChannel = new HomeChannel(page);
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: true });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([updateSetting('E2E_Enable', true, false), updateSetting('E2E_Allow_Unencrypted_Messages', false, false)]);
});

test.afterEach(async ({ api }) => {
Expand Down Expand Up @@ -1046,14 +1032,8 @@ test.describe('e2ee support legacy formats', () => {
poHomeChannel = new HomeChannel(page);
});

test.beforeAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: true });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
});

test.afterAll(async ({ api }) => {
await api.post('/settings/E2E_Enable', { value: false });
await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: false });
test.beforeAll(async ({ updateSetting }) => {
await Promise.all([updateSetting('E2E_Enable', true, false), updateSetting('E2E_Allow_Unencrypted_Messages', false, false)]);
});

// ->>>>>>>>>>>Not testing upload since it was not implemented in the legacy format
Expand Down
Loading