This commit is contained in:
Bruno Windels 2019-10-09 17:51:50 +02:00
parent 3e971e4880
commit 2d848bba29
25 changed files with 84 additions and 100 deletions

View file

@ -21,10 +21,9 @@ module.exports = class LogBuffer {
const result = eventMapper(arg);
if (reduceAsync) {
result.then((r) => this.buffer += r);
}
else {
} else {
this.buffer += result;
}
});
}
}
};

View file

@ -59,4 +59,4 @@ module.exports = class Logger {
this.muted = false;
return this;
}
}
};

View file

@ -57,13 +57,13 @@ module.exports = class RestSessionCreator {
`-u ${username}`,
`-p ${password}`,
'--no-admin',
this.hsUrl
this.hsUrl,
];
const registerCmd = `./register_new_matrix_user ${registerArgs.join(' ')}`;
const allCmds = [
`cd ${this.synapseSubdir}`,
". ./activate",
registerCmd
registerCmd,
].join(' && ');
await execAsync(allCmds, {cwd: this.cwd, encoding: 'utf-8'});
@ -74,9 +74,9 @@ module.exports = class RestSessionCreator {
"type": "m.login.password",
"identifier": {
"type": "m.id.user",
"user": username
"user": username,
},
"password": password
"password": password,
};
const url = `${this.hsUrl}/_matrix/client/r0/login`;
const responseBody = await request.post({url, json: true, body: requestBody});
@ -88,4 +88,4 @@ module.exports = class RestSessionCreator {
hsUrl: this.hsUrl,
};
}
}
};

View file

