Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBS adapter - fix logic for undefined endpoint URLs #7076

Merged
merged 5 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ function formatUrlParams(option) {
let temp = option[prop];
option[prop] = { p1Consent: temp, noP1Consent: temp };
}
if (utils.isPlainObject(option[prop]) && (!option[prop].p1Consent || !option[prop].noP1Consent)) {
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
['p1Consent', 'noP1Consent'].forEach((conUrl) => {
if (!option[prop][conUrl]) {
utils.logWarn(`s2sConfig.${prop}.${conUrl} not defined. PBS request will be skipped in some P1 scenarios.`);
}
});
}
});
}

Expand Down Expand Up @@ -1097,16 +1104,19 @@ export function PrebidServer() {
const request = OPEN_RTB_PROTOCOL.buildRequest(s2sBidRequest, bidRequests, validAdUnits, s2sBidRequest.s2sConfig, requestedBidders);
const requestJson = request && JSON.stringify(request);
utils.logInfo('BidRequest: ' + requestJson);
if (request && requestJson) {
const endpointUrl = getMatchingConsentUrl(s2sBidRequest.s2sConfig.endpoint, gdprConsent);
jsnellbaker marked this conversation as resolved.
Show resolved Hide resolved
if (request && requestJson && endpointUrl) {
ajax(
getMatchingConsentUrl(s2sBidRequest.s2sConfig.endpoint, gdprConsent),
endpointUrl,
{
success: response => handleResponse(response, requestedBidders, bidRequests, addBidResponse, done, s2sBidRequest.s2sConfig),
error: done
},
requestJson,
{ contentType: 'text/plain', withCredentials: true }
);
} else {
utils.logError('PBS request not made. Check endpoints.');
}
}
};
Expand Down
54 changes: 54 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,60 @@ describe('S2S Adapter', function () {
resetSyncedStatus();
});

it('should block request if config did not define p1Consent URL in endpoint object config', function() {
let badConfig = utils.deepClone(CONFIG);
badConfig.endpoint = { noP1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' };
config.setConfig({ s2sConfig: badConfig });

let badCfgRequest = utils.deepClone(REQUEST);
badCfgRequest.s2sConfig = badConfig;

adapter.callBids(badCfgRequest, BID_REQUESTS, addBidResponse, done, ajax);

expect(server.requests.length).to.equal(0);
});

it('should block request if config did not define noP1Consent URL in endpoint object config', function() {
let badConfig = utils.deepClone(CONFIG);
badConfig.endpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' };
config.setConfig({ s2sConfig: badConfig });

let badCfgRequest = utils.deepClone(REQUEST);
badCfgRequest.s2sConfig = badConfig;

let badBidderRequest = utils.deepClone(BID_REQUESTS);
badBidderRequest[0].gdprConsent = {
consentString: 'abc123',
addtlConsent: 'superduperconsent',
jsnellbaker marked this conversation as resolved.
Show resolved Hide resolved
gdprApplies: true,
apiVersion: 2,
vendorData: {
purpose: {
consents: {
1: false
}
}
}
};

adapter.callBids(badCfgRequest, badBidderRequest, addBidResponse, done, ajax);

expect(server.requests.length).to.equal(0);
});

it('should block request if config did not define any URLs in endpoint object config', function() {
let badConfig = utils.deepClone(CONFIG);
badConfig.endpoint = {};
config.setConfig({ s2sConfig: badConfig });

let badCfgRequest = utils.deepClone(REQUEST);
badCfgRequest.s2sConfig = badConfig;

adapter.callBids(badCfgRequest, BID_REQUESTS, addBidResponse, done, ajax);

expect(server.requests.length).to.equal(0);
});

it('should not add outstrean without renderer', function () {
config.setConfig({ s2sConfig: CONFIG });

Expand Down