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

Conversation

jsnellbaker
Copy link
Collaborator

@jsnellbaker jsnellbaker commented Jun 22, 2021

Type of change

  • Bugfix

Description of change

Fixes #7046

There was an issue present in s2sConfigs if the publisher defined the endpoint (or syncEndpoint) object config but didn't define both p1Consent and noP1Consent fields. In this case, the field that was undefined would still try to make a call to PBS with an undefined URL for that type of user.

This PR addresses this scenario by blocking the call to PBS entirely if a particular URL field was undefined for that type of user. It will return an error for this scenario notifying what likely happened.

Also added a warning when evaluating the s2sConfig if one of these fields were undefined when using the object config.

TO NOTE:
Publishers still using the old string version of the endpoint (or syncEndpoint) fields or who relied on the defaultVendor feature to populate the endpoint URLs are unaffected by this scenario/fix. For the former, the single URL they define in the s2sConfig is still shared between consent/non-consent users. For the latter, the URLs are still read/assigned based on the configs defined in Prebid.js.

if (utils.isPlainObject(option[prop]) && (!option[prop].p1Consent || !option[prop].noP1Consent)) {
['p1Consent', 'noP1Consent'].forEach((conUrl) => {
if (!option[prop][conUrl]) {
utils.logWarn(`s2sConfig.${prop}.${conUrl} was not defined in manually set s2sConfig. This may prevent PBS requests from executing in certain cases. Please define field manually or instead use the defaultVendor settings of host company (if avialable).`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been encouraging folks to keep messages short because they don't minify.

How about something more terse like "s2sConfig.${prop}.${conUrl} not defined. PBS request will be skipped in some P1 scenarios."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, makes sense. updated.

@@ -1107,6 +1114,8 @@ export function PrebidServer() {
requestJson,
{ contentType: 'text/plain', withCredentials: true }
);
} else {
utils.logError('Prebid Server request did not execute. Please ensure endpoint URL(s) are properly defined in your s2sConfig. Otherwise check for warnings/errors, likely noted earlier in console logs...');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, with the goal of saving bytes in the package, how about something more terse like

"PBS request not made. Check endpoints."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@jsnellbaker
Copy link
Collaborator Author

updated messages and added unit test

@@ -1097,7 +1104,7 @@ 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) {
if (request && requestJson && getMatchingConsentUrl(s2sBidRequest.s2sConfig.endpoint, gdprConsent)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put the URL into a variable. Makes refactoring easier as there's only one place to look for

Comment on lines 509 to 521
it('should block request if config did not define proper 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);
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add two more test cases

  1. for p1Consent only configuration (which is probably the more common one)
  2. for an empty object
Suggested change
it('should block request if config did not define proper 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);
});
[
{ p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' },
{ noP1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' },
{ }
].forEach(endpoint => {
it('should block request if config did not define proper URL in endpoint object config', function() {
let badConfig = utils.deepClone(CONFIG);
badConfig.endpoint = 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);
});
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean add a test for when p1Consent is the only property defined and the request contains a no-consent scenario - to test that the request is blocked here as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for confirming. I added some tests guessing that was the case. Please take a look when you have the chance (in addition to the other change you suggested).

@muuki88
Copy link
Collaborator

muuki88 commented Jun 23, 2021

Thanks for the fast fix @jsnellbaker ❤️

Copy link
Collaborator

@muuki88 muuki88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix 👏 👏

modules/prebidServerBidAdapter/index.js Show resolved Hide resolved
@muuki88
Copy link
Collaborator

muuki88 commented Jul 12, 2021

@bretg is this good to go? We have some publishers that have way to many calls to /undefined 😉

@ChrisHuie ChrisHuie merged commit dc5f028 into master Jul 12, 2021
@ChrisHuie ChrisHuie deleted the pbs_config_consentUrl_fix branch July 12, 2021 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle undefined noP1Consent endpoint in pbs s2sConfig
5 participants