Skip to content

Commit

Permalink
add check for config to make sure its defined (prebid#5873)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fawke authored and stsepelin committed May 28, 2021
1 parent 762d8fd commit f99894c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export function resetConsentData() {
export function setConsentConfig(config) {
// if `config.gdpr` or `config.usp` exist, assume new config format.
// else for backward compatability, just use `config`
config = config.gdpr || config.usp ? config.gdpr : config;
config = config && (config.gdpr || config.usp ? config.gdpr : config);
if (!config || typeof config !== 'object') {
utils.logWarn('consentManagement config not defined, exiting consent manager');
return;
Expand Down
2 changes: 1 addition & 1 deletion modules/consentManagementUsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export function resetConsentData() {
* @param {object} config required; consentManagementUSP module config settings; usp (string), timeout (int), allowAuctionWithoutConsent (boolean)
*/
export function setConsentConfig(config) {
config = config.usp;
config = config && config.usp;
if (!config || typeof config !== 'object') {
utils.logWarn('consentManagement.usp config not defined, exiting usp consent manager');
return;
Expand Down
7 changes: 7 additions & 0 deletions test/spec/modules/consentManagementUsp_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ describe('consentManagement', function () {
sinon.assert.calledOnce(utils.logWarn);
sinon.assert.notCalled(utils.logInfo);
});

it('should exit consentManagementUsp module if config is "undefined"', function() {
setConsentConfig(undefined);
expect(consentAPI).to.be.undefined;
sinon.assert.calledOnce(utils.logWarn);
sinon.assert.notCalled(utils.logInfo);
});
});

describe('valid setConsentConfig value', function () {
Expand Down
6 changes: 6 additions & 0 deletions test/spec/modules/consentManagement_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ describe('consentManagement', function () {
expect(userCMP).to.be.undefined;
sinon.assert.calledOnce(utils.logWarn);
});

it('should exit consentManagement module if config is "undefined"', function() {
setConsentConfig(undefined);
expect(userCMP).to.be.undefined;
sinon.assert.calledOnce(utils.logWarn);
});
});

describe('valid setConsentConfig value', function () {
Expand Down

0 comments on commit f99894c

Please sign in to comment.