Skip to content

Commit 5eddbd3

Browse files
committed
Ad e2ee actions
1 parent a5d8009 commit 5eddbd3

File tree

2 files changed

+116
-65
lines changed

2 files changed

+116
-65
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/// <reference types='cypress' />
18+
19+
export function startCrossSigning(data: any): string {
20+
if (data?.["userId"]) {
21+
cy.get(".mx_RightPanel_roomSummaryButton").click();
22+
cy.get(".mx_RoomSummaryCard_icon_people").click();
23+
cy.get(".mx_MemberList_query").type(data["userId"]);
24+
cy.get(".mx_MemberList_wrapper .mx_EntityTile").click();
25+
cy.get(".mx_UserInfo_verifyButton").click();
26+
cy.get(".mx_UserInfo_startVerification").click();
27+
} else {
28+
cy.gotoAllSettings();
29+
cy.get("[data-testid='settings-tab-USER_SECURITY_TAB']").click();
30+
cy.contains("Verify").first().click();
31+
cy.contains("Verify with another device").click();
32+
}
33+
return 'started_crosssign';
34+
}
35+
36+
export function acceptCrossSigningRequest(): string {
37+
// Can we please tag some buttons :)
38+
// Click 'Verify' when it comes up
39+
cy.get('.mx_Toast_buttons > .mx_AccessibleButton_kind_primary').click();
40+
// Click to move to emoji verification
41+
cy.wait(1000).then(() => {
42+
// Choose whichever exists
43+
Cypress.$(".mx_VerificationPanel_verifyByEmojiButton")?.trigger("click");
44+
Cypress.$('.mx_VerificationPanel_QRPhase_startOption > .mx_AccessibleButton')?.trigger("click");
45+
});
46+
return 'accepted_crosssign';
47+
}
48+
49+
export function verifyCrossSigningEmoji(): string {
50+
cy.get('.mx_VerificationShowSas_buttonRow > .mx_AccessibleButton_kind_primary').click();
51+
cy.get('.mx_UserInfo_container > .mx_AccessibleButton').click();
52+
return 'verified_crosssign';
53+
}
54+
55+
export function verifyDeviceIsTrusted(): string {
56+
cy.gotoAllSettings();
57+
cy.get("[data-testid='settings-tab-USER_SECURITY_TAB']").click();
58+
// For now, we only care if there are any verified devices
59+
// Eventually, we'd want to check if a device is verified by name
60+
cy.contains(/^Verified devices$/);
61+
cy.get(".mx_DevicesPanel_device").children();
62+
return "verified";
63+
}
64+
65+
export function enableKeyBackup(data: any): string {
66+
cy.gotoAllSettings();
67+
cy.get("[data-testid='settings-tab-USER_SECURITY_TAB']").click();
68+
cy.get(".mx_SecureBackupPanel_buttonRow").contains("Set up").click();
69+
cy.get(".mx_CreateSecretStorageDialog_optionIcon_securePhrase").click();
70+
cy.get(".mx_CreateSecretStorageDialog [data-testid='dialog-primary-button']").click();
71+
const password = data["key_backup_passphrase"];
72+
if (!password) {
73+
throw new Error("'key_backup_passphrase' not in data for action 'enable_dehydrated_device'");
74+
}
75+
cy.get(".mx_CreateSecretStorageDialog_passPhraseContainer input[type='password']").type(password);
76+
cy.get("[data-testid='dialog-primary-button']").click();
77+
// confirm the password again
78+
cy.get(".mx_CreateSecretStorageDialog_passPhraseContainer input[type='password']").type(password);
79+
cy.get("[data-testid='dialog-primary-button']").click();
80+
// Continue to next screen
81+
cy.get("[data-testid='dialog-primary-button']").click();
82+
// Classic flakiness fix
83+
cy.wait(500);
84+
cy.get(".mx_CreateSecretStorageDialog").contains("Continue").click();
85+
return "key_backup_enabled";
86+
}
87+
88+
export function enableDehydratedDevice(data: any): string {
89+
cy.gotoAllSettings();
90+
cy.get("[data-testid='settings-tab-USER_LABS_TAB']").click();
91+
cy.get("[aria-label='Offline encrypted messaging using dehydrated devices']").click();
92+
cy.get(".mx_Dialog_cancelButton").click();
93+
enableKeyBackup(data);
94+
return "enabled_dehydrated_device";
95+
}

cypress/e2e/trafficlight/trafficlight.spec.ts

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ limitations under the License.
1919
/// <reference types='cypress' />
2020

2121
import { login, logout, register } from "./actions/auth";
22+
import {
23+
acceptCrossSigningRequest,
24+
enableDehydratedDevice,
25+
enableKeyBackup,
26+
startCrossSigning,
27+
verifyCrossSigningEmoji,
28+
verifyDeviceIsTrusted,
29+
} from "./actions/e2e";
2230

