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

restrict outstream w/o renderer to PBS #3881

Merged
merged 5 commits into from
Jul 12, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,21 @@ const OPEN_RTB_PROTOCOL = {
const imp = { id: adUnit.code, ext, secure: _s2sConfig.secure };

if (banner) { imp.banner = banner; }
if (video) { imp.video = video; }

imps.push(imp);
if (video) {
if (video.context === 'outstream' && !adUnit.renderer) {
// Don't push oustream w/o renderer to request object.
utils.logError('Outstream bid without renderer cannot be sent to Prebid Server.');
} else {
imp.video = video;
}
}
if (imp.banner || imp.video) { imps.push(imp); }
});

if (!imps.length) {
utils.logError('Request to Prebid Server rejected due to invalid media type(s) in adUnit.')
return;
}
const request = {
id: s2sBidRequest.tid,
source: {tid: s2sBidRequest.tid},
Expand Down Expand Up @@ -626,6 +636,9 @@ const OPEN_RTB_PROTOCOL = {

if (utils.deepAccess(bid, 'ext.prebid.type') === VIDEO) {
bidObject.mediaType = VIDEO;
let sizes = bidRequest.sizes && bidRequest.sizes[0];
bidObject.playerHeight = sizes[0];
bidObject.playerWidth = sizes[1];

// try to get cache values from 'response.ext.prebid.cache'
// else try 'bid.ext.prebid.targeting' as fallback
Expand Down Expand Up @@ -721,17 +734,18 @@ export function PrebidServer() {
}

const request = protocolAdapter().buildRequest(s2sBidRequest, bidRequests, adUnitsWithSizes);
const requestJson = JSON.stringify(request);

ajax(
_s2sConfig.endpoint,
{
success: response => handleResponse(response, requestedBidders, bidRequests, addBidResponse, done),
error: done
},
requestJson,
{ contentType: 'text/plain', withCredentials: true }
);
const requestJson = request && JSON.stringify(request);
if (request && requestJson) {
ajax(
_s2sConfig.endpoint,
{
success: response => handleResponse(response, requestedBidders, bidRequests, addBidResponse, done),
error: done
},
requestJson,
{ contentType: 'text/plain', withCredentials: true }
);
}
};

/* Notify Prebid of bid responses so bids can get in the auction */
Expand Down
75 changes: 75 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,69 @@ const VIDEO_REQUEST = {
]
};

const OUTSTREAM_VIDEO_REQUEST = {
'account_id': '1',
'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5',
'max_bids': 1,
'timeout_millis': 1000,
'secure': 0,
'url': '',
'prebid_version': '1.4.0-pre',
'ad_units': [
{
'code': 'div-gpt-ad-1460505748561-0',
'sizes': [640, 480],
'mediaTypes': {
'video': {
playerSize: [[ 640, 480 ]],
context: 'outstream',
mimes: ['video/mp4']
},
banner: { sizes: [[300, 250]] }
},
'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c',
'bids': [
{
'bid_id': '123',
'bidder': 'appnexus',
'params': { 'placementId': '12349520' }
}
]
},
{
code: 'video1',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'outstream',
mimes: ['video/mp4']
}
},
bids: [
{
bidder: 'appnexus',
params: {
placementId: 13232385,
video: {
skippable: true,
playback_method: ['auto_play_sound_off']
}
}
}
],
renderer: {
url: 'http://cdn.adnxs.com/renderer/video/ANOutstreamVideo.js',
render: function (bid) {
ANOutstreamVideo.renderAd({
targetId: bid.adUnitCode,
adResponse: bid.adResponse,
});
}
}
}
]
};

let BID_REQUESTS;

const RESPONSE = {
Expand Down Expand Up @@ -390,6 +453,18 @@ describe('S2S Adapter', function () {
xhr.restore();
});

it('should not add outstrean without renderer', function() {
let ortb2Config = utils.deepClone(CONFIG);
ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'

config.setConfig({s2sConfig: ortb2Config});
adapter.callBids(OUTSTREAM_VIDEO_REQUEST, BID_REQUESTS, addBidResponse, done, ajax);

const requestBid = JSON.parse(requests[0].requestBody);
expect(requestBid.imp[0].banner).to.exist;
expect(requestBid.imp[0].video).to.not.exist;
});

it('exists and is a function', function () {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
Expand Down