Skip to content

Commit

Permalink
PBjs Core : filter bidders from config when not server-side (#9632)
Browse files Browse the repository at this point in the history
* filter bidders from config when not server-side

* fixed prebid server spec

* added filter for allowUnknownBidderCodes

* added unit test
  • Loading branch information
Ryan Schweitzer authored May 6, 2023
1 parent d5bfdee commit 45867d4
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
6 changes: 5 additions & 1 deletion modules/prebidServerBidAdapter/ortbConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ const PBS_CONVERTER = ortbConverter({
deepSetValue(ortbRequest, 'ext.prebid', mergeDeep(ortbRequest.ext?.prebid || {}, context.s2sBidRequest.s2sConfig.extPrebid));
}

const fpdConfigs = Object.entries(context.s2sBidRequest.ortb2Fragments?.bidder || {}).map(([bidder, ortb2]) => ({
const fpdConfigs = Object.entries(context.s2sBidRequest.ortb2Fragments?.bidder || {}).filter(([bidder]) => {
const bidders = context.s2sBidRequest.s2sConfig.bidders;
const allowUnknownBidderCodes = context.s2sBidRequest.s2sConfig.allowUnknownBidderCodes;
return allowUnknownBidderCodes || (bidders && bidders.includes(bidder));
}).map(([bidder, ortb2]) => ({
bidders: [bidder],
config: {ortb2}
}));
Expand Down
97 changes: 96 additions & 1 deletion test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,7 @@ describe('S2S Adapter', function () {
};
const bcat = ['IAB25', 'IAB7-39'];
const badv = ['blockedAdv-1.com', 'blockedAdv-2.com'];
const allowedBidders = ['rubicon', 'appnexus'];
const allowedBidders = ['appnexus'];

const expected = allowedBidders.map(bidder => ({
bidders: [bidder],
Expand Down Expand Up @@ -2516,6 +2516,101 @@ describe('S2S Adapter', function () {
expect(parsedRequestBody.bcat).to.deep.equal(bcat);
});

it('passes first party data in request for unknown when allowUnknownBidderCodes is true', () => {
const cfg = { ...CONFIG, allowUnknownBidderCodes: true };
config.setConfig({ s2sConfig: cfg });

const clonedReq = {...REQUEST, s2sConfig: cfg}
const s2sBidRequest = utils.deepClone(clonedReq);
const bidRequests = utils.deepClone(BID_REQUESTS);

const commonSite = {
keywords: ['power tools'],
search: 'drill'
};
const commonUser = {
keywords: ['a', 'b'],
gender: 'M'
};

const site = {
content: {userrating: 4},
ext: {
data: {
pageType: 'article',
category: 'tools'
}
}
};
const user = {
yob: '1984',
geo: { country: 'ca' },
ext: {
data: {
registered: true,
interests: ['cars']
}
}
};
const bcat = ['IAB25', 'IAB7-39'];
const badv = ['blockedAdv-1.com', 'blockedAdv-2.com'];
const allowedBidders = ['appnexus', 'unknown'];

const expected = allowedBidders.map(bidder => ({
bidders: [bidder],
config: {
ortb2: {
site: {
content: { userrating: 4 },
ext: {
data: {
pageType: 'article',
category: 'tools'
}
}
},
user: {
yob: '1984',
geo: { country: 'ca' },
ext: {
data: {
registered: true,
interests: ['cars']
}
}
},
bcat: ['IAB25', 'IAB7-39'],
badv: ['blockedAdv-1.com', 'blockedAdv-2.com']
}
}
}));
const commonContextExpected = utils.mergeDeep({
'page': 'http://mytestpage.com',
'domain': 'mytestpage.com',
'publisher': {
'id': '1',
'domain': 'mytestpage.com'
}
}, commonSite);

const ortb2Fragments = {
global: {site: commonSite, user: commonUser, badv, bcat},
bidder: Object.fromEntries(allowedBidders.map(bidder => [bidder, {site, user, bcat, badv}]))
};

// adapter.callBids({ ...REQUEST, s2sConfig: cfg }, BID_REQUESTS, addBidResponse, done, ajax);

adapter.callBids(addFpdEnrichmentsToS2SRequest({...s2sBidRequest, ortb2Fragments}, bidRequests, cfg), bidRequests, addBidResponse, done, ajax);
const parsedRequestBody = JSON.parse(server.requests[0].requestBody);
// eslint-disable-next-line no-console
console.log(parsedRequestBody);
expect(parsedRequestBody.ext.prebid.bidderconfig).to.deep.equal(expected);
expect(parsedRequestBody.site).to.deep.equal(commonContextExpected);
expect(parsedRequestBody.user).to.deep.equal(commonUser);
expect(parsedRequestBody.badv).to.deep.equal(badv);
expect(parsedRequestBody.bcat).to.deep.equal(bcat);
});

describe('pbAdSlot config', function () {
it('should not send \"imp.ext.data.pbadslot\" if \"ortb2Imp.ext\" is undefined', function () {
const consentConfig = { s2sConfig: CONFIG };
Expand Down

0 comments on commit 45867d4

Please sign in to comment.