Skip to content

Commit

Permalink
PBS Bid Adapter : site should not exist when app is present (#9258)
Browse files Browse the repository at this point in the history
* Update prebidServerBidAdapter_spec.js

* Update prebidServerBidAdapter_spec.js

* fix test

* remove app from site test

* add site/app/dooh function

* fix config

* remove deepSetValue

* add to ortb converter

* add check

* add back publisher.id

* fix linting

* ortb conversion lib: leave only one of dooh, app, or site in the request

Co-authored-by: Demetrio Girardi <dgirardi@prebid.org>
  • Loading branch information
ChrisHuie and dgirardi authored Jan 25, 2023
1 parent fd95236 commit ff84384
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
20 changes: 19 additions & 1 deletion libraries/ortbConverter/processors/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {deepSetValue, mergeDeep} from '../../../src/utils.js';
import {deepSetValue, logWarn, mergeDeep} from '../../../src/utils.js';
import {bannerResponseProcessor, fillBannerImp} from './banner.js';
import {fillVideoImp, fillVideoResponse} from './video.js';
import {setResponseMediaType} from './mediaType.js';
Expand All @@ -20,6 +20,10 @@ export const DEFAULT_PROCESSORS = {
appFpd: fpdFromTopLevelConfig('app'),
siteFpd: fpdFromTopLevelConfig('site'),
deviceFpd: fpdFromTopLevelConfig('device'),
onlyOneClient: {
priority: -99,
fn: onlyOneClientSection
},
props: {
// sets request properties id, tmax, test, source.tid
fn(ortbRequest, bidderRequest) {
Expand Down Expand Up @@ -133,3 +137,17 @@ function fpdFromTopLevelConfig(prop) {
}
}
}

export function onlyOneClientSection(ortbRequest) {
['dooh', 'app', 'site'].reduce((found, section) => {
if (ortbRequest[section] != null && Object.keys(ortbRequest[section]).length > 0) {
if (found != null) {
logWarn(`ORTB request specifies both '${found}' and '${section}'; dropping the latter.`)
delete ortbRequest[section];
} else {
found = section;
}
}
return found;
}, null);
}
2 changes: 1 addition & 1 deletion modules/prebidServerBidAdapter/ortbConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const PBS_CONVERTER = ortbConverter({
request.tmax = s2sBidRequest.s2sConfig.timeout;
deepSetValue(request, 'source.tid', proxyBidderRequest.auctionId);

[request.app, request.site].forEach(section => {
[request.app, request.dooh, request.site].forEach(section => {
if (section && !section.publisher?.id) {
deepSetValue(section, 'publisher.id', s2sBidRequest.s2sConfig.accountId);
}
Expand Down
22 changes: 22 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,28 @@ describe('S2S Adapter', function () {
});
});

it('site should not be present when app is present', function () {
const _config = {
s2sConfig: CONFIG,
app: { bundle: 'com.test.app' },
site: {
publisher: {
id: '1234',
domain: 'test.com'
},
content: {
language: 'en'
}
}
};

config.setConfig(_config);
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
const requestBid = JSON.parse(server.requests[0].requestBody);
expect(requestBid.site).to.not.exist;
expect(requestBid.app).to.exist.and.to.be.a('object');
});

it('adds appnexus aliases to request', function () {
config.setConfig({ s2sConfig: CONFIG });

Expand Down
23 changes: 23 additions & 0 deletions test/spec/ortbConverter/default_processors_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {onlyOneClientSection} from '../../../libraries/ortbConverter/processors/default.js';

describe('onlyOneClientSection', () => {
[
[['app'], 'app'],
[['site'], 'site'],
[['dooh'], 'dooh'],
[['app', 'site'], 'app'],
[['dooh', 'app', 'site'], 'dooh'],
[['dooh', 'site'], 'dooh']
].forEach(([sections, winner]) => {
it(`should leave only ${winner} in request when it contains ${sections.join(', ')}`, () => {
const req = Object.fromEntries(sections.map(s => [s, {foo: 'bar'}]));
onlyOneClientSection(req);
expect(Object.keys(req)).to.eql([winner]);
})
});
it('should not choke if none of the sections are in the request', () => {
const req = {};
onlyOneClientSection(req);
expect(req).to.eql({});
});
});

0 comments on commit ff84384

Please sign in to comment.