Skip to content

Commit

Permalink
Fixed getConfig cleanup of consent management (Issue prebid#10658)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wazabit committed May 27, 2024
1 parent 6e07e00 commit a740a11
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 21 deletions.
20 changes: 11 additions & 9 deletions modules/aidemBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const LOCAL_BASE_URL = 'http://127.0.0.1:8787';
const SUPPORTED_MEDIA_TYPES = [BANNER, VIDEO];
const REQUIRED_VIDEO_PARAMS = [ 'mimes', 'protocols', 'context' ];

const pbjsVersion = '$prebid.version$';

export const ERROR_CODES = {
BID_SIZE_INVALID_FORMAT: 1,
BID_SIZE_NOT_INCLUDED: 2,
Expand Down Expand Up @@ -59,7 +61,7 @@ const converter = ortbConverter({
const request = buildRequest(imps, bidderRequest, context);
deepSetValue(request, 'at', 1);
setPrebidRequestEnvironment(request);
deepSetValue(request, 'regs', getRegs());
deepSetValue(request, 'regs', getRegs(bidderRequest));
deepSetValue(request, 'site.publisher.id', bidderRequest.bids[0].params.publisherId);
deepSetValue(request, 'site.id', bidderRequest.bids[0].params.siteId);
return request;
Expand Down Expand Up @@ -106,22 +108,22 @@ function recur(obj) {
return result;
}

function getRegs() {
function getRegs(bidderRequest) {
let regs = {};
const consentManagement = config.getConfig('consentManagement');
const euConsentManagement = bidderRequest.gdprConsent;
const usConsentManagement = bidderRequest.uspConsent;
const coppa = config.getConfig('coppa');
if (consentManagement && !!(consentManagement.gdpr)) {
deepSetValue(regs, 'gdpr_applies', !!consentManagement.gdpr);
if (euConsentManagement && euConsentManagement.consentString) {
deepSetValue(regs, 'gdpr_applies', !!euConsentManagement.consentString);
} else {
deepSetValue(regs, 'gdpr_applies', false);
}
if (consentManagement && deepAccess(consentManagement, 'usp.cmpApi') === 'static') {
deepSetValue(regs, 'usp_applies', !!deepAccess(consentManagement, 'usp'));
deepSetValue(regs, 'us_privacy', deepAccess(consentManagement, 'usp.consentData.getUSPData.uspString'));
if (usConsentManagement) {
deepSetValue(regs, 'usp_applies', true);
deepSetValue(regs, 'us_privacy', bidderRequest.uspConsent);
} else {
deepSetValue(regs, 'usp_applies', false);
}

if (isBoolean(coppa)) {
deepSetValue(regs, 'coppa_applies', !!coppa);
} else {
Expand Down
73 changes: 61 additions & 12 deletions test/spec/modules/aidemBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const DEFAULT_VALID_BANNER_REQUESTS = [
},
params: {
siteId: '1',
placementId: '13144370'
placementId: '13144370',
},
src: 'client',
transactionId: 'db739693-9b4a-4669-9945-8eab938783cc'
Expand All @@ -193,7 +193,7 @@ const DEFAULT_VALID_VIDEO_REQUESTS = [
},
params: {
siteId: '1',
placementId: '13144370'
placementId: '13144370',
},
src: 'client',
transactionId: 'db739693-9b4a-4669-9945-8eab938783cc'
Expand All @@ -209,7 +209,27 @@ const VALID_BIDDER_REQUEST = {
params: {
placementId: '13144370',
siteId: '23434',
publisherId: '7689670753'
publisherId: '7689670753',
},
}
],
refererInfo: {
page: 'test-page',
domain: 'test-domain',
ref: 'test-referer'
},
}

const VALID_GDPR_BIDDER_REQUEST = {
auctionId: '19c97f22-5bd1-4b16-a128-80f75fb0a8a0',
bidderCode: 'aidem',
bidderRequestId: '1bbb7854dfa0d8',
bids: [
{
params: {
placementId: '13144370',
siteId: '23434',
publisherId: '7689670753',
},
}
],
Expand All @@ -218,6 +238,30 @@ const VALID_BIDDER_REQUEST = {
domain: 'test-domain',
ref: 'test-referer'
},
gdprConsent: {
consentString: 'test-gdpr-string'
}
}

const VALID_USP_BIDDER_REQUEST = {
auctionId: '19c97f22-5bd1-4b16-a128-80f75fb0a8a0',
bidderCode: 'aidem',
bidderRequestId: '1bbb7854dfa0d8',
bids: [
{
params: {
placementId: '13144370',
siteId: '23434',
publisherId: '7689670753',
},
}
],
refererInfo: {
page: 'test-page',
domain: 'test-domain',
ref: 'test-referer'
},
uspConsent: '1YYY'
}

const SERVER_RESPONSE_BANNER = {
Expand Down Expand Up @@ -601,19 +645,24 @@ describe('Aidem adapter', () => {
});

it(`should set gdpr to true`, function () {
config.setConfig({
/* config.setConfig({
consentManagement: {
consentManagement: {
gdpr: {
// any data here set gdpr to true
consentData: {
getTCData: {
tcString: 'Q1BsRDRFVVBsRDRFVUVXQUFBRU5DWkNBQUFBQUFBQUFBQUFBQUFBQUFBQUEuSUk3TmRfWF9fYlg5bi1fN182ZnQwZVkxZjlfcjM3dVF6RGhmTnMtOEYzTF9XX0x3WDMyRTdORjM2dHE0S21SNGt1MWJCSVFOdEhNblVEVW14YW9sVnJ6SHNhazJjcHlOS0pfSmtrbnNaZTJkWUdGOVBuOWxELVlLWjdfNV85X2Y1MlRfOV85Xy0zOXozXzlmX19fZHZfLV9fLXZqZl81OTluX3Y5ZlZfNzhfS2Y5X19fX19fLV9fX19fX19fX19fXzhB'
}
}
},
}
});
const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST);
}); */
const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_GDPR_BIDDER_REQUEST);
expect(data.regs.gdpr_applies).to.equal(true)
});

it(`should set usp_consent string`, function () {
config.setConfig({
/* config.setConfig({
consentManagement: {
usp: {
cmpApi: 'static',
Expand All @@ -624,13 +673,13 @@ describe('Aidem adapter', () => {
}
}
}
});
const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST);
}); */
const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_USP_BIDDER_REQUEST);
expect(data.regs.us_privacy).to.equal('1YYY')
});

it(`should not set usp_consent string`, function () {
config.setConfig({
/*config.setConfig({
consentManagement: {
usp: {
cmpApi: 'iab',
Expand All @@ -641,7 +690,7 @@ describe('Aidem adapter', () => {
}
}
}
});
});*/
const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST);
expect(data.regs.us_privacy).to.undefined
});
Expand Down

0 comments on commit a740a11

Please sign in to comment.