Skip to content

Commit

Permalink
Merge pull request #2504 from Orange-OpenSource/addEmptyChallengeDRME…
Browse files Browse the repository at this point in the history
…rror

Add empty challenge drm error
  • Loading branch information
epiclabsDASH committed Apr 3, 2018
2 parents ed9cb36 + f06dfde commit dcaca73
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/streaming/protection/controllers/ProtectionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ function ProtectionController(config) {
robustnessLevel = '';
}

function checkConfig() {
if (!eventBus || !eventBus.hasOwnProperty('on') || !protectionKeyController || !protectionKeyController.hasOwnProperty('getSupportedKeySystemsFromContentProtection')) {
throw new Error('Missing config parameter(s)');
}
}

/**
* Initialize this protection system with a given audio
* or video stream information.
Expand All @@ -89,6 +95,12 @@ function ProtectionController(config) {
// because still don't know which keysystem will be selected.
// Once Keysystem is selected and before creating the session, we will do that check
// so we create the strictly necessary DRM sessions
if (!mediaInfo) {
throw new Error('mediaInfo can not be null or undefined');
}

checkConfig();

eventBus.on(events.INTERNAL_KEY_MESSAGE, onKeyMessage, this);
eventBus.on(events.INTERNAL_KEY_STATUS_CHANGED, onKeyStatusChanged, this);

Expand Down Expand Up @@ -307,10 +319,12 @@ function ProtectionController(config) {

function getProtData(keySystem) {
let protData = null;
const keySystemString = keySystem.systemString;
if (keySystem) {
const keySystemString = keySystem.systemString;

if (protDataSet) {
protData = (keySystemString in protDataSet) ? protDataSet[keySystemString] : null;
if (protDataSet) {
protData = (keySystemString in protDataSet) ? protDataSet[keySystemString] : null;
}
}
return protData;
}
Expand Down Expand Up @@ -460,10 +474,16 @@ function ProtectionController(config) {
const message = keyMessage.message;
const sessionToken = keyMessage.sessionToken;
const protData = getProtData(keySystem);
const keySystemString = keySystem.systemString;
const keySystemString = keySystem ? keySystem.systemString : null;
const licenseServerData = protectionKeyController.getLicenseServer(keySystem, protData, messageType);
const eventData = { sessionToken: sessionToken, messageType: messageType };

// Ensure message from CDM is not empty
if (!message || message.byteLength === 0) {
sendLicenseRequestCompleteEvent(eventData, 'DRM: Empty key message from CDM');
return;
}

// Message not destined for license server
if (!licenseServerData) {
log('DRM: License server request not required for this message (type = ' + e.data.messageType + '). Session ID = ' + sessionToken.getSessionID());
Expand Down
12 changes: 12 additions & 0 deletions test/unit/mocks/ProtectionKeyControllerMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function ProtectionKeyControllerMock () {

this.getSupportedKeySystemsFromContentProtection = function (/*cps*/) {
return [];
};

this.getLicenseServer = function () {
return null;
};
}

export default ProtectionKeyControllerMock;
46 changes: 46 additions & 0 deletions test/unit/streaming.protection.controllers.ProtectionController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import ProtectionController from '../../src/streaming/protection/controllers/ProtectionController';
import ProtectionEvents from '../../src/streaming/protection/ProtectionEvents';
import EventBus from '../../src/core/EventBus';
import Debug from '../../src/core/Debug';

import ProtectionKeyControllerMock from './mocks/ProtectionKeyControllerMock';

const expect = require('chai').expect;
const context = {};
const eventBus = EventBus(context).getInstance();

describe('ProtectionController', function () {
describe('Not well initialized', function () {
let protectionController = ProtectionController(context).create({});

it('should throw an exception when attempting to call initializeForMedia function without mediaInfo parameter', function () {
expect(protectionController.initializeForMedia.bind(protectionController)).to.throw('mediaInfo can not be null or undefined');
});

it('should throw an error when initializeForMedia is called and config object has not been set properly', function () {
expect(protectionController.initializeForMedia.bind(protectionController, {})).to.throw('Missing config parameter(s)');
});
});

describe('onKeyMessage behavior', function () {
it('', function (done) {
const protectionKeyControllerMock = new ProtectionKeyControllerMock();
let protectionController = ProtectionController(context).create({protectionKeyController: protectionKeyControllerMock,
events: ProtectionEvents,
log: Debug(context).getInstance().log,
eventBus: eventBus});

let onDRMError = function (data) {
eventBus.off(ProtectionEvents.LICENSE_REQUEST_COMPLETE, onDRMError);
expect(data.error).to.be.equal('DRM: Empty key message from CDM'); // jshint ignore:line
done();
};

eventBus.on(ProtectionEvents.LICENSE_REQUEST_COMPLETE, onDRMError, this);

protectionController.initializeForMedia({});

eventBus.trigger(ProtectionEvents.INTERNAL_KEY_MESSAGE, {data: {}});
});
});
});

0 comments on commit dcaca73

Please sign in to comment.