From 097320a23987ffdd14e45d266471eab5bca33e5f Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Mon, 23 Apr 2018 12:35:29 -0700 Subject: [PATCH 1/2] Merged gdpr tests for banner bid requests --- modules/rubiconBidAdapter.js | 12 ++++ test/spec/modules/rubiconBidAdapter_spec.js | 79 +++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index dd716e6903b..453bc6e1fc1 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -228,6 +228,18 @@ export const spec = { 'tk_user_key', userId ]; + // add GDPR properties if enabled + if (config.getConfig('consentManagement')) { + if (bidRequest.gdprConsent && typeof bidRequest.gdprConsent === 'object') { + if (typeof bidRequest.gdprConsent.consentRequired === 'boolean') { + data.push( + 'gdpr', bidRequest.gdprConsent.consentRequired ? 1 : 0, + 'gdpr_consent', bidRequest.gdprConsent.consentString + ); + } + } + } + if (visitor !== null && typeof visitor === 'object') { utils._each(visitor, (item, key) => data.push(`tg_v.${key}`, item)); } diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js index 971ce7848e6..3bd73d84b2a 100644 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ b/test/spec/modules/rubiconBidAdapter_spec.js @@ -147,6 +147,10 @@ describe('the rubicon adapter', () => { bids: [ { bidder: 'rubicon', + gdprConsent: { + 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', + 'consentRequired': true + }, params: { accountId: '14062', siteId: '70608', @@ -535,6 +539,81 @@ describe('the rubicon adapter', () => { expect(window.DigiTrust.getUser.calledOnce).to.equal(true); }); }); + + it('should send GDPR params when enabled', () => { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + consentManagement: { + cmp: 'iab', + waitForConsentTimeout: 4000, + lookUpFailureResolution: 'cancel' + } + }; + return config[key]; + }); + + let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = parseQuery(request.data); + let expectedQuery = { + 'gdpr': '1', + 'gdpr_consent': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==' + }; + + // test that all values above are both present and correct + Object.keys(expectedQuery).forEach(key => { + let value = expectedQuery[key]; + expect(data[key]).to.equal(value); + }); + }); + + it('should not send GDPR params if not enabled', () => { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = {}; + return config[key]; + }); + + let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = parseQuery(request.data); + let expectedQuery = { + 'gdpr': undefined, + 'gdpr_consent': undefined + }; + + // test that all values above are both present and correct + Object.keys(expectedQuery).forEach(key => { + let value = expectedQuery[key]; + expect(data[key]).to.equal(value); + }); + }); + + it('should not send GDPR params if bidRequest does not pass gdprConsent', () => { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + consentManagement: { + cmp: 'iab', + waitForConsentTimeout: 4000, + lookUpFailureResolution: 'cancel' + } + }; + return config[key]; + }); + + // Remove gdprConsent from bidRequest + delete bidderRequest.bids[0].gdprConsent; + + let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = parseQuery(request.data); + let expectedQuery = { + 'gdpr': undefined, + 'gdpr_consent': undefined + }; + + // test that all values above are both present and correct + Object.keys(expectedQuery).forEach(key => { + let value = expectedQuery[key]; + expect(data[key]).to.equal(value); + }); + }); }); describe('for video requests', () => { From 20223031640c9b1718f448ade23d41692f850a22 Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Tue, 24 Apr 2018 10:59:22 -0700 Subject: [PATCH 2/2] Renamed the gdprConsent.consentRequired to gdprConsent.gdprApplies. Changed containing object used to access gdprConsent values (bidRequest -> bidderRequest) --- modules/rubiconBidAdapter.js | 21 ++++++------- test/spec/modules/rubiconBidAdapter_spec.js | 34 +++++++++------------ 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 453bc6e1fc1..d3735f01d62 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -178,9 +178,9 @@ export const spec = { data.slots.push(slotData); - if (bidderRequest && bidRequest.gdprConsent) { - data.gdpr = bidRequest.gdprConsent.consentRequired ? 1 : 0; - data.gdpr_consent = bidRequest.gdprConsent.consentString; + if (bidderRequest && bidderRequest.gdprConsent) { + data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; + data.gdpr_consent = bidderRequest.gdprConsent.consentString; } return { @@ -229,15 +229,12 @@ export const spec = { ]; // add GDPR properties if enabled - if (config.getConfig('consentManagement')) { - if (bidRequest.gdprConsent && typeof bidRequest.gdprConsent === 'object') { - if (typeof bidRequest.gdprConsent.consentRequired === 'boolean') { - data.push( - 'gdpr', bidRequest.gdprConsent.consentRequired ? 1 : 0, - 'gdpr_consent', bidRequest.gdprConsent.consentString - ); - } - } + if (config.getConfig('consentManagement') && + bidderRequest && bidderRequest.gdprConsent && typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { + data.push( + 'gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0, + 'gdpr_consent', bidderRequest.gdprConsent.consentString + ); } if (visitor !== null && typeof visitor === 'object') { diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js index 3bd73d84b2a..cc996041aac 100644 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ b/test/spec/modules/rubiconBidAdapter_spec.js @@ -15,20 +15,22 @@ describe('the rubicon adapter', () => { let sandbox, bidderRequest; + function addConsentManagement() { + bidderRequest.gdprConsent = { + 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', + 'gdprApplies': true + } + } + function createVideoBidderRequest() { - let bid = bidderRequest.bids[0]; + addConsentManagement(); + let bid = bidderRequest.bids[0]; bid.mediaTypes = { video: { context: 'instream' } }; - - bid.gdprConsent = { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'consentRequired': true - }; - bid.params.video = { 'language': 'en', 'p_aso.video.ext.skip': true, @@ -44,14 +46,11 @@ describe('the rubicon adapter', () => { } function createLegacyVideoBidderRequest() { - let bid = bidderRequest.bids[0]; + addConsentManagement(); + let bid = bidderRequest.bids[0]; // Legacy property (Prebid <1.0) bid.mediaType = 'video'; - bid.gdprConsent = { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'consentRequired': true - }; bid.params.video = { 'language': 'en', 'p_aso.video.ext.skip': true, @@ -147,10 +146,6 @@ describe('the rubicon adapter', () => { bids: [ { bidder: 'rubicon', - gdprConsent: { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'consentRequired': true - }, params: { accountId: '14062', siteId: '70608', @@ -541,6 +536,8 @@ describe('the rubicon adapter', () => { }); it('should send GDPR params when enabled', () => { + addConsentManagement(); + sandbox.stub(config, 'getConfig').callsFake((key) => { var config = { consentManagement: { @@ -586,7 +583,7 @@ describe('the rubicon adapter', () => { }); }); - it('should not send GDPR params if bidRequest does not pass gdprConsent', () => { + it('should not send GDPR params if gdprConsent is not set in config', () => { sandbox.stub(config, 'getConfig').callsFake((key) => { var config = { consentManagement: { @@ -598,9 +595,6 @@ describe('the rubicon adapter', () => { return config[key]; }); - // Remove gdprConsent from bidRequest - delete bidderRequest.bids[0].gdprConsent; - let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); let data = parseQuery(request.data); let expectedQuery = {