Skip to content

Commit

Permalink
GDPR consent management: accept static config without getTCData (pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored and jorgeluisrocha committed May 18, 2023
1 parent 88670d8 commit 6c86fba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
9 changes: 4 additions & 5 deletions modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,6 @@ function processCmpData(consentObject, {onSuccess, onError}) {
);
}

// do extra things for static config
if (userCMP === 'static') {
consentObject = consentObject.getTCData;
}

if (checkData()) {
onError(`CMP returned unexpected value during lookup process.`, consentObject);
} else {
Expand Down Expand Up @@ -362,6 +357,10 @@ export function setConsentConfig(config) {
if (userCMP === 'static') {
if (isPlainObject(config.consentData)) {
staticConsentData = config.consentData;
if (staticConsentData?.getTCData != null) {
// accept static config with or without `getTCData` - see https://github.com/prebid/Prebid.js/issues/9581
staticConsentData = staticConsentData.getTCData;
}
consentTimeout = 0;
} else {
logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`);
Expand Down
49 changes: 26 additions & 23 deletions test/spec/modules/consentManagement_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,17 @@ describe('consentManagement', function () {
});

describe('static consent string setConsentConfig value', () => {
afterEach(() => {
config.resetConfig();
});
Object.entries({
'getTCData': (cfg) => ({getTCData: cfg}),
'consent data directly': (cfg) => cfg,
}).forEach(([t, packageCfg]) => {
describe(`using ${t}`, () => {
afterEach(() => {
config.resetConfig();
});

it('results in user settings overriding system defaults for v2 spec', () => {
let staticConfig = {
cmpApi: 'static',
timeout: 7500,
consentData: {
getTCData: {
it('results in user settings overriding system defaults for v2 spec', () => {
const consentData = {
'tcString': 'COuqj-POu90rDBcBkBENAZCgAPzAAAPAACiQFwwBAABAA1ADEAbQC4YAYAAgAxAG0A',
'cmpId': 92,
'cmpVersion': 100,
Expand Down Expand Up @@ -218,18 +219,22 @@ describe('consentManagement', function () {
'legitimateInterests': {}
}
}
}
}
};
};

setConsentConfig(staticConfig);
expect(userCMP).to.be.equal('static');
expect(consentTimeout).to.be.equal(0); // should always return without a timeout when config is used
expect(gdprScope).to.be.equal(false);
const consent = gdprDataHandler.getConsentData();
expect(consent.consentString).to.eql(staticConfig.consentData.getTCData.tcString);
expect(consent.vendorData).to.eql(staticConfig.consentData.getTCData);
expect(staticConsentData).to.be.equal(staticConfig.consentData);
setConsentConfig({
cmpApi: 'static',
timeout: 7500,
consentData: packageCfg(consentData)
});
expect(userCMP).to.be.equal('static');
expect(consentTimeout).to.be.equal(0); // should always return without a timeout when config is used
expect(gdprScope).to.be.equal(false);
const consent = gdprDataHandler.getConsentData();
expect(consent.consentString).to.eql(consentData.tcString);
expect(consent.vendorData).to.eql(consentData);
expect(staticConsentData).to.be.equal(consentData);
});
});
});
});
});
Expand All @@ -243,9 +248,7 @@ describe('consentManagement', function () {
const staticConfig = {
cmpApi: 'static',
timeout: 7500,
consentData: {
getTCData: {}
}
consentData: {}
}

let didHookReturn;
Expand Down

0 comments on commit 6c86fba

Please sign in to comment.