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
…bigbluebutton#19725)

* update to support sha256 and sha512 algorithms

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

Co-authored-by: Anton Barboza de Sá <[email protected]>

---------

Co-authored-by: Anton Georgiev <[email protected]>
Co-authored-by: Anton Barboza de Sá <[email protected]>
  • Loading branch information
3 people committed Mar 18, 2024
1 parent da735d5 commit 574f8fd
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 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

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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 574f8fd

Please sign in to comment.