From 17a4392a3830e40a52fe5944e56174f8d49c6073 Mon Sep 17 00:00:00 2001 From: Inbal Vasserman Date: Mon, 6 May 2024 16:52:21 +0300 Subject: [PATCH 1/7] fix(SUP-42476): Bloomberg - Fallback not working player V7 eCDN --- src/k-provider/ovp/regex-action-handler.ts | 95 ++++++++++++---------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/src/k-provider/ovp/regex-action-handler.ts b/src/k-provider/ovp/regex-action-handler.ts index 30f77896..35135dd1 100644 --- a/src/k-provider/ovp/regex-action-handler.ts +++ b/src/k-provider/ovp/regex-action-handler.ts @@ -27,34 +27,39 @@ class RegexActionHandler { } /** - * Ping the ECDN url to check if alive - * @function _pingECDNUrl + * Ping the ECDN url and replace the host urls if needed + * @function _pingECDNAndReplaceHostUrls + * @param {ProviderMediaConfigObject} mediaConfig - The media config * @param {KalturaAccessControlModifyRequestHostRegexAction} regexAction - The regex action * @param {string} cdnUrl - The CDN url - * @returns {Promise} - Whether the media config sources urls should be modified or not + * @returns {Promise} - The media config with old or modified urls * @static * @private */ - private static async _isECDNUrlAlive(regexAction: KalturaAccessControlModifyRequestHostRegexAction, cdnUrl: string): Promise { - const urlPing = cdnUrl + '/api_v3/service/system/action/ping/format/1'; - const req = new XMLHttpRequest(); - req.open('GET', urlPing); - req.timeout = regexAction.checkAliveTimeoutMs; - req.onreadystatechange = (): boolean => { - if (req.readyState === 4) { - if (req.status === 200) { - return true; + private static _pingECDNAndReplaceHostUrls( + mediaConfig: ProviderMediaConfigObject, + regexAction: KalturaAccessControlModifyRequestHostRegexAction, + cdnUrl: string + ): Promise { + return new Promise(resolve => { + const urlPing = cdnUrl + '/api_v3/service/system/action/ping/format/1'; + const req = new XMLHttpRequest(); + req.open('GET', urlPing); + req.timeout = regexAction.checkAliveTimeoutMs; + req.onreadystatechange = ():void => { + if (req.readyState === 4) { + if (req.status === 200) { + RegexActionHandler._replaceHostUrls(mediaConfig, regexAction); + } + resolve(mediaConfig); } - return false; - } - return false; - }; - req.ontimeout = (): boolean => { - RegexActionHandler._logger.warn(`Got timeout while pinging the ECDN url. the ping url: ${urlPing}`); - return false; - }; - req.send(); - return false; + }; + req.ontimeout = ():void => { + RegexActionHandler._logger.warn(`Got timeout while pinging the ECDN url. the ping url: ${urlPing}`); + resolve(mediaConfig); + }; + req.send(); + }); } /** @@ -62,31 +67,33 @@ class RegexActionHandler { * @function handleRegexAction * @param {ProviderMediaConfigObject} mediaConfig - The media config * @param {Map} rawResponse - The raw response data from backend - * @returns {Promise} - The media config with old or modified urls + * @returns {ProviderMediaConfigObject} - The media config with old or modified urls * @static */ - public static async handleRegexAction(mediaConfig: ProviderMediaConfigObject, rawResponse: Map): Promise { - const cdnUrl = OVPConfiguration.get().cdnUrl; - const regexAction = RegexActionHandler._extractRegexActionFromData(rawResponse); - const regExp = RegexActionHandler._getRegExp(regexAction); + public static handleRegexAction(mediaConfig: ProviderMediaConfigObject, rawResponse: Map): Promise { + return new Promise(resolve => { + const cdnUrl = OVPConfiguration.get().cdnUrl; + const regexAction = RegexActionHandler._extractRegexActionFromData(rawResponse); + const regExp = RegexActionHandler._getRegExp(regexAction); - if ( - cdnUrl && - regexAction && - regExp && - cdnUrl.match(regExp) && - // we need to make the replacement in all cases except for when the checkAliveTimeoutMs > 0 && the ping has failed - !( - regexAction.checkAliveTimeoutMs > 0 && - !(await RegexActionHandler._isECDNUrlAlive(regexAction, cdnUrl.replace(regExp, regexAction.replacement))) - ) - ) { - RegexActionHandler._replaceHostUrls(mediaConfig, regexAction); - return mediaConfig; - } - - RegexActionHandler._logger.debug('exiting handleRegexAction - not applying regex action.'); - return mediaConfig; + if( + cdnUrl && + regexAction && + regExp && + cdnUrl.match(regExp) + ) { + if (regexAction.checkAliveTimeoutMs > 0) { + RegexActionHandler._logger.debug('executing ping request...'); + RegexActionHandler._pingECDNAndReplaceHostUrls(mediaConfig, regexAction, cdnUrl.replace(regExp, regexAction.replacement)).then(resolve); + } else { + RegexActionHandler._replaceHostUrls(mediaConfig, regexAction); + resolve(mediaConfig); + } + } else { + RegexActionHandler._logger.debug('exiting handleRegexAction - not applying regex action.'); + resolve(mediaConfig); + } + }); } /** From 7a618cfb82138a77b9b572d3f36eb8abbeb23d66 Mon Sep 17 00:00:00 2001 From: Inbal Vasserman Date: Mon, 6 May 2024 16:57:53 +0300 Subject: [PATCH 2/7] try fix git issue --- src/k-provider/ovp/regex-action-handler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/k-provider/ovp/regex-action-handler.ts b/src/k-provider/ovp/regex-action-handler.ts index 35135dd1..2dbac79c 100644 --- a/src/k-provider/ovp/regex-action-handler.ts +++ b/src/k-provider/ovp/regex-action-handler.ts @@ -36,7 +36,7 @@ class RegexActionHandler { * @static * @private */ - private static _pingECDNAndReplaceHostUrls( + private static _isECDNUrlAlive( mediaConfig: ProviderMediaConfigObject, regexAction: KalturaAccessControlModifyRequestHostRegexAction, cdnUrl: string @@ -84,7 +84,7 @@ class RegexActionHandler { ) { if (regexAction.checkAliveTimeoutMs > 0) { RegexActionHandler._logger.debug('executing ping request...'); - RegexActionHandler._pingECDNAndReplaceHostUrls(mediaConfig, regexAction, cdnUrl.replace(regExp, regexAction.replacement)).then(resolve); + RegexActionHandler._isECDNUrlAlive(mediaConfig, regexAction, cdnUrl.replace(regExp, regexAction.replacement)).then(resolve); } else { RegexActionHandler._replaceHostUrls(mediaConfig, regexAction); resolve(mediaConfig); From c5c297d40bc8d0a5ddab37de6d4f8afedbdfb6d9 Mon Sep 17 00:00:00 2001 From: Inbal Vasserman Date: Mon, 6 May 2024 17:05:18 +0300 Subject: [PATCH 3/7] try to fix tests --- src/k-provider/ovp/regex-action-handler.ts | 4 ++-- .../ovp/regex-action-handler.spec.js | 19 ------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/k-provider/ovp/regex-action-handler.ts b/src/k-provider/ovp/regex-action-handler.ts index 2dbac79c..35135dd1 100644 --- a/src/k-provider/ovp/regex-action-handler.ts +++ b/src/k-provider/ovp/regex-action-handler.ts @@ -36,7 +36,7 @@ class RegexActionHandler { * @static * @private */ - private static _isECDNUrlAlive( + private static _pingECDNAndReplaceHostUrls( mediaConfig: ProviderMediaConfigObject, regexAction: KalturaAccessControlModifyRequestHostRegexAction, cdnUrl: string @@ -84,7 +84,7 @@ class RegexActionHandler { ) { if (regexAction.checkAliveTimeoutMs > 0) { RegexActionHandler._logger.debug('executing ping request...'); - RegexActionHandler._isECDNUrlAlive(mediaConfig, regexAction, cdnUrl.replace(regExp, regexAction.replacement)).then(resolve); + RegexActionHandler._pingECDNAndReplaceHostUrls(mediaConfig, regexAction, cdnUrl.replace(regExp, regexAction.replacement)).then(resolve); } else { RegexActionHandler._replaceHostUrls(mediaConfig, regexAction); resolve(mediaConfig); diff --git a/test/src/k-provider/ovp/regex-action-handler.spec.js b/test/src/k-provider/ovp/regex-action-handler.spec.js index 2f9e247e..d6b1c991 100644 --- a/test/src/k-provider/ovp/regex-action-handler.spec.js +++ b/test/src/k-provider/ovp/regex-action-handler.spec.js @@ -19,16 +19,7 @@ describe('handleRegexAction', function () { data.set('media', mediaEntryLoader); }); - afterEach(() => { - RegexActionHandler._isECDNUrlAlive.restore(); - }); - it('should modify all URLs', done => { - sinon.stub(RegexActionHandler, '_isECDNUrlAlive').callsFake(function () { - return new Promise(resolve => { - resolve(true); - }); - }); OVPConfiguration.set({replaceHostOnlyManifestUrls: false}); mediaConfigForTest = JSON.parse(JSON.stringify({...mediaConfig})); RegexActionHandler.handleRegexAction(mediaConfigForTest, data).then( @@ -47,11 +38,6 @@ describe('handleRegexAction', function () { }); it('should modify only the manifest URLs', done => { - sinon.stub(RegexActionHandler, '_isECDNUrlAlive').callsFake(function () { - return new Promise(resolve => { - resolve(true); - }); - }); OVPConfiguration.set({replaceHostOnlyManifestUrls: true}); mediaConfigForTest = JSON.parse(JSON.stringify({...mediaConfig})); RegexActionHandler.handleRegexAction(mediaConfigForTest, data).then( @@ -70,11 +56,6 @@ describe('handleRegexAction', function () { }); it('should not modify the sources URLs', done => { - sinon.stub(RegexActionHandler, '_isECDNUrlAlive').callsFake(function () { - return new Promise(resolve => { - resolve(false); - }); - }); mediaConfigForTest = JSON.parse(JSON.stringify({...mediaConfig})); RegexActionHandler.handleRegexAction(mediaConfigForTest, data).then( mediaConfigRes => { From 26ac970c31a43cd830d8332b139c671ffd51d1a6 Mon Sep 17 00:00:00 2001 From: Inbal Vasserman Date: Mon, 6 May 2024 17:08:04 +0300 Subject: [PATCH 4/7] try to fix tests 2 --- test/src/k-provider/ovp/regex-action-handler.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/k-provider/ovp/regex-action-handler.spec.js b/test/src/k-provider/ovp/regex-action-handler.spec.js index d6b1c991..b997ace3 100644 --- a/test/src/k-provider/ovp/regex-action-handler.spec.js +++ b/test/src/k-provider/ovp/regex-action-handler.spec.js @@ -21,7 +21,7 @@ describe('handleRegexAction', function () { it('should modify all URLs', done => { OVPConfiguration.set({replaceHostOnlyManifestUrls: false}); - mediaConfigForTest = JSON.parse(JSON.stringify({...mediaConfig})); + mediaConfigForTest = {...mediaConfig}; RegexActionHandler.handleRegexAction(mediaConfigForTest, data).then( mediaConfigRes => { try { From 2e491537c4130f0d463de317ebd503cf84d7aff1 Mon Sep 17 00:00:00 2001 From: Inbal Vasserman Date: Mon, 6 May 2024 17:11:51 +0300 Subject: [PATCH 5/7] try to fix tests 3 --- test/src/k-provider/ovp/regex-action-handler.spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/src/k-provider/ovp/regex-action-handler.spec.js b/test/src/k-provider/ovp/regex-action-handler.spec.js index b997ace3..ef35b248 100644 --- a/test/src/k-provider/ovp/regex-action-handler.spec.js +++ b/test/src/k-provider/ovp/regex-action-handler.spec.js @@ -19,6 +19,10 @@ describe('handleRegexAction', function () { data.set('media', mediaEntryLoader); }); + afterEach(() => { + RegexActionHandler._pingECDNAndReplaceHostUrls.restore(); + }); + it('should modify all URLs', done => { OVPConfiguration.set({replaceHostOnlyManifestUrls: false}); mediaConfigForTest = {...mediaConfig}; From 663ac1ec2393e3fb480d7bb2882f51bb3e21e623 Mon Sep 17 00:00:00 2001 From: Inbal Vasserman Date: Wed, 8 May 2024 12:20:21 +0300 Subject: [PATCH 6/7] fix tests --- .../ovp/regex-action-handler.spec.js | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/src/k-provider/ovp/regex-action-handler.spec.js b/test/src/k-provider/ovp/regex-action-handler.spec.js index ef35b248..d0f5a84e 100644 --- a/test/src/k-provider/ovp/regex-action-handler.spec.js +++ b/test/src/k-provider/ovp/regex-action-handler.spec.js @@ -8,8 +8,8 @@ import RegexActionHandler from '../../../../src/k-provider/ovp/regex-action-hand import OVPMediaEntryLoader from '../../../../src/k-provider/ovp/loaders/media-entry-loader'; import OVPConfiguration from '../../../../src/k-provider/ovp/config'; -describe('handleRegexAction', function () { - let data = new Map(); +describe.only('handleRegexAction', ()=> { + const data = new Map(); let mediaEntryLoader; let mediaConfigForTest = {...mediaConfig}; @@ -24,8 +24,15 @@ describe('handleRegexAction', function () { }); it('should modify all URLs', done => { + sinon.stub(RegexActionHandler, '_pingECDNAndReplaceHostUrls').callsFake((mediaConfig, regexAction) => { + return new Promise(resolve => { + RegexActionHandler._replaceHostUrls(mediaConfig, regexAction); + resolve(mediaConfig); + }); + }); + OVPConfiguration.set({replaceHostOnlyManifestUrls: false}); - mediaConfigForTest = {...mediaConfig}; + mediaConfigForTest = JSON.parse(JSON.stringify({...mediaConfig})); RegexActionHandler.handleRegexAction(mediaConfigForTest, data).then( mediaConfigRes => { try { @@ -42,6 +49,13 @@ describe('handleRegexAction', function () { }); it('should modify only the manifest URLs', done => { + sinon.stub(RegexActionHandler, '_pingECDNAndReplaceHostUrls').callsFake((mediaConfig, regexAction) => { + return new Promise(resolve => { + RegexActionHandler._replaceHostUrls(mediaConfig, regexAction); + resolve(mediaConfig); + }); + }); + OVPConfiguration.set({replaceHostOnlyManifestUrls: true}); mediaConfigForTest = JSON.parse(JSON.stringify({...mediaConfig})); RegexActionHandler.handleRegexAction(mediaConfigForTest, data).then( @@ -60,6 +74,11 @@ describe('handleRegexAction', function () { }); it('should not modify the sources URLs', done => { + sinon.stub(RegexActionHandler, '_pingECDNAndReplaceHostUrls').callsFake((mediaConfig) => { + return new Promise(resolve => { + resolve(mediaConfig); + }); + }); mediaConfigForTest = JSON.parse(JSON.stringify({...mediaConfig})); RegexActionHandler.handleRegexAction(mediaConfigForTest, data).then( mediaConfigRes => { From fc0cf2029aa48fc92a66795ee26a5ac6176e50f4 Mon Sep 17 00:00:00 2001 From: Inbal Vasserman Date: Wed, 8 May 2024 12:21:15 +0300 Subject: [PATCH 7/7] remove describe only from tests --- test/src/k-provider/ovp/regex-action-handler.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/k-provider/ovp/regex-action-handler.spec.js b/test/src/k-provider/ovp/regex-action-handler.spec.js index d0f5a84e..f6b06b6f 100644 --- a/test/src/k-provider/ovp/regex-action-handler.spec.js +++ b/test/src/k-provider/ovp/regex-action-handler.spec.js @@ -8,7 +8,7 @@ import RegexActionHandler from '../../../../src/k-provider/ovp/regex-action-hand import OVPMediaEntryLoader from '../../../../src/k-provider/ovp/loaders/media-entry-loader'; import OVPConfiguration from '../../../../src/k-provider/ovp/config'; -describe.only('handleRegexAction', ()=> { +describe('handleRegexAction', ()=> { const data = new Map(); let mediaEntryLoader; let mediaConfigForTest = {...mediaConfig};