Skip to content

Commit

Permalink
fix: handle tenant url strings that contain protocol (#119)
Browse files Browse the repository at this point in the history
* handle tenant url strings that contain protocol

* appease the linter

* bump version to 2.24.1
  • Loading branch information
andrei-gavrilescu authored Oct 5, 2023
1 parent c1d0bcf commit c86022b
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rtcstats-server",
"version": "2.24.0",
"version": "2.24.1",
"description": "The rtcstats-server represents the server side component of the rtcstats ecosystem, the client side being https://github.com/jitsi/rtcstats which collects and sends WebRTC related statistics.",
"main": "websocket.js",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions src/demux.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class DemuxSink extends Writable {
* @param {string} id - UniqueId associated with the sink
* @param {WriteStream} sink - Opened file writable stream associated with the id
*/
_sinkClose({ id, sink }) {
this.log.info('[Demux] close-sink %s', id);
_sinkClose({ id, sink, meta }) {
this.log.info('[Demux] close-sink %s, metadata: %o', id, meta);

sink.end();
}
Expand Down
148 changes: 147 additions & 1 deletion src/test/jest/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-undef */
/* eslint-disable max-len */
const { getStatsFormat, StatsFormat } = require('../../utils/stats-detection');
const { getUrlParameter, addProtocol } = require('../../utils/utils');
const { getUrlParameter, addProtocol, extractTenantDataFromUrl } = require('../../utils/utils');

describe('getStatsFormat', () => {
beforeEach(() => {
Expand Down Expand Up @@ -200,3 +200,149 @@ describe('addProtocol', () => {
expect(addProtocol(undefined)).toBe(undefined);
});
});

describe('extractTenantDataFromUrl', () => {
test('returns expected tenant information for url without protocol data', () => {
const url = '8x8.vc/vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1');
expect(jaasMeetingFqn).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand');
expect(jaasClientId).toBe('a91ddcwqdqdqw60785131lda1');
expect(isJaaSTenant).toBe(true);
});

test('returns expected tenant information for url without an meeting name', () => {
const url = '8x8.vc/vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1');
expect(jaasMeetingFqn).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1');
expect(jaasClientId).toBe('a91ddcwqdqdqw60785131lda1');
expect(isJaaSTenant).toBe(true);
});

test('returns empty tenant information if magic prefix is not set', () => {
const url = '8x8.vc/vpaas-magi-a91ddcwqdqdqw60785131lda1/';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('');
expect(jaasMeetingFqn).toBe('');
expect(jaasClientId).toBe('');
expect(isJaaSTenant).toBe(false);
});

test('returns empty tenant information for empty string as url', () => {
const url = '';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('');
expect(jaasMeetingFqn).toBe('');
expect(jaasClientId).toBe('');
expect(isJaaSTenant).toBe(false);
});

test('returns empty tenant information for undefined as url', () => {
const url = undefined;

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('');
expect(jaasMeetingFqn).toBe('');
expect(jaasClientId).toBe('');
expect(isJaaSTenant).toBe(false);
});

test('returns empty tenant information for malformed url', () => {
const url = 'htt//8x8.vc/vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('');
expect(jaasMeetingFqn).toBe('');
expect(jaasClientId).toBe('');
expect(isJaaSTenant).toBe(false);
});

test('returns empty tenant information for malformed url', () => {
const url = 'http:////8x8.vc/vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('');
expect(jaasMeetingFqn).toBe('');
expect(jaasClientId).toBe('');
expect(isJaaSTenant).toBe(false);
});

test('returns expected tenant information for url with https protocol data', () => {
const url = 'https://8x8.vc/vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1');
expect(jaasMeetingFqn).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand');
expect(jaasClientId).toBe('a91ddcwqdqdqw60785131lda1');
expect(isJaaSTenant).toBe(true);
});

test('returns expected tenant information for url with http protocol data', () => {
const url = 'http://8x8.vc/vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand';

const {
tenant,
jaasMeetingFqn,
jaasClientId,
isJaaSTenant
} = extractTenantDataFromUrl(url);

expect(tenant).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1');
expect(jaasMeetingFqn).toBe('vpaas-magic-cookie-a91ddcwqdqdqw60785131lda1/random-meeting/rand');
expect(jaasClientId).toBe('a91ddcwqdqdqw60785131lda1');
expect(isJaaSTenant).toBe(true);
});
});
4 changes: 3 additions & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ const VPAAS_TENANT_PREFIX = 'vpaas-magic-cookie-';
*/
function extractTenantDataFromUrl(conferenceUrl = '') {

const [ , urlFirstPart, ...confPath ] = conferenceUrl.split('/');
const noProtoConferenceUrl = conferenceUrl.replace(/(^\w+:|^)\/\//, '');

const [ , urlFirstPart, ...confPath ] = noProtoConferenceUrl.split('/');

let tenant = '';
let jaasClientId = '';
Expand Down

0 comments on commit c86022b

Please sign in to comment.