diff --git a/modules/rtbhouseBidAdapter.js b/modules/rtbhouseBidAdapter.js index cd60925b2c75..678e156c5e65 100644 --- a/modules/rtbhouseBidAdapter.js +++ b/modules/rtbhouseBidAdapter.js @@ -73,8 +73,7 @@ export const spec = { isBidRequestValid: function (bid) { return !!(includes(REGIONS, bid.params.region) && bid.params.publisherId); }, - - buildRequests: function (validBidRequests) { + buildRequests: function (validBidRequests, bidderRequest) { const request = { id: validBidRequests[0].auctionId, imp: validBidRequests.map(slot => mapImpression(slot)), @@ -82,6 +81,14 @@ export const spec = { cur: DEFAULT_CURRENCY_ARR, test: validBidRequests[0].params.test || 0 }; + if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) { + const consentStr = (bidderRequest.gdprConsent.consentString) + ? bidderRequest.gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : ''; + const gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; + request.regs = {ext: {gdpr: gdpr}}; + request.user = {ext: {consent: consentStr}}; + }; + return { method: 'POST', url: buildEndpointUrl(validBidRequests[0].params.region), diff --git a/test/spec/modules/rtbhouseBidAdapter_spec.js b/test/spec/modules/rtbhouseBidAdapter_spec.js index 69bd3f40f72b..70f21d2c8681 100644 --- a/test/spec/modules/rtbhouseBidAdapter_spec.js +++ b/test/spec/modules/rtbhouseBidAdapter_spec.js @@ -4,7 +4,7 @@ import { newBidder } from 'src/adapters/bidderFactory'; const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; - +const consentStr = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; /** * Helpers */ @@ -79,12 +79,38 @@ describe('RTBHouseAdapter', () => { it('sends bid request to ENDPOINT via POST', () => { let bidRequest = Object.assign([], bidRequests); delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); expect(request.url).to.equal(buildEndpointUrl(bidRequest[0].params.region)); expect(request.method).to.equal('POST'); }); - }) + + it('should not populate GDPR if for non-EEA users', () => { + let bidRequest = Object.assign([], bidRequests); + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data).to.not.have.property('regs'); + expect(data).to.not.have.property('user'); + }); + + it('should populate GDPR and consent string if available for EEA users', () => { + let bidRequest = Object.assign([], bidRequests); + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true, consentString: consentStr}}); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); + }); + + it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', () => { + let bidRequest = Object.assign([], bidRequests); + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true}}); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal(''); + }); + }); describe('interpretResponse', () => { let response = [{