2331
type JSONValue =
2432
| string
@@ -72,50 +80,28 @@ function recurse() {
7280

7381
function runAction(action: string, data: JSONValue): string | undefined {
7482
switch (action) {
83+
// Auth
7584
case 'register':
7685
return register(data);
7786
case 'login':
7887
return login(data);
79-
case "logout": {
88+
case "logout":
8089
return logout();
81-
}
90+
91+
// E2E
8292
case 'start_crosssign':
83-
if (data?.["userId"]) {
84-
cy.get(".mx_RightPanel_roomSummaryButton").click();
85-
cy.get(".mx_RoomSummaryCard_icon_people").click();
86-
cy.get(".mx_MemberList_query").type(data["userId"]);
87-
cy.get(".mx_MemberList_wrapper .mx_EntityTile").click();
88-
cy.get(".mx_UserInfo_verifyButton").click();
89-
cy.get(".mx_UserInfo_startVerification").click();
90-
} else {
91-
cy.gotoAllSettings();
92-
cy.get("[data-testid='settings-tab-USER_SECURITY_TAB']").click();
93-
cy.contains("Verify").first().click();
94-
cy.contains("Verify with another device").click();
95-
}
96-
return 'started_crosssign';
93+
return startCrossSigning(data);
9794
case 'accept_crosssign':
98-
// Can we please tag some buttons :)
99-
// Click 'Verify' when it comes up
100-
cy.get('.mx_Toast_buttons > .mx_AccessibleButton_kind_primary').click();
101-
// Click to move to emoji verification
102-
cy.wait(1000).then(() => {
103-
// Choose whichever exists
104-
Cypress.$(".mx_VerificationPanel_verifyByEmojiButton")?.trigger("click");
105-
Cypress.$('.mx_VerificationPanel_QRPhase_startOption > .mx_AccessibleButton')?.trigger("click");
106-
});
107-
return 'accepted_crosssign';
95+
return acceptCrossSigningRequest();
10896
case 'verify_crosssign_emoji':
109-
cy.get('.mx_VerificationShowSas_buttonRow > .mx_AccessibleButton_kind_primary').click();
110-
cy.get('.mx_UserInfo_container > .mx_AccessibleButton').click();
111-
return 'verified_crosssign';
97+
return verifyCrossSigningEmoji();
11298
case "verify_trusted_device":
113-
cy.gotoAllSettings();
114-
cy.get("[data-testid='settings-tab-USER_SECURITY_TAB']").click();
115-
// For now, we only care if there are any verified devices
116-
cy.contains(/^Verified devices$/);
117-
cy.get(".mx_DevicesPanel_device").children();
118-
return "verified";
99+
return verifyDeviceIsTrusted();
100+
case "enable_dehydrated_device":
101+
return enableDehydratedDevice(data);
102+
case "enable_key_backup":
103+
return enableKeyBackup(data);
104+
119105
case 'idle':
120106
cy.wait(5000);
121107
break;
@@ -156,36 +142,6 @@ function runAction(action: string, data: JSONValue): string | undefined {
156142
cy.get(".mx_Dialog_cancelButton").click();
157143
cy.get("[data-test-id=base-card-close-button]").click();
158144
return "changed";
159-
case "enable_dehydrated_device": {
160-
cy.gotoAllSettings();
161-
cy.get("[data-testid='settings-tab-USER_LABS_TAB']").click();
162-
cy.get("[aria-label='Offline encrypted messaging using dehydrated devices']").click();
163-
cy.get(".mx_Dialog_cancelButton").click();
164-
runAction("enable_key_backup", data);
165-
return "enabled_dehydrated_device";
166-
}
167-
case "enable_key_backup": {
168-
cy.gotoAllSettings();
169-
cy.get("[data-testid='settings-tab-USER_SECURITY_TAB']").click();
170-
cy.get(".mx_SecureBackupPanel_buttonRow").contains("Set up").click();
171-
cy.get(".mx_CreateSecretStorageDialog_optionIcon_securePhrase").click();
172-
cy.get(".mx_CreateSecretStorageDialog [data-testid='dialog-primary-button']").click();
173-
const password = data["key_backup_passphrase"];
174-
if (!password) {
175-
throw new Error("'key_backup_passphrase' not in data for action 'enable_dehydrated_device'");
176-
}
177-
cy.get(".mx_CreateSecretStorageDialog_passPhraseContainer input[type='password']").type(password);
178-
cy.get("[data-testid='dialog-primary-button']").click();
179-
// confirm the password again
180-
cy.get(".mx_CreateSecretStorageDialog_passPhraseContainer input[type='password']").type(password);
181-
cy.get("[data-testid='dialog-primary-button']").click();
182-
// Continue to next screen
183-
cy.get("[data-testid='dialog-primary-button']").click();
184-
// Classic flakiness fix
185-
cy.wait(500);
186-
cy.get(".mx_CreateSecretStorageDialog").contains("Continue").click();
187-
return "key_backup_enabled";
188-
}
189145
case "invite_user": {
190146
cy.get(".mx_RightPanel_roomSummaryButton").click();
191147
cy.get(".mx_RoomSummaryCard_icon_people").click();

0 commit comments

Comments
 (0)