-
Notifications
You must be signed in to change notification settings - Fork 13.7k
test: refactor e2ee encrypted channels tests #36987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
4fcaf37
52a35c1
3f11fbc
4b6e5f3
b9668ef
ac098ce
1db3ca3
8ac6952
0170e6c
3ec2578
fc43abc
4d4737b
a03af2e
a4011ea
085a776
4de43c6
c77d994
56ab9ee
f5ee4fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,120 @@ | ||||||||||||||||||||||||||||||
| import { faker } from '@faker-js/faker'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import { Users } from '../fixtures/userStates'; | ||||||||||||||||||||||||||||||
| import { HomeChannel } from '../page-objects'; | ||||||||||||||||||||||||||||||
| import { EncryptedRoomPage } from '../page-objects/encrypted-room'; | ||||||||||||||||||||||||||||||
| import { DisableRoomEncryptionModal, EnableRoomEncryptionModal, CreateE2EEChannel } from '../page-objects/fragments/e2ee'; | ||||||||||||||||||||||||||||||
| import { deleteRoom } from '../utils/create-target-channel'; | ||||||||||||||||||||||||||||||
| import { preserveSettings } from '../utils/preserveSettings'; | ||||||||||||||||||||||||||||||
| import { resolvePrivateRoomId } from '../utils/resolve-room-id'; | ||||||||||||||||||||||||||||||
| import { test, expect } from '../utils/test'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const settingsList = ['E2E_Enable', 'E2E_Allow_Unencrypted_Messages']; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| preserveSettings(settingsList); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| test.describe('E2EE Channel Basic Functionality', () => { | ||||||||||||||||||||||||||||||
| const createdChannels: { name: string; id?: string | null }[] = []; | ||||||||||||||||||||||||||||||
| let poHomeChannel: HomeChannel; | ||||||||||||||||||||||||||||||
| let encryptedRoomPage: EncryptedRoomPage; | ||||||||||||||||||||||||||||||
| let enableEncryptionModal: EnableRoomEncryptionModal; | ||||||||||||||||||||||||||||||
| let disableEncryptionModal: DisableRoomEncryptionModal; | ||||||||||||||||||||||||||||||
| let createE2EEChannel: CreateE2EEChannel; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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); | ||||||||||||||||||||||||||||||
| encryptedRoomPage = new EncryptedRoomPage(page); | ||||||||||||||||||||||||||||||
| createE2EEChannel = new CreateE2EEChannel(page); | ||||||||||||||||||||||||||||||
| await poHomeChannel.goto(); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| test.afterAll(async ({ api }) => { | ||||||||||||||||||||||||||||||
| await Promise.all(createdChannels.map(({ id }) => (id ? deleteRoom(api, id) : Promise.resolve()))); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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 createE2EEChannel.createAndStore(channelName, createdChannels); | ||||||||||||||||||||||||||||||
| await poHomeChannel.content.waitForChannel(); | ||||||||||||||||||||||||||||||
| 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(encryptedRoomPage.lastMessage.encryptedIcon).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(encryptedRoomPage.lastMessage.encryptedIcon).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(encryptedRoomPage.lastMessage.encryptedIcon).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(); | ||||||||||||||||||||||||||||||
| const roomId = await resolvePrivateRoomId(page, channelName); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| createdChannels.push({ name: channelName, id: roomId ?? undefined }); | ||||||||||||||||||||||||||||||
| await expect(page).toHaveURL(`/group/${channelName}`); | ||||||||||||||||||||||||||||||
| await expect(poHomeChannel.toastSuccess).toBeVisible(); | ||||||||||||||||||||||||||||||
| await poHomeChannel.dismissToast(); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
Comment on lines
+98
to
+104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert roomId resolution to ensure cleanup and fail fast If resolvePrivateRoomId returns null, you silently skip cleanup. Assert and store a non-null id. Apply this diff: - const roomId = await resolvePrivateRoomId(page, channelName);
-
- createdChannels.push({ name: channelName, id: roomId ?? undefined });
+ const roomId = await resolvePrivateRoomId(page, channelName);
+ await expect(roomId, 'Failed to resolve roomId for cleanup').toBeTruthy();
+ createdChannels.push({ name: channelName, id: roomId! });Based on learnings 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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(encryptedRoomPage.lastMessage.encryptedIcon).toBeVisible(); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run this describe serially to protect shared E2E settings.
beforeAllsets/settings/E2E_Enableand friends,afterAll(viapreserveSettings) restores them. When multiple specs now execute in parallel, one suite can finish and revert the settings while another is still using them—classic flake territory. Please mark the describe as serial (or otherwise coordinate) so the toggled settings stay consistent for the duration of the suite.test.describe('E2EE Channel Basic Functionality', () => { + test.describe.configure({ mode: 'serial' });🤖 Prompt for AI Agents