fix verification, replace device id/key with SAS verification.
This commit is contained in:
parent
ae5dc9d0b3
commit
9ab1692544
5 changed files with 114 additions and 25 deletions
|
@ -24,28 +24,24 @@ const invite = require('../usecases/invite');
|
||||||
const {receiveMessage} = require('../usecases/timeline');
|
const {receiveMessage} = require('../usecases/timeline');
|
||||||
const {createRoom} = require('../usecases/create-room');
|
const {createRoom} = require('../usecases/create-room');
|
||||||
const changeRoomSettings = require('../usecases/room-settings');
|
const changeRoomSettings = require('../usecases/room-settings');
|
||||||
const {getE2EDeviceFromSettings} = require('../usecases/settings');
|
const {startSasVerifcation, acceptSasVerification} = require('../usecases/verify');
|
||||||
const {verifyDeviceForUser} = require('../usecases/memberlist');
|
const assert = require('assert');
|
||||||
|
|
||||||
module.exports = async function e2eEncryptionScenarios(alice, bob) {
|
module.exports = async function e2eEncryptionScenarios(alice, bob) {
|
||||||
console.log(" creating an e2e encrypted room and join through invite:");
|
console.log(" creating an e2e encrypted room and join through invite:");
|
||||||
const room = "secrets";
|
const room = "secrets";
|
||||||
await createRoom(bob, room);
|
await createRoom(bob, room);
|
||||||
await changeRoomSettings(bob, {encryption: true});
|
await changeRoomSettings(bob, {encryption: true});
|
||||||
|
// await cancelKeyBackup(bob);
|
||||||
await invite(bob, "@alice:localhost");
|
await invite(bob, "@alice:localhost");
|
||||||
await acceptInvite(alice, room);
|
await acceptInvite(alice, room);
|
||||||
const bobDevice = await getE2EDeviceFromSettings(bob);
|
// do sas verifcation
|
||||||
// wait some time for the encryption warning dialog
|
bob.log.step(`starts SAS verification with ${alice.username}`);
|
||||||
// to appear after closing the settings
|
const bobSasPromise = startSasVerifcation(bob, alice.username);
|
||||||
await delay(1000);
|
const aliceSasPromise = acceptSasVerification(alice, bob.username);
|
||||||
await acceptDialogMaybe(bob, "encryption");
|
const [bobSas, aliceSas] = await Promise.all([bobSasPromise, aliceSasPromise]);
|
||||||
const aliceDevice = await getE2EDeviceFromSettings(alice);
|
assert.deepEqual(bobSas, aliceSas);
|
||||||
// wait some time for the encryption warning dialog
|
bob.log.done(`done, (${bobSas.join(", ")}) matches!`);
|
||||||
// to appear after closing the settings
|
|
||||||
await delay(1000);
|
|
||||||
await acceptDialogMaybe(alice, "encryption");
|
|
||||||
await verifyDeviceForUser(bob, "alice", aliceDevice);
|
|
||||||
await verifyDeviceForUser(alice, "bob", bobDevice);
|
|
||||||
const aliceMessage = "Guess what I just heard?!"
|
const aliceMessage = "Guess what I just heard?!"
|
||||||
await sendMessage(alice, aliceMessage);
|
await sendMessage(alice, aliceMessage);
|
||||||
await receiveMessage(bob, {sender: "alice", body: aliceMessage, encrypted: true});
|
await receiveMessage(bob, {sender: "alice", body: aliceMessage, encrypted: true});
|
||||||
|
|
|
@ -16,27 +16,29 @@ limitations under the License.
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
|
async function assertDialog(session, expectedTitle) {
|
||||||
|
const titleElement = await session.waitAndQuery(".mx_Dialog .mx_Dialog_title");
|
||||||
|
const dialogHeader = await session.innerText(titleElement);
|
||||||
|
assert(dialogHeader, expectedTitle);
|
||||||
|
}
|
||||||
|
|
||||||
async function acceptDialog(session, expectedContent) {
|
async function acceptDialog(session, expectedTitle) {
|
||||||
const foundDialog = await acceptDialogMaybe(session, expectedContent);
|
const foundDialog = await acceptDialogMaybe(session, expectedTitle);
|
||||||
if (!foundDialog) {
|
if (!foundDialog) {
|
||||||
throw new Error("could not find a dialog");
|
throw new Error("could not find a dialog");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function acceptDialogMaybe(session, expectedContent) {
|
async function acceptDialogMaybe(session, expectedTitle) {
|
||||||
let dialog = null;
|
let primaryButton = null;
|
||||||
try {
|
try {
|
||||||
dialog = await session.waitAndQuery(".mx_QuestionDialog");
|
primaryButton = await session.waitAndQuery(".mx_Dialog [role=dialog] .mx_Dialog_primary");
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (expectedContent) {
|
if (expectedTitle) {
|
||||||
const contentElement = await dialog.$(".mx_Dialog_content");
|
await assertDialog(session, expectedTitle);
|
||||||
const content = await (await contentElement.getProperty("innerText")).jsonValue();
|
|
||||||
assert.ok(content.indexOf(expectedContent) !== -1);
|
|
||||||
}
|
}
|
||||||
const primaryButton = await dialog.$(".mx_Dialog_primary");
|
|
||||||
await primaryButton.click();
|
await primaryButton.click();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -44,4 +46,5 @@ async function acceptDialogMaybe(session, expectedContent) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
acceptDialog,
|
acceptDialog,
|
||||||
acceptDialogMaybe,
|
acceptDialogMaybe,
|
||||||
|
assertDialog,
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,16 @@ limitations under the License.
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
|
async function openMemberInfo(session, name) {
|
||||||
|
const membersAndNames = await getMembersInMemberlist(session);
|
||||||
|
const matchingLabel = membersAndNames.filter((m) => {
|
||||||
|
return m.displayName === name;
|
||||||
|
}).map((m) => m.label)[0];
|
||||||
|
await matchingLabel.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.openMemberInfo = openMemberInfo;
|
||||||
|
|
||||||
module.exports.verifyDeviceForUser = async function(session, name, expectedDevice) {
|
module.exports.verifyDeviceForUser = async function(session, name, expectedDevice) {
|
||||||
session.log.step(`verifies e2e device for ${name}`);
|
session.log.step(`verifies e2e device for ${name}`);
|
||||||
const membersAndNames = await getMembersInMemberlist(session);
|
const membersAndNames = await getMembersInMemberlist(session);
|
||||||
|
@ -23,8 +33,20 @@ module.exports.verifyDeviceForUser = async function(session, name, expectedDevic
|
||||||
return m.displayName === name;
|
return m.displayName === name;
|
||||||
}).map((m) => m.label)[0];
|
}).map((m) => m.label)[0];
|
||||||
await matchingLabel.click();
|
await matchingLabel.click();
|
||||||
|
// click verify in member info
|
||||||
const firstVerifyButton = await session.waitAndQuery(".mx_MemberDeviceInfo_verify");
|
const firstVerifyButton = await session.waitAndQuery(".mx_MemberDeviceInfo_verify");
|
||||||
await firstVerifyButton.click();
|
await firstVerifyButton.click();
|
||||||
|
// expect "Verify device" dialog and click "Begin Verification"
|
||||||
|
const dialogHeader = await session.innerText(await session.waitAndQuery(".mx_Dialog .mx_Dialog_title"));
|
||||||
|
assert(dialogHeader, "Verify device");
|
||||||
|
const beginVerificationButton = await session.waitAndQuery(".mx_Dialog .mx_Dialog_primary")
|
||||||
|
await beginVerificationButton.click();
|
||||||
|
// get emoji SAS labels
|
||||||
|
const sasLabelElements = await session.waitAndQueryAll(".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label");
|
||||||
|
const sasLabels = await Promise.all(sasLabelElements.map(e => session.innerText(e)));
|
||||||
|
console.log("my sas labels", sasLabels);
|
||||||
|
|
||||||
|
|
||||||
const dialogCodeFields = await session.waitAndQueryAll(".mx_QuestionDialog code");
|
const dialogCodeFields = await session.waitAndQueryAll(".mx_QuestionDialog code");
|
||||||
assert.equal(dialogCodeFields.length, 2);
|
assert.equal(dialogCodeFields.length, 2);
|
||||||
const deviceId = await session.innerText(dialogCodeFields[0]);
|
const deviceId = await session.innerText(dialogCodeFields[0]);
|
||||||
|
|
|
@ -68,7 +68,7 @@ module.exports = async function changeRoomSettings(session, settings) {
|
||||||
const clicked = await setSettingsToggle(session, e2eEncryptionToggle, settings.encryption);
|
const clicked = await setSettingsToggle(session, e2eEncryptionToggle, settings.encryption);
|
||||||
// if enabling, accept beta warning dialog
|
// if enabling, accept beta warning dialog
|
||||||
if (clicked && settings.encryption) {
|
if (clicked && settings.encryption) {
|
||||||
await acceptDialog(session, "encryption");
|
await acceptDialog(session, "Enable encryption?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
68
src/usecases/verify.js
Normal file
68
src/usecases/verify.js
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 New Vector Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const {openMemberInfo} = require("./memberlist");
|
||||||
|
const {assertDialog, acceptDialog} = require("./dialog");
|
||||||
|
|
||||||
|
async function assertVerified(session) {
|
||||||
|
const dialogSubTitle = await session.innerText(await session.waitAndQuery(".mx_Dialog h2"));
|
||||||
|
assert(dialogSubTitle, "Verified!");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startVerification(session, name) {
|
||||||
|
await openMemberInfo(session, name);
|
||||||
|
// click verify in member info
|
||||||
|
const firstVerifyButton = await session.waitAndQuery(".mx_MemberDeviceInfo_verify");
|
||||||
|
await firstVerifyButton.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getSasCodes(session) {
|
||||||
|
const sasLabelElements = await session.waitAndQueryAll(".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label");
|
||||||
|
const sasLabels = await Promise.all(sasLabelElements.map(e => session.innerText(e)));
|
||||||
|
return sasLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.startSasVerifcation = async function(session, name) {
|
||||||
|
await startVerification(session, name);
|
||||||
|
// expect "Verify device" dialog and click "Begin Verification"
|
||||||
|
await assertDialog(session, "Verify device");
|
||||||
|
// click "Begin Verification"
|
||||||
|
await acceptDialog(session);
|
||||||
|
const sasCodes = await getSasCodes(session);
|
||||||
|
// click "Verify"
|
||||||
|
await acceptDialog(session);
|
||||||
|
await assertVerified(session);
|
||||||
|
// click "Got it" when verification is done
|
||||||
|
await acceptDialog(session);
|
||||||
|
return sasCodes;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.acceptSasVerification = async function(session, name) {
|
||||||
|
await assertDialog(session, "Incoming Verification Request");
|
||||||
|
const opponentLabelElement = await session.query(".mx_IncomingSasDialog_opponentProfile h2");
|
||||||
|
const opponentLabel = await session.innerText(opponentLabelElement);
|
||||||
|
assert(opponentLabel, name);
|
||||||
|
// click "Continue" button
|
||||||
|
await acceptDialog(session);
|
||||||
|
const sasCodes = await getSasCodes(session);
|
||||||
|
// click "Verify"
|
||||||
|
await acceptDialog(session);
|
||||||
|
await assertVerified(session);
|
||||||
|
// click "Got it" when verification is done
|
||||||
|
await acceptDialog(session);
|
||||||
|
return sasCodes;
|
||||||
|
};
|
Loading…
Reference in a new issue