2018-08-07 18:58:58 +03:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
2018-08-14 13:53:16 +03:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2018-08-07 18:58:58 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-09-12 19:38:42 +03:00
|
|
|
const {delay, range} = require('./util');
|
2018-09-12 19:40:25 +03:00
|
|
|
const {acceptDialogMaybe} = require('./usecases/dialog');
|
|
|
|
const signup = require('./usecases/signup');
|
|
|
|
const join = require('./usecases/join');
|
|
|
|
const sendMessage = require('./usecases/send-message');
|
|
|
|
const acceptInvite = require('./usecases/accept-invite');
|
|
|
|
const invite = require('./usecases/invite');
|
2018-09-12 15:49:48 +03:00
|
|
|
const {
|
|
|
|
receiveMessage,
|
|
|
|
checkTimelineContains,
|
|
|
|
scrollToTimelineTop
|
2018-09-12 19:40:25 +03:00
|
|
|
} = require('./usecases/timeline');
|
|
|
|
const createRoom = require('./usecases/create-room');
|
|
|
|
const changeRoomSettings = require('./usecases/room-settings');
|
|
|
|
const acceptServerNoticesInviteAndConsent = require('./usecases/server-notices-consent');
|
|
|
|
const {enableLazyLoading, getE2EDeviceFromSettings} = require('./usecases/settings');
|
|
|
|
const verifyDeviceForUser = require("./usecases/verify-device");
|
2018-08-07 18:58:58 +03:00
|
|
|
|
2018-09-11 19:32:32 +03:00
|
|
|
module.exports = async function scenario(createSession, restCreator) {
|
2018-08-14 13:53:16 +03:00
|
|
|
async function createUser(username) {
|
|
|
|
const session = await createSession(username);
|
2018-09-11 19:28:50 +03:00
|
|
|
await signup(session, session.username, 'testtest', session.hsUrl);
|
2018-08-14 13:53:16 +03:00
|
|
|
await acceptServerNoticesInviteAndConsent(session);
|
|
|
|
return session;
|
|
|
|
}
|
2018-08-07 18:58:58 +03:00
|
|
|
|
2018-08-14 13:53:16 +03:00
|
|
|
const alice = await createUser("alice");
|
|
|
|
const bob = await createUser("bob");
|
2018-09-11 19:32:32 +03:00
|
|
|
const charlies = await createRestUsers(restCreator);
|
2018-08-08 13:35:50 +03:00
|
|
|
|
2018-09-12 15:53:19 +03:00
|
|
|
await createDirectoryRoomAndTalk(alice, bob);
|
|
|
|
await createE2ERoomAndTalk(alice, bob);
|
2018-09-11 19:32:32 +03:00
|
|
|
await aLazyLoadingTest(alice, bob, charlies);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function createRestUsers(restCreator) {
|
|
|
|
const usernames = range(1, 10).map((i) => `charly-${i}`);
|
|
|
|
const charlies = await restCreator.createSessionRange(usernames, 'testtest');
|
|
|
|
await charlies.setDisplayName((s) => `Charly #${s.userName().split('-')[1]}`);
|
|
|
|
return charlies;
|
2018-08-08 13:35:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async function createDirectoryRoomAndTalk(alice, bob) {
|
2018-08-14 13:53:16 +03:00
|
|
|
console.log(" creating a public room and join through directory:");
|
|
|
|
const room = 'test';
|
|
|
|
await createRoom(alice, room);
|
|
|
|
await changeRoomSettings(alice, {directory: true, visibility: "public_no_guests"});
|
|
|
|
await join(bob, room);
|
|
|
|
const bobMessage = "hi Alice!";
|
|
|
|
await sendMessage(bob, bobMessage);
|
|
|
|
await receiveMessage(alice, {sender: "bob", body: bobMessage});
|
|
|
|
const aliceMessage = "hi Bob, welcome!"
|
|
|
|
await sendMessage(alice, aliceMessage);
|
|
|
|
await receiveMessage(bob, {sender: "alice", body: aliceMessage});
|
2018-08-08 16:22:54 +03:00
|
|
|
}
|
2018-08-08 13:35:50 +03:00
|
|
|
|
2018-08-08 13:42:34 +03:00
|
|
|
async function createE2ERoomAndTalk(alice, bob) {
|
2018-08-14 13:53:16 +03:00
|
|
|
console.log(" creating an e2e encrypted room and join through invite:");
|
|
|
|
const room = "secrets";
|
|
|
|
await createRoom(bob, room);
|
|
|
|
await changeRoomSettings(bob, {encryption: true});
|
|
|
|
await invite(bob, "@alice:localhost");
|
|
|
|
await acceptInvite(alice, room);
|
|
|
|
const bobDevice = await getE2EDeviceFromSettings(bob);
|
|
|
|
// wait some time for the encryption warning dialog
|
|
|
|
// to appear after closing the settings
|
2018-09-12 19:38:42 +03:00
|
|
|
await delay(1000);
|
2018-08-23 11:04:06 +03:00
|
|
|
await acceptDialogMaybe(bob, "encryption");
|
2018-08-14 13:53:16 +03:00
|
|
|
const aliceDevice = await getE2EDeviceFromSettings(alice);
|
|
|
|
// wait some time for the encryption warning dialog
|
|
|
|
// to appear after closing the settings
|
2018-09-12 19:38:42 +03:00
|
|
|
await delay(1000);
|
2018-08-23 11:04:06 +03:00
|
|
|
await acceptDialogMaybe(alice, "encryption");
|
2018-08-14 13:53:16 +03:00
|
|
|
await verifyDeviceForUser(bob, "alice", aliceDevice);
|
|
|
|
await verifyDeviceForUser(alice, "bob", bobDevice);
|
|
|
|
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});
|
2018-08-08 16:22:54 +03:00
|
|
|
}
|
2018-09-11 19:28:50 +03:00
|
|
|
|
2018-09-11 19:32:32 +03:00
|
|
|
async function aLazyLoadingTest(alice, bob, charlies) {
|
2018-09-12 15:53:19 +03:00
|
|
|
console.log(" creating a room for lazy loading member scenarios:");
|
2018-09-11 19:28:50 +03:00
|
|
|
await enableLazyLoading(alice);
|
2018-09-11 19:32:32 +03:00
|
|
|
const room = "Lazy Loading Test";
|
|
|
|
const alias = "#lltest:localhost";
|
2018-09-12 15:53:19 +03:00
|
|
|
const charlyMsg1 = "hi bob!";
|
|
|
|
const charlyMsg2 = "how's it going??";
|
2018-09-11 19:32:32 +03:00
|
|
|
await createRoom(bob, room);
|
|
|
|
await changeRoomSettings(bob, {directory: true, visibility: "public_no_guests", alias});
|
|
|
|
// wait for alias to be set by server after clicking "save"
|
2018-09-12 15:53:19 +03:00
|
|
|
// so the charlies can join it.
|
2018-09-11 19:32:32 +03:00
|
|
|
await bob.delay(500);
|
2018-09-12 15:53:19 +03:00
|
|
|
const charlyMembers = await charlies.join(alias);
|
|
|
|
await charlyMembers.talk(charlyMsg1);
|
|
|
|
await charlyMembers.talk(charlyMsg2);
|
2018-09-12 10:47:57 +03:00
|
|
|
bob.log.step("sends 20 messages").mute();
|
2018-09-11 19:32:32 +03:00
|
|
|
for(let i = 20; i >= 1; --i) {
|
|
|
|
await sendMessage(bob, `I will only say this ${i} time(s)!`);
|
|
|
|
}
|
2018-09-12 10:47:57 +03:00
|
|
|
bob.log.unmute().done();
|
2018-09-12 15:53:19 +03:00
|
|
|
await join(alice, alias);
|
|
|
|
await scrollToTimelineTop(alice);
|
|
|
|
//alice should see 2 messages from every charly with
|
|
|
|
//the correct display name
|
|
|
|
const expectedMessages = [charlyMsg1, charlyMsg2].reduce((messages, msgText) => {
|
|
|
|
return charlies.sessions.reduce((messages, charly) => {
|
|
|
|
return messages.concat({
|
|
|
|
sender: charly.displayName(),
|
|
|
|
body: msgText,
|
|
|
|
});
|
|
|
|
}, messages);
|
|
|
|
}, []);
|
|
|
|
await checkTimelineContains(alice, expectedMessages, "Charly #1-10");
|
2018-09-11 19:28:50 +03:00
|
|
|
}
|