Skip to content

Commit

Permalink
GumGum: handling misconfigured requests (#5212)
Browse files Browse the repository at this point in the history
* uses encodeURIComponent inline

* adds test for jcsi param

* adds request delay depending on previous response

* adds inVideo param
  • Loading branch information
susyt authored Jun 5, 2020
1 parent 77705e8 commit 8d00d1e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const ALIAS_BIDDER_CODE = ['gg']
const BID_ENDPOINT = `https://g2.gumgum.com/hbid/imp`
const SUPPORTED_MEDIA_TYPES = [BANNER, VIDEO]
const TIME_TO_LIVE = 60
const DELAY_REQUEST_TIME = 1800000; // setting to 30 mins

let invalidRequestIds = {};
let browserParams = {};
let pageViewId = null

Expand Down Expand Up @@ -132,9 +134,16 @@ function isBidRequestValid (bid) {
params,
adUnitCode
} = bid;
const id = params.inScreen || params.inScreenPubID || params.inSlot || params.ICV || params.video || params.inVideo;

if (invalidRequestIds[id]) {
utils.logWarn(`[GumGum] Please check the implementation for ${id} for the placement ${adUnitCode}`);
return false;
}

switch (true) {
case !!(params.inScreen): break;
case !!(params.inScreenPubID): break;
case !!(params.inSlot): break;
case !!(params.ICV): break;
case !!(params.video): break;
Expand Down Expand Up @@ -281,6 +290,19 @@ function buildRequests (validBidRequests, bidderRequest) {
function interpretResponse (serverResponse, bidRequest) {
const bidResponses = []
const serverResponseBody = serverResponse.body

if (!serverResponseBody || serverResponseBody.err) {
const data = bidRequest.data || {}
const id = data.t || data.si || data.ni || data.pubId;
const delayTime = serverResponseBody ? serverResponseBody.err.drt : DELAY_REQUEST_TIME;
invalidRequestIds[id] = { productId: data.pi, timestamp: new Date().getTime() };

setTimeout(() => {
!!invalidRequestIds[id] && delete invalidRequestIds[id];
}, delayTime);
utils.logWarn(`[GumGum] Please check the implementation for ${id}`);
}

const defaultResponse = {
ad: {
price: 0,
Expand Down
20 changes: 20 additions & 0 deletions test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ describe('gumgumAdapter', function () {
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should return false if invalid request id is found', function () {
const bidRequest = {
id: 12345,
sizes: [[300, 250], [1, 1]],
url: ENDPOINT,
method: 'GET',
pi: 3,
data: { t: '10433394' }
};
let body;
spec.interpretResponse({ body }, bidRequest); // empty response
expect(spec.isBidRequestValid(bid)).to.be.equal(false);
});
});

describe('buildRequests', function () {
Expand Down Expand Up @@ -341,6 +355,12 @@ describe('gumgumAdapter', function () {
expect(result.length).to.equal(0);
});

it('handles empty response', function () {
let body;
let result = spec.interpretResponse({ body }, bidRequest);
expect(result.length).to.equal(0);
});

it('returns 1x1 when eligible product and size available', function () {
let inscreenBidRequest = {
id: 12346,
Expand Down

0 comments on commit 8d00d1e

Please sign in to comment.