Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions apps/meteor/tests/e2e/e2e-encryption/e2ee-channel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { faker } from '@faker-js/faker';

import { Users } from '../fixtures/userStates';
import { HomeChannel } from '../page-objects';
import { DisableRoomEncryptionModal, EnableRoomEncryptionModal } from '../page-objects/fragments/e2ee';
import { preserveSettings } from '../utils/preserveSettings';
import { test, expect } from '../utils/test';

const settingsList = ['E2E_Enable', 'E2E_Allow_Unencrypted_Messages'];

preserveSettings(settingsList);

test.describe('E2EE Channel Basic Functionality', () => {
const createdChannels: string[] = [];
let poHomeChannel: HomeChannel;
let enableEncryptionModal: EnableRoomEncryptionModal;
let disableEncryptionModal: DisableRoomEncryptionModal;

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

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

test.beforeEach(async ({ page }) => {
poHomeChannel = new HomeChannel(page);
enableEncryptionModal = new EnableRoomEncryptionModal(page);
disableEncryptionModal = new DisableRoomEncryptionModal(page);
await page.goto('/home');
});

test.afterAll(async ({ api }) => {
await Promise.all(createdChannels.map((channelName) => api.post('/groups.delete', { roomName: channelName })));
});

test('expect create a private channel encrypted and send an encrypted message', async ({ page }) => {
const channelName = faker.string.uuid();

await test.step('create encrypted channel', async () => {
await poHomeChannel.sidenav.createEncryptedChannel(channelName);
createdChannels.push(channelName);
await expect(page).toHaveURL(`/group/${channelName}`);
await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible();
});

await test.step('send encrypted message and verify encryption', async () => {
await poHomeChannel.content.sendMessage('hello world');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world');
await expect(poHomeChannel.content.getMessageEncryptedIcon(poHomeChannel.content.lastUserMessage)).toBeVisible();
});

await test.step('disable encryption', async () => {
await poHomeChannel.tabs.kebab.click({ force: true });
await expect(poHomeChannel.tabs.btnDisableE2E).toBeVisible();
await poHomeChannel.tabs.btnDisableE2E.click({ force: true });
await disableEncryptionModal.disable();
await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeHidden();
});

await test.step('send unencrypted message and verify no encryption', async () => {
await poHomeChannel.content.sendMessage('hello world not encrypted');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world not encrypted');
await expect(poHomeChannel.content.getMessageEncryptedIcon(poHomeChannel.content.lastUserMessage)).not.toBeVisible();
});

await test.step('re-enable encryption', async () => {
await poHomeChannel.tabs.kebab.click({ force: true });
await expect(poHomeChannel.tabs.btnEnableE2E).toBeVisible();
await poHomeChannel.tabs.btnEnableE2E.click({ force: true });
await enableEncryptionModal.enable();
await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible();
});

await test.step('send encrypted message again and verify encryption restored', async () => {
await poHomeChannel.content.sendMessage('hello world encrypted again');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world encrypted again');
await expect(poHomeChannel.content.getMessageEncryptedIcon(poHomeChannel.content.lastUserMessage)).toBeVisible();
});
});

test('expect create a private channel, encrypt it and send an encrypted message', async ({ page }) => {
const channelName = faker.string.uuid();

await test.step('create private channel', async () => {
await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.fill(channelName);
await poHomeChannel.sidenav.btnCreate.click();
await poHomeChannel.content.waitForChannel();
createdChannels.push(channelName);
await expect(page).toHaveURL(`/group/${channelName}`);
await expect(poHomeChannel.toastSuccess).toBeVisible();
await poHomeChannel.dismissToast();
});

await test.step('enable encryption', async () => {
await poHomeChannel.tabs.kebab.click();
await expect(poHomeChannel.tabs.btnEnableE2E).toBeVisible();
await poHomeChannel.tabs.btnEnableE2E.click();
await enableEncryptionModal.enable();
await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible();
});

await test.step('send encrypted message and verify', async () => {
await poHomeChannel.content.sendMessage('hello world');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world');
await expect(poHomeChannel.content.getMessageEncryptedIcon(poHomeChannel.content.lastUserMessage)).toBeVisible();
});
});
});
Loading
Loading