@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const request = require('request-promise-native');
const RestRoom = require('./room');
const {approveConsent} = require('./consent');
const Logger = require('../logger');
module.exports = class RestMultiSession {
@ -31,7 +28,7 @@ module.exports = class RestMultiSession {
pop(userName) {
const idx = this.sessions.findIndex((s) => s.userName() === userName);
if(idx === -1) {
if (idx === -1) {
throw new Error(`user ${userName} not found`);
}
const session = this.sessions.splice(idx, 1)[0];
@ -39,7 +36,7 @@ module.exports = class RestMultiSession {
}
async setDisplayName(fn) {
this.log.step("set their display name")
this.log.step("set their display name");
await Promise.all(this.sessions.map(async (s) => {
s.log.mute();
await s.setDisplayName(fn(s));
@ -49,10 +46,10 @@ module.exports = class RestMultiSession {
}
async join(roomIdOrAlias) {
this.log.step(`join ${roomIdOrAlias}`)
this.log.step(`join ${roomIdOrAlias}`);
const rooms = await Promise.all(this.sessions.map(async (s) => {
s.log.mute();
const room = await s.join(roomIdOrAlias);
const room = await s.join(roomIdOrAlias);
s.log.unmute();
return room;
}));
@ -64,7 +61,7 @@ module.exports = class RestMultiSession {
const rooms = this.sessions.map(s => s.room(roomIdOrAlias));
return new RestMultiRoom(rooms, roomIdOrAlias, this.log);
}
}
};
class RestMultiRoom {
constructor(rooms, roomIdOrAlias, log) {
@ -74,7 +71,7 @@ class RestMultiRoom {
}
async talk(message) {
this.log.step(`say "${message}" in ${this.roomIdOrAlias}`)
this.log.step(`say "${message}" in ${this.roomIdOrAlias}`);
await Promise.all(this.rooms.map(async (r) => {
r.log.mute();
await r.talk(message);
@ -84,7 +81,7 @@ class RestMultiRoom {
}
async leave() {
this.log.step(`leave ${this.roomIdOrAlias}`)
this.log.step(`leave ${this.roomIdOrAlias}`);
await Promise.all(this.rooms.map(async (r) => {
r.log.mute();
await r.leave();

View file

@ -25,18 +25,18 @@ module.exports = class RestRoom {
}
async talk(message) {
this.log.step(`says "${message}" in ${this._roomId}`)
this.log.step(`says "${message}" in ${this._roomId}`);
const txId = uuidv4();
await this.session._put(`/rooms/${this._roomId}/send/m.room.message/${txId}`, {
"msgtype": "m.text",
"body": message
"body": message,
});
this.log.done();
return txId;
}
async leave() {
this.log.step(`leaves ${this._roomId}`)
this.log.step(`leaves ${this._roomId}`);
await this.session._post(`/rooms/${this._roomId}/leave`);
this.log.done();
}
@ -44,4 +44,4 @@ module.exports = class RestRoom {
roomId() {
return this._roomId;
}
}
};

View file

@ -43,17 +43,17 @@ module.exports = class RestSession {
this.log.step(`sets their display name to ${displayName}`);
this._displayName = displayName;
await this._put(`/profile/${this._credentials.userId}/displayname`, {
displayname: displayName
displayname: displayName,
});
this.log.done();
}
async join(roomIdOrAlias) {
this.log.step(`joins ${roomIdOrAlias}`);
const {room_id} = await this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`);
const roomId = await this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`).room_id;
this.log.done();
const room = new RestRoom(this, room_id, this.log);
this._rooms[room_id] = room;
const room = new RestRoom(this, roomId, this.log);
this._rooms[roomId] = room;
this._rooms[roomIdOrAlias] = room;
return room;
}
@ -86,9 +86,9 @@ module.exports = class RestSession {
body.topic = options.topic;
}
const {room_id} = await this._post(`/createRoom`, body);
const roomId = await this._post(`/createRoom`, body).room_id;
this.log.done();
return new RestRoom(this, room_id, this.log);
return new RestRoom(this, roomId, this.log);
}
_post(csApiPath, body) {
@ -105,23 +105,22 @@ module.exports = class RestSession {
url: `${this._credentials.hsUrl}/_matrix/client/r0${csApiPath}`,
method,
headers: {
"Authorization": `Bearer ${this._credentials.accessToken}`
"Authorization": `Bearer ${this._credentials.accessToken}`,
},
json: true,
body
body,
});
return responseBody;
} catch(err) {
} catch (err) {
const responseBody = err.response.body;
if (responseBody.errcode === 'M_CONSENT_NOT_GIVEN') {
await approveConsent(responseBody.consent_uri);
return this._request(method, csApiPath, body);
} else if(responseBody && responseBody.error) {
} else if (responseBody && responseBody.error) {
throw new Error(`${method} ${csApiPath}: ${responseBody.error}`);
} else {
throw new Error(`${method} ${csApiPath}: ${err.response.statusCode}`);
}
}
}
}
};

View file

@ -42,7 +42,7 @@ module.exports = async function scenario(createSession, restCreator) {
console.log("create REST users:");
const charlies = await createRestUsers(restCreator);
await lazyLoadingScenarios(alice, bob, charlies);
}
};
async function createRestUsers(restCreator) {
const usernames = range(1, 10).map((i) => `charly-${i}`);

View file

@ -30,7 +30,7 @@ module.exports = async function roomDirectoryScenarios(alice, bob) {
const bobMessage = "hi Alice!";
await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage});
const aliceMessage = "hi Bob, welcome!"
const aliceMessage = "hi Bob, welcome!";
await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage});
}
};

View file

@ -14,10 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const {delay} = require('../util');
const {acceptDialogMaybe} = require('../usecases/dialog');
const join = require('../usecases/join');
const sendMessage = require('../usecases/send-message');
const acceptInvite = require('../usecases/accept-invite');
const invite = require('../usecases/invite');
@ -43,10 +39,10 @@ module.exports = async function e2eEncryptionScenarios(alice, bob) {
const [bobSas, aliceSas] = await Promise.all([bobSasPromise, aliceSasPromise]);
assert.deepEqual(bobSas, aliceSas);
bob.log.done(`done (match for ${bobSas.join(", ")})`);
const aliceMessage = "Guess what I just heard?!"
const aliceMessage = "Guess what I just heard?!";
await sendMessage(alice, aliceMessage);
await receiveMessage(bob, {sender: "alice", body: aliceMessage, encrypted: true});
const bobMessage = "You've got to tell me!";
await sendMessage(bob, bobMessage);
await receiveMessage(alice, {sender: "bob", body: bobMessage, encrypted: true});
}
};

View file

@ -20,12 +20,11 @@ const join = require('../usecases/join');
const sendMessage = require('../usecases/send-message');
const {
checkTimelineContains,
scrollToTimelineTop
scrollToTimelineTop,
} = require('../usecases/timeline');
const {createRoom} = require('../usecases/create-room');
const {getMembersInMemberlist} = require('../usecases/memberlist');
const changeRoomSettings = require('../usecases/room-settings');
const {enableLazyLoading} = require('../usecases/settings');
const assert = require('assert');
module.exports = async function lazyLoadingScenarios(alice, bob, charlies) {
@ -43,7 +42,7 @@ module.exports = async function lazyLoadingScenarios(alice, bob, charlies) {
await delay(1000);
await checkMemberListLacksCharlies(alice, charlies);
await checkMemberListLacksCharlies(bob, charlies);
}
};
const room = "Lazy Loading Test";
const alias = "#lltest:localhost";
@ -60,7 +59,7 @@ async function setupRoomWithBobAliceAndCharlies(alice, bob, charlies) {
await charlyMembers.talk(charlyMsg1);
await charlyMembers.talk(charlyMsg2);
bob.log.step("sends 20 messages").mute();
for(let i = 20; i >= 1; --i) {
for (let i = 20; i >= 1; --i) {
await sendMessage(bob, `I will only say this ${i} time(s)!`);
}
bob.log.unmute().done();
@ -112,7 +111,7 @@ async function joinCharliesWhileAliceIsOffline(alice, charly6to10) {
const members6to10 = await charly6to10.join(alias);
const member6 = members6to10.rooms[0];
member6.log.step("sends 20 messages").mute();
for(let i = 20; i >= 1; --i) {
for (let i = 20; i >= 1; --i) {
await member6.talk("where is charly?");
}
member6.log.unmute().done();

View file

@ -42,7 +42,7 @@ module.exports = class RiotSession {
const page = await browser.newPage();
await page.setViewport({
width: 1280,
height: 800
height: 800,
});
if (throttleCpuFactor !== 1) {
const client = await page.target().createCDPSession();
@ -55,8 +55,8 @@ module.exports = class RiotSession {
async tryGetInnertext(selector) {
const field = await this.page.$(selector);
if (field != null) {
const text_handle = await field.getProperty('innerText');
return await text_handle.jsonValue();
const textHandle = await field.getProperty('innerText');
return await textHandle.jsonValue();
}
return null;
}
@ -70,7 +70,7 @@ module.exports = class RiotSession {
return this.getElementProperty(field, 'innerText');
}
getOuterHTML(element_handle) {
getOuterHTML(field) {
return this.getElementProperty(field, 'outerHTML');
}
@ -97,12 +97,12 @@ module.exports = class RiotSession {
return {
logs() {
return buffer;
}
}
},
};
}
async printElements(label, elements) {
console.log(label, await Promise.all(elements.map(getOuterHTML)));
console.log(label, await Promise.all(elements.map(this.getOuterHTML)));
}
async replaceInputText(input, text) {
@ -210,7 +210,7 @@ module.exports = class RiotSession {
async poll(callback, interval = 100) {
const timeout = DEFAULT_TIMEOUT;
let waited = 0;
while(waited < timeout) {
while (waited < timeout) {
await this.delay(interval);
waited += interval;
if (await callback()) {
@ -219,4 +219,4 @@ module.exports = class RiotSession {
}
return false;
}
}
};

View file

@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
const {acceptDialogMaybe} = require('./dialog');
module.exports = async function acceptInvite(session, name) {
session.log.step(`accepts "${name}" invite`);
//TODO: brittle selector
@ -35,4 +32,4 @@ module.exports = async function acceptInvite(session, name) {
await acceptInvitationLink.click();
session.log.done();
}
};

View file

@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
async function openRoomDirectory(session) {
const roomDirectoryButton = await session.query('.mx_LeftPanel_explore .mx_AccessibleButton');
await roomDirectoryButton.click();

View file

@ -33,7 +33,7 @@ async function acceptDialogMaybe(session, expectedTitle) {
let primaryButton = null;
try {
primaryButton = await session.query(".mx_Dialog .mx_Dialog_primary");
} catch(err) {
} catch (err) {
return false;
}
if (expectedTitle) {

View file

@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
module.exports = async function invite(session, userId) {
session.log.step(`invites "${userId}" to room`);
await session.delay(1000);
@ -27,4 +25,4 @@ module.exports = async function invite(session, userId) {
const confirmButton = await session.query(".mx_Dialog_primary");
await confirmButton.click();
session.log.done();
}
};

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
const {openRoomDirectory} = require('./create-room');
module.exports = async function join(session, roomName) {
@ -27,4 +26,4 @@ module.exports = async function join(session, roomName) {
await joinFirstLink.click();
await session.query('.mx_MessageComposer');
session.log.done();
}
};

View file

@ -22,7 +22,7 @@ async function openMemberInfo(session, name) {
return m.displayName === name;
}).map((m) => m.label)[0];
await matchingLabel.click();
};
}
module.exports.openMemberInfo = openMemberInfo;
@ -39,10 +39,11 @@ module.exports.verifyDeviceForUser = async function(session, name, expectedDevic
// expect "Verify device" dialog and click "Begin Verification"
const dialogHeader = await session.innerText(await session.query(".mx_Dialog .mx_Dialog_title"));
assert(dialogHeader, "Verify device");
const beginVerificationButton = await session.query(".mx_Dialog .mx_Dialog_primary")
const beginVerificationButton = await session.query(".mx_Dialog .mx_Dialog_primary");
await beginVerificationButton.click();
// get emoji SAS labels
const sasLabelElements = await session.queryAll(".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label");
const sasLabelElements = await session.queryAll(
".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);
@ -58,7 +59,7 @@ module.exports.verifyDeviceForUser = async function(session, name, expectedDevic
const closeMemberInfo = await session.query(".mx_MemberInfo_cancel");
await closeMemberInfo.click();
session.log.done();
}
};
async function getMembersInMemberlist(session) {
const memberNameElements = await session.queryAll(".mx_MemberList .mx_EntityTile_name");

View file

@ -96,4 +96,4 @@ module.exports = async function changeRoomSettings(session, settings) {
await closeButton.click();
session.log.endGroup();
}
};

View file

@ -31,4 +31,4 @@ module.exports = async function sendMessage(session, message) {
// wait for the message to appear sent
await session.query(".mx_EventTile_last:not(.mx_EventTile_sending)");
session.log.done();
}
};

View file

@ -22,7 +22,8 @@ async function openSettings(session, section) {
const settingsItem = await session.query(".mx_TopLeftMenu_icon_settings");
await settingsItem.click();
if (section) {
const sectionButton = await session.query(`.mx_UserSettingsDialog .mx_TabbedView_tabLabels .mx_UserSettingsDialog_${section}Icon`);
const sectionButton = await session.query(
`.mx_UserSettingsDialog .mx_TabbedView_tabLabels .mx_UserSettingsDialog_${section}Icon`);
await sectionButton.click();
}
}
@ -37,7 +38,7 @@ module.exports.enableLazyLoading = async function(session) {
const closeButton = await session.query(".mx_RoomHeader_cancelButton");
await closeButton.click();
session.log.done();
}
};
module.exports.getE2EDeviceFromSettings = async function(session) {
session.log.step(`gets e2e device/key from settings`);
@ -50,4 +51,4 @@ module.exports.getE2EDeviceFromSettings = async function(session) {
await closeButton.click();
session.log.done();
return {id, key};
}
};

View file

@ -60,8 +60,8 @@ module.exports = async function signup(session, username, password, homeserver)
// Password validation is async, wait for it to complete before submit
await session.query(".mx_Field_valid #mx_RegistrationForm_password");
//check no errors
const error_text = await session.tryGetInnertext('.mx_Login_error');
assert.strictEqual(!!error_text, false);
const errorText = await session.tryGetInnertext('.mx_Login_error');
assert.strictEqual(!!errorText, false);
//submit form
//await page.screenshot({path: "beforesubmit.png", fullPage: true});
await registerButton.click();
@ -87,4 +87,4 @@ module.exports = async function signup(session, username, password, homeserver)
});
assert(foundHomeUrl);
session.log.done();
}
};

View file

@ -36,11 +36,11 @@ module.exports.scrollToTimelineTop = async function(session) {
} else {
await new Promise((resolve) => setTimeout(resolve, 50));
}
} while (!timedOut)
} while (!timedOut);
});
})
});
session.log.done();
}
};
module.exports.receiveMessage = async function(session, expectedMessage) {
session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`);
@ -56,7 +56,7 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
await session.poll(async () => {
try {
lastMessage = await getLastMessage();
} catch(err) {
} catch (err) {
return false;
}
// stop polling when found the expected message
@ -66,10 +66,10 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
});
assertMessage(lastMessage, expectedMessage);
session.log.done();
}
};
module.exports.checkTimelineContains = async function (session, expectedMessages, sendersDescription) {
module.exports.checkTimelineContains = async function(session, expectedMessages, sendersDescription) {
session.log.step(`checks timeline contains ${expectedMessages.length} ` +
`given messages${sendersDescription ? ` from ${sendersDescription}`:""}`);
const eventTiles = await getAllEventTiles(session);
@ -94,14 +94,14 @@ module.exports.checkTimelineContains = async function (session, expectedMessages
});
try {
assertMessage(foundMessage, expectedMessage);
} catch(err) {
} catch (err) {
console.log("timelineMessages", timelineMessages);
throw err;
}
});
session.log.done();
}
};
function assertMessage(foundMessage, expectedMessage) {
assert(foundMessage, `message ${JSON.stringify(expectedMessage)} not found in timeline`);

View file

@ -31,7 +31,8 @@ async function startVerification(session, name) {
}
async function getSasCodes(session) {
const sasLabelElements = await session.queryAll(".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label");
const sasLabelElements = await session.queryAll(
".mx_VerificationShowSas .mx_VerificationShowSas_emojiSas .mx_VerificationShowSas_emojiSas_label");
const sasLabels = await Promise.all(sasLabelElements.map(e => session.innerText(e)));
return sasLabels;
}

View file

@ -20,8 +20,8 @@ module.exports.range = function(start, amount, step = 1) {
r.push(start + (i * step));
}
return r;
}
};
module.exports.delay = function(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
};

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const assert = require('assert');
const RiotSession = require('./src/session');
const scenario = require('./src/scenario');
const RestSessionCreator = require('./src/rest/creator');
@ -35,7 +34,7 @@ program
const hsUrl = 'http://localhost:5005';
async function runTests() {
let sessions = [];
const sessions = [];
const options = {
slowMo: program.slowMo ? 20 : undefined,
devtools: program.devTools,
@ -54,7 +53,7 @@ async function runTests() {
const restCreator = new RestSessionCreator(
'synapse/installations/consent/env/bin',
hsUrl,
__dirname
__dirname,
);
async function createSession(username) {
@ -66,7 +65,7 @@ async function runTests() {
let failure = false;
try {
await scenario(createSession, restCreator);
} catch(err) {
} catch (err) {
failure = true;
console.log('failure: ', err);
if (program.logDirectory) {
@ -90,15 +89,15 @@ async function runTests() {
}
async function writeLogs(sessions, dir) {
let logs = "";
for(let i = 0; i < sessions.length; ++i) {
const logs = "";
for (let i = 0; i < sessions.length; ++i) {
const session = sessions[i];
const userLogDir = `${dir}/${session.username}`;
fs.mkdirSync(userLogDir);
const consoleLogName = `${userLogDir}/console.log`;
const networkLogName = `${userLogDir}/network.log`;
const appHtmlName = `${userLogDir}/app.html`;
documentHtml = await session.page.content();
const documentHtml = await session.page.content();
fs.writeFileSync(appHtmlName, documentHtml);
fs.writeFileSync(networkLogName, session.networkLogs());
fs.writeFileSync(consoleLogName, session.consoleLogs());