bigbluebutton-Github/bigbluebutton-tests/playwright/core/helpers.js

108 lines
4.1 KiB
JavaScript
Raw Normal View History

require('dotenv').config();
const sha1 = require('sha1');
const axios = require('axios');
2023-02-14 21:59:46 +08:00
const { test, expect } = require('@playwright/test');
const xml2js = require('xml2js');
const { runScript } = require('./util');
2023-07-11 03:29:30 +08:00
const { env } = require('node:process');
const parameters = require('./parameters');
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
function apiCallUrl(name, callParams) {
const query = new URLSearchParams(callParams).toString();
2023-02-14 21:59:46 +08:00
const apiCall = `${name}${query}${parameters.secret}`;
const checksum = sha1(apiCall);
const url = `${parameters.server}/${name}?${query}&checksum=${checksum}`;
return url;
}
function apiCall(name, callParams) {
const url = apiCallUrl(name, callParams);
return axios.get(url, { adapter: 'http' }).then(response => xml2js.parseStringPromise(response.data));
}
2023-07-11 03:29:30 +08:00
function createMeetingUrl(params, createParameter, customMeetingId) {
2023-02-14 21:59:46 +08:00
const meetingID = (customMeetingId) ? customMeetingId : `random-${getRandomInt(1000000, 10000000).toString()}`;
const mp = params.moderatorPW;
const ap = params.attendeePW;
2023-02-14 21:59:46 +08:00
const baseQuery = `name=${meetingID}&meetingID=${meetingID}&attendeePW=${ap}&moderatorPW=${mp}`
2021-12-15 01:10:44 +08:00
+ `&allowStartStopRecording=true&autoStartRecording=false&welcome=${params.welcome}`;
2023-07-11 03:29:30 +08:00
const query = createParameter !== undefined ? `${baseQuery}&${createParameter}` : baseQuery;
2023-02-14 21:59:46 +08:00
const apiCall = `create${query}${params.secret}`;
const checksum = sha1(apiCall);
const url = `${params.server}/create?${query}&checksum=${checksum}`;
return url;
}
2023-07-11 03:29:30 +08:00
function createMeetingPromise(params, createParameter, customMeetingId) {
const url = createMeetingUrl(params, createParameter, customMeetingId);
return axios.get(url, { adapter: 'http' });
}
2023-07-11 03:29:30 +08:00
async function createMeeting(params, createParameter, page) {
const promise = createMeetingPromise(params, createParameter);
const response = await promise;
expect(response.status).toEqual(200);
2023-02-14 21:59:46 +08:00
const xmlResponse = await xml2js.parseStringPromise(response.data);
2023-07-11 03:29:30 +08:00
if (env.CONSOLE !== undefined) {
const CONSOLE_strings = env.CONSOLE.split(',').map(opt => opt.trim().toLowerCase());
const CONSOLE_options = {
colorize: CONSOLE_strings.includes('color') || CONSOLE_strings.includes('colour'),
drop_references: CONSOLE_strings.includes('norefs'),
drop_timestamps: CONSOLE_strings.includes('nots'),
line_label: CONSOLE_strings.includes('label') ? this.username + " " : undefined,
noClientLogger: CONSOLE_strings.includes('nocl') || CONSOLE_strings.includes('noclientlogger'),
};
page.on('console', async (msg) => console.log(await console_format(msg, CONSOLE_options)));
}
2023-02-14 21:59:46 +08:00
return xmlResponse.response.meetingID[0];
}
2023-07-11 03:29:30 +08:00
function getJoinURL(meetingID, params, moderator, joinParameter) {
const pw = moderator ? params.moderatorPW : params.attendeePW;
2023-02-14 21:59:46 +08:00
const baseQuery = `fullName=${params.fullName}&meetingID=${meetingID}&password=${pw}`;
2023-07-11 03:29:30 +08:00
const query = joinParameter !== undefined ? `${baseQuery}&${joinParameter}` : baseQuery;
2023-02-14 21:59:46 +08:00
const apiCall = `join${query}${params.secret}`;
const checksum = sha1(apiCall);
return `${params.server}/join?${query}&checksum=${checksum}`;
}
async function checkRootPermission() {
const checkSudo = await runScript('timeout -k 1 1 sudo id', {
handleOutput: (output) => output ? true : false
})
await expect(checkSudo, 'Sudo failed: need to run this test with root permission (can be fixed by running "sudo -v" and entering the password)').toBeTruthy();
}
2022-12-01 21:43:36 +08:00
function linkIssue(issueNumber) {
test.info().annotations.push({
type: 'Issue/PR',
description: `https://github.com/bigbluebutton/bigbluebutton/issues/${issueNumber}`,
});
}
2021-11-27 04:01:41 +08:00
function sleep(time) {
return new Promise((resolve) => {
setTimeout(resolve, time);
});
}
exports.getRandomInt = getRandomInt;
exports.apiCallUrl = apiCallUrl;
exports.apiCall = apiCall;
exports.createMeetingUrl = createMeetingUrl;
exports.createMeetingPromise = createMeetingPromise;
exports.createMeeting = createMeeting;
exports.getJoinURL = getJoinURL;
exports.checkRootPermission = checkRootPermission;
2022-12-01 21:43:36 +08:00
exports.linkIssue = linkIssue;
2021-11-27 04:01:41 +08:00
exports.sleep = sleep;