Skip to content

Commit

Permalink
test: update playwright tests to support sha256 and sha512 algorithms (
Browse files Browse the repository at this point in the history
…#19725)

* update to support sha256 and sha512 algorithms

* Update bigbluebutton-tests/playwright/.env.template

Co-authored-by: Anton Barboza de Sá <antonbsa.bck@gmail.com>

---------

Co-authored-by: Anton Georgiev <antobinary@users.noreply.github.com>
Co-authored-by: Anton Barboza de Sá <antonbsa.bck@gmail.com>
  • Loading branch information
3 people committed Mar 7, 2024
1 parent 2fec707 commit fdbab50
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 48 deletions.
1 change: 1 addition & 0 deletions bigbluebutton-tests/playwright/.env.template
@@ -1,6 +1,7 @@
# meeting credentials
BBB_URL="" # https://DOMAIN_NAME/bigbluebutton/api
BBB_SECRET=""
CHECKSUM="" # (sha1 | sha256 | sha512) Force a specific checksum algorithm. Useful for when the secret length is not a sha algorithm length

DEBUG_MODE="" # (true / false|empty) Enable or disable debug features
TIMEOUT_MULTIPLIER=1 # (number / empty) Apply a multiplier on default timeouts - depending the server strength (not recommended to use greater values than 3)
26 changes: 22 additions & 4 deletions bigbluebutton-tests/playwright/core/helpers.js
@@ -1,5 +1,5 @@
require('dotenv').config();
const sha1 = require('sha1');
const sha = require('sha.js');
const axios = require('axios');
const { test, expect } = require('@playwright/test');
const xml2js = require('xml2js');
Expand All @@ -11,6 +11,24 @@ const { format } = require('node:util');
const chalk = require('chalk');
const parameters = require('./parameters');

function getChecksum(text, secret) {
let algorithm = (process.env.CHECKSUM || '').toLowerCase();
if (!['sha1', 'sha256', 'sha512'].includes(algorithm)) {
switch (secret.length) {
case 128:
algorithm = 'sha512';
break;
case 64:
algorithm = 'sha256';
break;
case 40:
default:
algorithm = 'sha1'
}
}
return sha(algorithm).update(text).digest('hex');
}

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
Expand All @@ -20,7 +38,7 @@ function getRandomInt(min, max) {
function apiCallUrl(name, callParams) {
const query = new URLSearchParams(callParams).toString();
const apiCall = `${name}${query}${parameters.secret}`;
const checksum = sha1(apiCall);
const checksum = getChecksum(apiCall, parameters.secret);
const url = `${parameters.server}/${name}?${query}&checksum=${checksum}`;
return url;
}
Expand All @@ -38,7 +56,7 @@ function createMeetingUrl(params, createParameter, customMeetingId) {
+ `&allowStartStopRecording=true&autoStartRecording=false&welcome=${params.welcome}`;
const query = createParameter !== undefined ? `${baseQuery}&${createParameter}` : baseQuery;
const apiCall = `create${query}${params.secret}`;
const checksum = sha1(apiCall);
const checksum = getChecksum(apiCall, parameters.secret);
const url = `${params.server}/create?${query}&checksum=${checksum}`;
return url;
}
Expand All @@ -61,7 +79,7 @@ function getJoinURL(meetingID, params, moderator, joinParameter) {
const baseQuery = `fullName=${params.fullName}&meetingID=${meetingID}&password=${pw}`;
const query = joinParameter !== undefined ? `${baseQuery}&${joinParameter}` : baseQuery;
const apiCall = `join${query}${params.secret}`;
const checksum = sha1(apiCall);
const checksum = getChecksum(apiCall, parameters.secret);
return `${params.server}/join?${query}&checksum=${checksum}`;
}

Expand Down
92 changes: 50 additions & 42 deletions bigbluebutton-tests/playwright/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bigbluebutton-tests/playwright/package.json
Expand Up @@ -16,7 +16,7 @@
"deep-equal": "^2.2.1",
"dotenv": "^16.1.4",
"playwright": "^1.37.1",
"sha1": "^1.1.1",
"sha.js": "^2.4.11",
"xml2js": "^0.6.0"
}
}
}

0 comments on commit fdbab50

Please sign in to comment.