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

GDPR consent management: accept static config without getTCData #9664

Merged
merged 1 commit into from
Mar 19, 2023
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
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