Skip to content

Commit

Permalink
Reject sizeless banner bids (prebid#1389)
Browse files Browse the repository at this point in the history
* Reject banner bids that don't have width and height

* Set banner as default and refactor into updated bidmanager

* Set size if adunit has one valid size and add test

* Set video mediaType for adapter video bid
  • Loading branch information
matthewlane authored and dbemiller committed Aug 10, 2017
1 parent 2e28621 commit 0dad8c3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/getintentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var GetIntentAdapter = function GetIntentAdapter() {
if (br.mediaType === 'video') {
bid.vastUrl = bidResponse.vast_url;
bid.descriptionUrl = bidResponse.vast_url;
bid.mediaType = 'video';
} else {
bid.ad = bidResponse.ad;
}
Expand Down
1 change: 1 addition & 0 deletions src/bidfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Bid(statusCode, bidRequest) {
this.height = 0;
this.statusMessage = _getStatus();
this.adId = _bidId;
this.mediaType = 'banner';

function _getStatus() {
switch (_statusCode) {
Expand Down
27 changes: 27 additions & 0 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,36 @@ exports.addBidResponse = function (adUnitCode, bid) {
utils.logError(errorMessage(`Video bid does not have required vastUrl property.`));
return false;
}
if (bid.mediaType === 'banner' && !validBidSize(bid)) {
utils.logError(errorMessage(`Banner bids require a width and height`));
return false;
}

return true;
}

// check that the bid has a width and height set
function validBidSize(bid) {
if ((bid.width || bid.width === 0) && (bid.height || bid.height === 0)) {
return true;
}

const adUnit = getBidderRequest(bid.bidderCode, adUnitCode);
const sizes = adUnit && adUnit.bids && adUnit.bids[0] && adUnit.bids[0].sizes;
const parsedSizes = utils.parseSizesInput(sizes);

// if a banner impression has one valid size, we assign that size to any bid
// response that does not explicitly set width or height
if (parsedSizes.length === 1) {
const [ width, height ] = parsedSizes[0].split('x');
bid.width = width;
bid.height = height;
return true;
}

return false;
}

// Postprocess the bids so that all the universal properties exist, no matter which bidder they came from.
// This should be called before addBidToAuction().
function prepareBidForAuction() {
Expand Down
42 changes: 42 additions & 0 deletions test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,48 @@ describe('bidmanager.js', function () {
assert.equal(addedBid1.adId, bid1.adId);
});

it('should not add banner bids that have no width or height', () => {
const bid = Object.assign({},
bidfactory.createBid(1),
{
width: undefined,
height: undefined
}
);

bidmanager.addBidResponse('adUnitCode', bid);

const addedBid = $$PREBID_GLOBAL$$._bidsReceived[$$PREBID_GLOBAL$$._bidsReceived.length - 1];

assert.notEqual(bid.adId, addedBid.adId);
});

it('should add banner bids that have no width or height but single adunit size', () => {
sinon.stub(utils, 'getBidderRequest', () => ({
bids: [{
sizes: [[300, 250]],
}]
}));

const bid = Object.assign({},
bidfactory.createBid(1),
{
width: undefined,
height: undefined
}
);

bidmanager.addBidResponse('adUnitCode', bid);

const addedBid = $$PREBID_GLOBAL$$._bidsReceived[$$PREBID_GLOBAL$$._bidsReceived.length - 1];

assert.equal(bid.adId, addedBid.adId);
assert.equal(addedBid.width, 300);
assert.equal(addedBid.height, 250);

utils.getBidderRequest.restore();
});

it('should not add native bids that do not have required assets', () => {
sinon.stub(utils, 'getBidRequest', () => ({
bidder: 'appnexusAst',
Expand Down
1 change: 0 additions & 1 deletion test/spec/modules/spotxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ describe('spotx adapter tests', () => {
expect(bid.bidderCode).to.equal('spotx');
expect(bid.statusMessage).to.equal('Bid returned empty or error response');
expect(bid.cpm).to.be.undefined;
expect(bid.mediaType).to.be.undefined;
expect(bid.vastUrl).to.be.undefined;

bidManager.addBidResponse.restore();
Expand Down

0 comments on commit 0dad8c3

Please sign in to comment.