diff --git a/package-lock.json b/package-lock.json index b0284c47..a32320e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rtcstats-server", - "version": "2.24.0", + "version": "2.24.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rtcstats-server", - "version": "2.24.0", + "version": "2.24.1", "license": "ISC", "dependencies": { "amplitude": "^4.0.1", diff --git a/package.json b/package.json index deeb5baa..3dd8efbc 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/demux.js b/src/demux.js index 3d23f196..47412b41 100644 --- a/src/demux.js +++ b/src/demux.js @@ -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(); } diff --git a/src/test/jest/utils.test.js b/src/test/jest/utils.test.js index 5f3bb64b..f551c9f6 100644 --- a/src/test/jest/utils.test.js +++ b/src/test/jest/utils.test.js @@ -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(() => { @@ -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); + }); +}); diff --git a/src/utils/utils.js b/src/utils/utils.js index f51cb393..83b56a1c 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -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 = '';