element-web/src/scenario.js

72 lines
2.8 KiB
JavaScript
Raw Normal View History

/*
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 signup = require('./tests/signup');
const join = require('./tests/join');
const sendMessage = require('./tests/send-message');
2018-08-08 13:22:54 +00:00
const acceptInvite = require('./tests/accept-invite');
const invite = require('./tests/invite');
const receiveMessage = require('./tests/receive-message');
const createRoom = require('./tests/create-room');
const changeRoomSettings = require('./tests/room-settings');
const acceptServerNoticesInviteAndConsent = require('./tests/server-notices-consent');
2018-08-08 13:22:54 +00:00
const getE2EDeviceFromSettings = require('./tests/e2e-device');
const verifyDeviceForUser = require("./tests/verify-device");
module.exports = async function scenario(createSession) {
async function createUser(username) {
const session = await createSession(username);
await signup(session, session.username, 'testtest');
const noticesName = "Server Notices";
await acceptServerNoticesInviteAndConsent(session, noticesName);
return session;
}
const alice = await createUser("alice");
const bob = await createUser("bob");
2018-08-08 10:35:50 +00:00
await createDirectoryRoomAndTalk(alice, bob);
2018-08-08 13:22:54 +00:00
await createE2ERoomAndTalk(alice, bob);
2018-08-08 10:35:50 +00:00
}
async function createDirectoryRoomAndTalk(alice, bob) {
console.log(" creating a public room and join through directory:");
const room = 'test';
2018-08-08 10:42:34 +00:00
const message = "hi Alice!";
await createRoom(alice, room);
await changeRoomSettings(alice, {directory: true, visibility: "public_no_guests"});
await join(bob, room);
2018-08-08 10:42:34 +00:00
await sendMessage(bob, message);
await receiveMessage(alice, {sender: "bob", body: message});
2018-08-08 13:22:54 +00:00
}
2018-08-08 10:35:50 +00:00
2018-08-08 10:42:34 +00:00
async function createE2ERoomAndTalk(alice, bob) {
2018-08-08 13:22:54 +00:00
console.log(" creating an e2e encrypted room and join through invite:");
const room = "secrets";
const message = "Guess what I just heard?!"
await createRoom(bob, room);
2018-08-08 10:42:34 +00:00
await changeRoomSettings(bob, {encryption: true});
await invite(bob, "@alice:localhost");
2018-08-08 13:22:54 +00:00
await acceptInvite(alice, room);
const bobDevice = await getE2EDeviceFromSettings(bob);
const aliceDevice = await getE2EDeviceFromSettings(alice);
await verifyDeviceForUser(bob, "alice", aliceDevice);
await verifyDeviceForUser(alice, "bob", bobDevice);
await sendMessage(alice, message);
await receiveMessage(bob, {sender: "alice", body: message, encrypted: true});
}