-
Notifications
You must be signed in to change notification settings - Fork 10k
/
e2e-encryption.spec.ts
213 lines (139 loc) · 7.54 KB
/
e2e-encryption.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { faker } from '@faker-js/faker';
import injectInitialData from './fixtures/inject-initial-data';
import { Users, storeState, restoreState } from './fixtures/userStates';
import { AccountProfile, HomeChannel } from './page-objects';
import { test, expect } from './utils/test';
// OK Enable e2ee on admin
// OK Test banner and check password, logout and use password
// OK Set new password, logout and use the password
// OK Reset key, should logout, login and check banner
// OK Create channel encrypted and send message
// OK Disable encryption and send message
// OK Enable encryption and send message
// OK Create channel not encrypted, encrypt end send message
test.use({ storageState: Users.admin.state });
test.describe.serial('e2e-encryption initial setup', () => {
let poAccountProfile: AccountProfile;
let poHomeChannel: HomeChannel;
let password: string;
test.beforeEach(async ({ page }) => {
poAccountProfile = new AccountProfile(page);
poHomeChannel = new HomeChannel(page);
await page.goto('/account/security');
});
test.beforeAll(async ({ api }) => {
const statusCode = (await api.post('/settings/E2E_Enable', { value: true })).status();
await expect(statusCode).toBe(200);
});
test.afterAll(async ({ api }) => {
const statusCode = (await api.post('/settings/E2E_Enable', { value: false })).status();
await expect(statusCode).toBe(200);
});
test.afterEach(async ({ api }) => {
await api.recreateContext();
});
test("expect reset user's e2e encryption key", async ({ page }) => {
// Reset key to start the flow from the beginning
// It will execute a logout
await poAccountProfile.securityE2EEncryptionSection.click();
await poAccountProfile.securityE2EEncryptionResetKeyButton.click();
await page.locator('role=button[name="Login"]').waitFor();
await injectInitialData();
// Login again, check the banner to save the generated password and test it
await restoreState(page, Users.admin);
await page.locator('role=banner >> text="Save Your Encryption Password"').click();
password = (await page.evaluate(() => localStorage.getItem('e2e.randomPassword'))) || 'undefined';
await expect(page.locator('#modal-root')).toContainText(password);
await page.locator('#modal-root .rcx-button--primary').click();
await expect(page.locator('role=banner >> text="Save Your Encryption Password"')).not.toBeVisible();
await poHomeChannel.sidenav.logout();
await page.locator('role=button[name="Login"]').waitFor();
await injectInitialData();
await restoreState(page, Users.admin);
await page.locator('role=banner >> text="Enter your E2E password"').click();
await page.locator('#modal-root input').type(password);
await page.locator('#modal-root .rcx-button--primary').click();
await expect(page.locator('role=banner')).not.toBeVisible();
await storeState(page, Users.admin);
});
test('expect change the e2ee password', async ({ page }) => {
// Change the password to a new one and test it
const newPassword = 'new password';
await restoreState(page, Users.admin);
await poAccountProfile.securityE2EEncryptionSection.click();
await poAccountProfile.securityE2EEncryptionPassword.click();
await poAccountProfile.securityE2EEncryptionPassword.type(newPassword);
await poAccountProfile.securityE2EEncryptionPasswordConfirmation.type(newPassword);
await poAccountProfile.securityE2EEncryptionSavePasswordButton.click();
await poAccountProfile.btnClose.click();
await poHomeChannel.sidenav.logout();
await page.locator('role=button[name="Login"]').waitFor();
await injectInitialData();
await restoreState(page, Users.admin, {except: ['public_key', 'private_key']});
await page.locator('role=banner >> text="Enter your E2E password"').click();
await page.locator('#modal-root input').type(password);
await page.locator('#modal-root .rcx-button--primary').click();
await page.locator('role=banner >> text="Wasn\'t possible to decode your encryption key to be imported."').click();
await page.locator('#modal-root input').type(newPassword);
await page.locator('#modal-root .rcx-button--primary').click();
await expect(page.locator('role=banner')).not.toBeVisible();
});
});
test.describe.serial('e2e-encryption', () => {
let poHomeChannel: HomeChannel;
test.beforeEach(async ({ page, api }) => {
const statusCode = (await api.post('/settings/E2E_Enable', { value: true })).status();
await expect(statusCode).toBe(200);
poHomeChannel = new HomeChannel(page);
await page.goto('/home');
});
test.afterAll(async ({ api }) => {
const statusCode = (await api.post('/settings/E2E_Enable', { value: false })).status();
await expect(statusCode).toBe(200);
});
test('expect create a private channel encrypted and send an encrypted message', async ({ page }) => {
const channelName = faker.datatype.uuid();
await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.type(channelName);
await poHomeChannel.sidenav.checkboxEncryption.check({ force: true });
await poHomeChannel.sidenav.btnCreate.click();
await expect(page).toHaveURL(`/group/${channelName}`);
await expect(poHomeChannel.toastSuccess).toBeVisible();
await poHomeChannel.toastSuccess.locator('button >> i.rcx-icon--name-cross.rcx-icon').click();
await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible();
await poHomeChannel.content.sendMessage('hello world');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world');
await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible();
await poHomeChannel.tabs.kebab.click({ force: true });
await expect(poHomeChannel.tabs.btnE2E).toBeVisible();
await poHomeChannel.tabs.btnE2E.click({ force: true });
await page.waitForTimeout(1000);
await poHomeChannel.content.sendMessage('hello world not encrypted');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world not encrypted');
await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).not.toBeVisible();
await poHomeChannel.tabs.kebab.click({ force: true });
await expect(poHomeChannel.tabs.btnE2E).toBeVisible();
await poHomeChannel.tabs.btnE2E.click({ force: true });
await page.waitForTimeout(1000);
await poHomeChannel.content.sendMessage('hello world encrypted again');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world encrypted again');
await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible();
});
test('expect create a private channel, encrypt it and send an encrypted message', async ({ page }) => {
const channelName = faker.datatype.uuid();
await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.type(channelName);
await poHomeChannel.sidenav.btnCreate.click();
await expect(page).toHaveURL(`/group/${channelName}`);
await expect(poHomeChannel.toastSuccess).toBeVisible();
await poHomeChannel.toastSuccess.locator('button >> i.rcx-icon--name-cross.rcx-icon').click();
await poHomeChannel.tabs.kebab.click({ force: true });
await expect(poHomeChannel.tabs.btnE2E).toBeVisible();
await poHomeChannel.tabs.btnE2E.click({ force: true });
await page.waitForTimeout(1000);
await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible();
await poHomeChannel.content.sendMessage('hello world');
await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world');
await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible();
});
});