Skip to content

Commit

Permalink
Prebid Core: Handled edge cases for allowedAlternateBidderCodes funct…
Browse files Browse the repository at this point in the history
…ionality (prebid#8760)

* Changed net revenue to True

* handled edge cases

* Empty alternateBidderCodes will reject the bids

Co-authored-by: Azhar <[email protected]>
  • Loading branch information
2 people authored and jorgeluisrocha committed May 18, 2023
1 parent d6e5abe commit d32171e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export function newBidder(spec) {
let allowAlternateBidderCodes = bidderSettings.get(requestBidder, 'allowAlternateBidderCodes') || false;
let alternateBiddersList = bidderSettings.get(requestBidder, 'allowedAlternateBidderCodes');
if (!!responseBidder && !!requestBidder && requestBidder !== responseBidder) {
alternateBiddersList = isArray(alternateBiddersList) ? alternateBiddersList.map(val => val.trim().toLowerCase()).filter(val => !!val).filter(uniques) : alternateBiddersList;
if (!allowAlternateBidderCodes || (isArray(alternateBiddersList) && (alternateBiddersList[0] !== '*' && !alternateBiddersList.includes(responseBidder)))) {
return true;
}
Expand Down
29 changes: 27 additions & 2 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ describe('validate bid response: ', function () {
bids1 = Object.assign({},
bids[0],
{
bidderCode: 'validAlternateBidder',
adapterCode: 'knownAdapter1'
bidderCode: 'validalternatebidder',
adapterCode: 'knownadapter1'
}
);
logWarnSpy = sinon.spy(utils, 'logWarn');
Expand Down Expand Up @@ -1126,6 +1126,31 @@ describe('validate bid response: ', function () {
expect(logErrorSpy.callCount).to.equal(0);
});

it('should accept the bid, when allowedAlternateBidderCodes is marked as * (with space) and allowAlternateBidderCodes flag is true', function () {
bidderSettingStub.withArgs(CODE, 'allowAlternateBidderCodes').returns(true);
bidderSettingStub.withArgs(CODE, 'allowedAlternateBidderCodes').returns([' * ']);

const bidder = newBidder(spec);
spec.interpretResponse.returns(bids1);
bidder.callBids(bidRequest, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);

expect(addBidResponseStub.calledOnce).to.equal(true);
expect(logWarnSpy.callCount).to.equal(0);
expect(logErrorSpy.callCount).to.equal(0);
});

it('should not accept the bid, when allowedAlternateBidderCodes is marked as empty array and allowAlternateBidderCodes flag is true', function () {
bidderSettingStub.withArgs(CODE, 'allowAlternateBidderCodes').returns(true);
bidderSettingStub.withArgs(CODE, 'allowedAlternateBidderCodes').returns([]);

const bidder = newBidder(spec);
spec.interpretResponse.returns(bids1);
bidder.callBids(bidRequest, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);

expect(addBidResponseStub.calledOnce).to.equal(false);
expect(logWarnSpy.callCount).to.equal(1);
});

it('should accept the bid, when allowedAlternateBidderCodes contains bidder name and allowAlternateBidderCodes flag is true', function () {
bidderSettingStub.withArgs(CODE, 'allowAlternateBidderCodes').returns(true);
bidderSettingStub.withArgs(CODE, 'allowedAlternateBidderCodes').returns(['validAlternateBidder']);
Expand Down

0 comments on commit d32171e

Please sign in to comment.