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

GumGum: handling misconfigured requests #5212

Merged
merged 8 commits into from
Jun 5, 2020
22 changes: 22 additions & 0 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const BID_ENDPOINT = `https://g2.gumgum.com/hbid/imp`
const DT_CREDENTIALS = { member: 'YcXr87z2lpbB' }
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 @@ -137,9 +139,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 @@ -286,6 +295,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