Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for consentManagement config to make sure it's defined #5873

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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