Skip to content

Commit

Permalink
feat(FEC-8734): add protection for invalid source creation (#70)
Browse files Browse the repository at this point in the history
don't add invalid sources to sources object.
source may have incompatible protocol for example and then a source with missing protocol query string param is generated - so need to make sure this is not added to output of applicable sources.
Also add:

fix reference to this in a static class method
fix mandatory params check in PlaySourceUrlBuilder
  • Loading branch information
OrenMe authored Dec 11, 2018
1 parent 602628e commit 8fd30fd
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 48 deletions.
Empty file.
14 changes: 8 additions & 6 deletions src/k-provider/ott/provider-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ export default class OTTProviderParser {
const sources = new MediaSources();
const addAdaptiveSource = (source: KalturaPlaybackSource) => {
const parsedSource = OTTProviderParser._parseAdaptiveSource(source);
const sourceFormat = SupportedStreamFormat.get(source.format);
sources.map(parsedSource, sourceFormat);
if (parsedSource) {
const sourceFormat = SupportedStreamFormat.get(source.format);
sources.map(parsedSource, sourceFormat);
}
};
const parseAdaptiveSources = () => {
kalturaSources.filter(source => !isProgressiveSource(source.format)).forEach(addAdaptiveSource);
Expand All @@ -177,23 +179,23 @@ export default class OTTProviderParser {
* Returns a parsed adaptive source
* @function _parseAdaptiveSource
* @param {KalturaPlaybackSource} kalturaSource - A kaltura source
* @returns {MediaSource} - The parsed adaptive kalturaSource
* @returns {?MediaSource} - The parsed adaptive kalturaSource
* @static
* @private
*/
static _parseAdaptiveSource(kalturaSource: ?KalturaPlaybackSource): MediaSource {
static _parseAdaptiveSource(kalturaSource: ?KalturaPlaybackSource): ?MediaSource {
const mediaSource = new MediaSource();
if (kalturaSource) {
const playUrl = kalturaSource.url;
const mediaFormat = SupportedStreamFormat.get(kalturaSource.format);
if (mediaFormat) {
mediaSource.mimetype = mediaFormat.mimeType;
}
if (playUrl === '') {
if (!playUrl) {
OTTProviderParser._logger.error(
`failed to create play url from source, discarding source: (${kalturaSource.fileId}), ${kalturaSource.format}.`
);
return mediaSource;
return null;
}
mediaSource.url = playUrl;
mediaSource.id = kalturaSource.fileId + ',' + kalturaSource.format;
Expand Down
33 changes: 19 additions & 14 deletions src/k-provider/ovp/play-source-url-builder.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
//@flow
import OVPConfiguration from './config';

type urlParamsType = {
partnerId: number,
entryId: string,
ks: string,
uiConfId: ?number,
format: string,
protocol: string,
extension: string,
flavorIds: ?string
};

export default class PlaySourceUrlBuilder {
/**
* Returns source url by given url params
* @function build
* @param {Object} urlParams The params
* @param {urlParamsType} urlParams The params
* @returns {string} The URL
* @static
*/
static build(urlParams: Object): string {
static build(urlParams: urlParamsType): string {
const config = OVPConfiguration.get();
const cdnUrl: string = config.cdnUrl;
const partnerId: string = urlParams.partnerId;
const entryId: string = urlParams.entryId;
const ks: string = urlParams.ks;
const uiConfId: string = urlParams.uiConfId;
const format: string = urlParams.format;
const protocol: string = urlParams.protocol;
const extension: string = urlParams.extension;
const flavorIds: string = urlParams.flavorIds;

if (cdnUrl === '' && partnerId === '' && entryId === '' && extension === '' && format === '') {
const {partnerId, entryId, ks, uiConfId, format, protocol, extension, flavorIds} = urlParams;

//verify mandatory params
if (!cdnUrl || !partnerId || !entryId || !extension || !format || !protocol || !extension) {
return '';
}

Expand All @@ -31,9 +36,9 @@ export default class PlaySourceUrlBuilder {
}
playUrl += 'p/' + partnerId + '/sp/' + partnerId + '00' + '/playManifest/entryId/' + entryId + '/protocol/' + protocol + '/format/' + format;

if (flavorIds !== '') {
if (flavorIds) {
playUrl += '/flavorIds/' + flavorIds;
} else if (uiConfId !== '') {
} else if (uiConfId) {
playUrl += '/uiConfId/' + uiConfId;
}

Expand Down
66 changes: 38 additions & 28 deletions src/k-provider/ovp/provider-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class OVPProviderParser {
mediaEntry.poster = entry.poster;
mediaEntry.id = entry.id;
mediaEntry.duration = entry.duration;
mediaEntry.metadata = this._parseMetadata(metadataList);
mediaEntry.metadata = OVPProviderParser._parseMetadata(metadataList);
mediaEntry.metadata.description = entry.description || '';
mediaEntry.metadata.name = entry.name || '';
mediaEntry.metadata.tags = entry.tags || '';
Expand Down Expand Up @@ -154,8 +154,10 @@ export default class OVPProviderParser {
const sources = new MediaSources();
const addAdaptiveSource = (source: KalturaPlaybackSource) => {
const parsedSource = OVPProviderParser._parseAdaptiveSource(source, playbackContext, ks, partnerId, uiConfId, entry.id);
const sourceFormat = SupportedStreamFormat.get(source.format);
sources.map(parsedSource, sourceFormat);
if (parsedSource) {
const sourceFormat = SupportedStreamFormat.get(source.format);
sources.map(parsedSource, sourceFormat);
}
};
const parseAdaptiveSources = () => {
kalturaSources.filter(source => !isProgressiveSource(source.format)).forEach(addAdaptiveSource);
Expand All @@ -180,7 +182,7 @@ export default class OVPProviderParser {
* @param {number} partnerId - The partner ID
* @param {number} uiConfId - The uiConf ID
* @param {string} entryId - The entry id
* @returns {MediaSource} - The parsed adaptive kalturaSource
* @returns {?MediaSource} - The parsed adaptive kalturaSource
* @static
* @private
*/
Expand All @@ -191,11 +193,14 @@ export default class OVPProviderParser {
partnerId: number,
uiConfId: ?number,
entryId: string
): MediaSource {
): ?MediaSource {
const mediaSource: MediaSource = new MediaSource();
if (kalturaSource) {
let playUrl: string = '';
const mediaFormat = SupportedStreamFormat.get(kalturaSource.format);
const protocol = kalturaSource.getProtocol(OVPProviderParser._getBaseProtocol());
const deliveryProfileId = kalturaSource.deliveryProfileId;
const format = kalturaSource.format;
let extension: string = '';
if (mediaFormat) {
extension = mediaFormat.pathExt;
Expand All @@ -207,26 +212,25 @@ export default class OVPProviderParser {
extension = playbackContext.flavorAssets[0].fileExt;
}
playUrl = PlaySourceUrlBuilder.build({
entryId: entryId,
entryId,
flavorIds: kalturaSource.flavorIds,
format: kalturaSource.format,
ks: ks,
partnerId: partnerId,
uiConfId: uiConfId,
extension: extension,
protocol: kalturaSource.getProtocol(this._getBaseProtocol())
format,
ks,
partnerId,
uiConfId,
extension,
protocol
});
} else {
playUrl = kalturaSource.url;
}
if (playUrl === '') {
OVPProviderParser._logger.error(
`failed to create play url from source, discarding source: (${entryId}_${kalturaSource.deliveryProfileId}), ${kalturaSource.format}.`
);
return mediaSource;
if (!playUrl) {
const message = `failed to create play url from source, discarding source: (${entryId}_${deliveryProfileId}), ${format}`;
OVPProviderParser._logger.warn(message);
return null;
}
mediaSource.url = OVPProviderParser._applyRegexAction(playbackContext, playUrl);
mediaSource.id = entryId + '_' + kalturaSource.deliveryProfileId + ',' + kalturaSource.format;
mediaSource.id = entryId + '_' + deliveryProfileId + ',' + format;
if (kalturaSource.hasDrmData()) {
const drmParams: Array<Drm> = [];
kalturaSource.drm.forEach(drm => {
Expand Down Expand Up @@ -262,9 +266,10 @@ export default class OVPProviderParser {
const videoSources: Array<MediaSource> = [];
const audioSources: Array<MediaSource> = [];
if (kalturaSource) {
const protocol = kalturaSource.getProtocol(this._getBaseProtocol());
const protocol = kalturaSource.getProtocol(OVPProviderParser._getBaseProtocol());
const format = kalturaSource.format;
const sourceId = kalturaSource.deliveryProfileId + ',' + kalturaSource.format;
const deliveryProfileId = kalturaSource.deliveryProfileId;
const sourceId = deliveryProfileId + ',' + format;
playbackContext.flavorAssets.map(flavor => {
const mediaSource: MediaSource = new MediaSource();
mediaSource.id = flavor.id + sourceId;
Expand All @@ -274,20 +279,25 @@ export default class OVPProviderParser {
mediaSource.bandwidth = flavor.bitrate * 1024;
mediaSource.label = flavor.label || flavor.language;
const playUrl = PlaySourceUrlBuilder.build({
entryId: entryId,
entryId,
flavorIds: flavor.id,
format: format,
ks: ks,
format,
ks,
partnerId: partnerId,
uiConfId: uiConfId,
extension: flavor.fileExt,
protocol: protocol
protocol
});
mediaSource.url = OVPProviderParser._applyRegexAction(playbackContext, playUrl);
if (flavor.height && flavor.width) {
videoSources.push(mediaSource);
if (playUrl === '') {
OVPProviderParser._logger.warn(`failed to create play url from source, discarding source: (${entryId}_${deliveryProfileId}), ${format}.`);
return null;
} else {
audioSources.push(mediaSource);
mediaSource.url = OVPProviderParser._applyRegexAction(playbackContext, playUrl);
if (flavor.height && flavor.width) {
videoSources.push(mediaSource);
} else {
audioSources.push(mediaSource);
}
}
});
}
Expand Down
Loading

0 comments on commit 8fd30fd

Please sign in to comment.