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

Fix request size validate #5951

Merged
merged 9 commits into from
Nov 17, 2020
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
38 changes: 9 additions & 29 deletions modules/relaidoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'relaido';
const BIDDER_DOMAIN = 'api.relaido.jp';
const ADAPTER_VERSION = '1.0.1';
const ADAPTER_VERSION = '1.0.2';
const DEFAULT_TTL = 300;
const UUID_KEY = 'relaido_uuid';

const storage = getStorageManager();

function isBidRequestValid(bid) {
if (!utils.isSafariBrowser() && !hasUuid()) {
utils.logWarn('uuid is not found.');
return false;
}
if (!utils.deepAccess(bid, 'params.placementId')) {
utils.logWarn('placementId param is reqeuired.');
return false;
Expand Down Expand Up @@ -64,7 +60,7 @@ function buildRequests(validBidRequests, bidderRequest) {
};

if (hasVideoMediaType(bidRequest)) {
const playerSize = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize');
const playerSize = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'));
payload.width = playerSize[0][0];
payload.height = playerSize[0][1];
} else if (hasBannerMediaType(bidRequest)) {
Expand Down Expand Up @@ -101,10 +97,6 @@ function interpretResponse(serverResponse, bidRequest) {
return [];
}

if (body.uuid) {
storage.setDataInLocalStorage(UUID_KEY, body.uuid);
}

const playerUrl = bidRequest.player || body.playerUrl;
const mediaType = bidRequest.mediaType || VIDEO;

Expand Down Expand Up @@ -141,7 +133,6 @@ function getUserSyncs(syncOptions, serverResponses) {
if (serverResponses.length > 0) {
syncUrl = utils.deepAccess(serverResponses, '0.body.syncUrl') || syncUrl;
}
receiveMessage();
return [{
type: 'iframe',
url: syncUrl
Expand Down Expand Up @@ -219,17 +210,6 @@ function outstreamRender(bid) {
});
}

function receiveMessage() {
window.addEventListener('message', setUuid);
}

function setUuid(e) {
if (utils.isPlainObject(e.data) && e.data.relaido_uuid) {
storage.setDataInLocalStorage(UUID_KEY, e.data.relaido_uuid);
window.removeEventListener('message', setUuid);
}
}

function isBannerValid(bid) {
if (!isMobile()) {
return false;
Expand All @@ -242,8 +222,8 @@ function isBannerValid(bid) {
}

function isVideoValid(bid) {
const playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize');
if (playerSize && utils.isArray(playerSize) && playerSize.length > 0) {
const playerSize = getValidSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize'));
if (playerSize.length > 0) {
const context = utils.deepAccess(bid, 'mediaTypes.video.context');
if (context && context === 'outstream') {
return true;
Expand All @@ -252,12 +232,12 @@ function isVideoValid(bid) {
return false;
}

function hasUuid() {
return !!storage.getDataFromLocalStorage(UUID_KEY);
}

function getUuid() {
return storage.getDataFromLocalStorage(UUID_KEY) || '';
const id = storage.getCookie(UUID_KEY)
if (id) return id;
const newId = utils.generateUUID();
storage.setCookie(UUID_KEY, newId);
return newId;
}

export function isMobile() {
Expand Down
14 changes: 6 additions & 8 deletions test/spec/modules/relaidoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { expect } from 'chai';
import { spec } from 'modules/relaidoBidAdapter.js';
import * as utils from 'src/utils.js';
import { getStorageManager } from '../../../src/storageManager.js';

const UUID_KEY = 'relaido_uuid';
const DEFAULT_USER_AGENT = window.navigator.userAgent;
const MOBILE_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1';
const relaido_uuid = 'hogehoge';

const setUADefault = () => { window.navigator.__defineGetter__('userAgent', function () { return DEFAULT_USER_AGENT }) };
const setUAMobile = () => { window.navigator.__defineGetter__('userAgent', function () { return MOBILE_USER_AGENT }) };

const storage = getStorageManager();
storage.setCookie(UUID_KEY, relaido_uuid);

describe('RelaidoAdapter', function () {
const relaido_uuid = 'hogehoge';
window.document.cookie = `${UUID_KEY}=${relaido_uuid}`
let bidRequest;
let bidderRequest;
let serverResponse;
Expand Down Expand Up @@ -65,7 +70,6 @@ describe('RelaidoAdapter', function () {
height: bidRequest.mediaTypes.video.playerSize[0][1],
mediaType: 'video',
};
localStorage.setItem(UUID_KEY, relaido_uuid);
});

describe('spec.isBidRequestValid', function () {
Expand Down Expand Up @@ -140,12 +144,6 @@ describe('RelaidoAdapter', function () {
setUADefault();
});

it('should return false when the uuid are missing', function () {
localStorage.removeItem(UUID_KEY);
const result = !!(utils.isSafariBrowser());
expect(spec.isBidRequestValid(bidRequest)).to.equal(result);
});

it('should return false when the placementId params are missing', function () {
bidRequest.params.placementId = undefined;
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
Expand Down