From 4dd0f3c6454ab88d5c050749f60abdce1aa61227 Mon Sep 17 00:00:00 2001 From: Love Sharma Date: Fri, 3 Dec 2021 17:15:28 -0500 Subject: [PATCH 1/3] ix infinite loop fix --- modules/ixBidAdapter.js | 28 +++++++++++++++++---- test/spec/modules/ixBidAdapter_spec.js | 34 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index af981a226c0..e3b57b06cfe 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -1,8 +1,8 @@ -import { deepAccess, parseGPTSingleSizeArray, inIframe, deepClone, logError, logWarn, isFn, contains, isInteger, isArray, deepSetValue, parseQueryStringParameters, isEmpty, mergeDeep, convertTypes } from '../src/utils.js'; +import { deepAccess, parseGPTSingleSizeArray, inIframe, deepClone, logError, logWarn, isFn, contains, isInteger, isArray, deepSetValue, parseQueryStringParameters, isEmpty, mergeDeep, convertTypes, hasDeviceAccess } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; import { EVENTS } from '../src/constants.json'; -import { getStorageManager } from '../src/storageManager.js'; +import { getStorageManager, validateStorageEnforcement } from '../src/storageManager.js'; import events from '../src/events.js'; import find from 'core-js-pure/features/array/find.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -40,6 +40,10 @@ export const ERROR_CODES = { PB_FPD_EXCEEDS_MAX_SIZE: 8, VIDEO_DURATION_INVALID: 9 }; +const DEFAULT_ENFORCEMENT_SETTINGS = { + hasEnforcementHook: false, + valid: hasDeviceAccess() +}; const FIRST_PARTY_DATA = { SITE: [ 'id', 'name', 'domain', 'cat', 'sectioncat', 'pagecat', 'page', 'ref', 'search', 'mobile', @@ -991,7 +995,7 @@ function createMissingBannerImp(bid, imp, newSize) { * * @param {ErrorData} data */ -function errorEventHandler(data) { +function storeErrorEventData(data) { if (!storage.localStorageIsEnabled()) { return; } @@ -1033,6 +1037,20 @@ function errorEventHandler(data) { storage.setDataInLocalStorage(LOCAL_STORAGE_KEY, JSON.stringify(currentStorage)); } +/** + * Event handler for storing data into local storage. It will only store data if + * local storage premissions are avaliable + */ +function localStorageHandler(data) { + if (data.type === 'ERROR' && data.arguments && data.arguments[1] && data.arguments[1].bidder === BIDDER_CODE) { + validateStorageEnforcement(GLOBAL_VENDOR_ID, BIDDER_CODE, DEFAULT_ENFORCEMENT_SETTINGS, (permissions) => { + if (permissions.valid) { + storeErrorEventData(data); + } + }); + } +} + /** * Get ixdiag stored in LocalStorage and format to be added to request payload * @@ -1129,8 +1147,8 @@ export const spec = { */ isBidRequestValid: function (bid) { if (!hasRegisteredHandler) { - events.on(EVENTS.AUCTION_DEBUG, errorEventHandler); - events.on(EVENTS.AD_RENDER_FAILED, errorEventHandler); + events.on(EVENTS.AUCTION_DEBUG, localStorageHandler); + events.on(EVENTS.AD_RENDER_FAILED, localStorageHandler); hasRegisteredHandler = true; } diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 32ce40f25cb..b2a6502cdc1 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -4,6 +4,7 @@ import { expect } from 'chai'; import { newBidder } from 'src/adapters/bidderFactory.js'; import { spec, storage, ERROR_CODES } from '../../../modules/ixBidAdapter.js'; import { createEidsArray } from 'modules/userId/eids.js'; +import { gdprDataHandler } from 'src/adapterManager.js'; describe('IndexexchangeAdapter', function () { const IX_SECURE_ENDPOINT = 'https://htlb.casalemedia.com/cygnus'; @@ -2614,6 +2615,7 @@ describe('IndexexchangeAdapter', function () { }); afterEach(() => { + gdprDataHandler.setConsentData(null); setDataInLocalStorageStub.restore(); getDataFromLocalStorageStub.restore(); removeDataFromLocalStorageStub.restore(); @@ -2806,5 +2808,37 @@ describe('IndexexchangeAdapter', function () { expect(JSON.parse(localStorageValues[key])[EXPIRED_DATE]).to.be.undefined; expect(JSON.parse(localStorageValues[key])).to.deep.equal({ [TODAY]: { '1': 1, '3': 8, '4': 1 } }) }); + + it('should not save error data into localstorage if consent is not given', () => { + gdprDataHandler.setConsentData({ + 'apiVersion': 2, + 'gdprApplies': true, + 'vendorData': { + 'purpose': { + 'consents': { + '1': true + } + }, + 'vendor': { + 'consents': { + '10': false + } + } + } + }); + + const bid = utils.deepClone(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]); + bid.params.size = ['400', 100]; + expect(spec.isBidRequestValid(bid)).to.be.false; + expect(localStorageValues[key]).to.be.undefined; + }); + + it('should not save error data into localstorage if deviceAccess is false', () => { + config.setConfig({ deviceAccess: false }); + const bid = utils.deepClone(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]); + bid.params.size = ['400', 100]; + expect(spec.isBidRequestValid(bid)).to.be.false; + expect(localStorageValues[key]).to.be.undefined; + }); }); }); From e08de8d747008ccb425f43ffda7e32a75c9afee4 Mon Sep 17 00:00:00 2001 From: Love Sharma Date: Mon, 6 Dec 2021 17:23:33 -0500 Subject: [PATCH 2/3] moved deviceaccess check --- modules/ixBidAdapter.js | 8 ++++---- test/spec/modules/ixBidAdapter_spec.js | 26 -------------------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index e3b57b06cfe..e7c4c0ecbf8 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -40,10 +40,6 @@ export const ERROR_CODES = { PB_FPD_EXCEEDS_MAX_SIZE: 8, VIDEO_DURATION_INVALID: 9 }; -const DEFAULT_ENFORCEMENT_SETTINGS = { - hasEnforcementHook: false, - valid: hasDeviceAccess() -}; const FIRST_PARTY_DATA = { SITE: [ 'id', 'name', 'domain', 'cat', 'sectioncat', 'pagecat', 'page', 'ref', 'search', 'mobile', @@ -1043,6 +1039,10 @@ function storeErrorEventData(data) { */ function localStorageHandler(data) { if (data.type === 'ERROR' && data.arguments && data.arguments[1] && data.arguments[1].bidder === BIDDER_CODE) { + const DEFAULT_ENFORCEMENT_SETTINGS = { + hasEnforcementHook: false, + valid: hasDeviceAccess() + }; validateStorageEnforcement(GLOBAL_VENDOR_ID, BIDDER_CODE, DEFAULT_ENFORCEMENT_SETTINGS, (permissions) => { if (permissions.valid) { storeErrorEventData(data); diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index b2a6502cdc1..af8e683de8b 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -4,7 +4,6 @@ import { expect } from 'chai'; import { newBidder } from 'src/adapters/bidderFactory.js'; import { spec, storage, ERROR_CODES } from '../../../modules/ixBidAdapter.js'; import { createEidsArray } from 'modules/userId/eids.js'; -import { gdprDataHandler } from 'src/adapterManager.js'; describe('IndexexchangeAdapter', function () { const IX_SECURE_ENDPOINT = 'https://htlb.casalemedia.com/cygnus'; @@ -2615,7 +2614,6 @@ describe('IndexexchangeAdapter', function () { }); afterEach(() => { - gdprDataHandler.setConsentData(null); setDataInLocalStorageStub.restore(); getDataFromLocalStorageStub.restore(); removeDataFromLocalStorageStub.restore(); @@ -2810,30 +2808,6 @@ describe('IndexexchangeAdapter', function () { }); it('should not save error data into localstorage if consent is not given', () => { - gdprDataHandler.setConsentData({ - 'apiVersion': 2, - 'gdprApplies': true, - 'vendorData': { - 'purpose': { - 'consents': { - '1': true - } - }, - 'vendor': { - 'consents': { - '10': false - } - } - } - }); - - const bid = utils.deepClone(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]); - bid.params.size = ['400', 100]; - expect(spec.isBidRequestValid(bid)).to.be.false; - expect(localStorageValues[key]).to.be.undefined; - }); - - it('should not save error data into localstorage if deviceAccess is false', () => { config.setConfig({ deviceAccess: false }); const bid = utils.deepClone(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]); bid.params.size = ['400', 100]; From 71b9c4943194a3b6f2941b6cbe8050729f01c4e8 Mon Sep 17 00:00:00 2001 From: Love Sharma Date: Tue, 7 Dec 2021 16:43:49 -0500 Subject: [PATCH 3/3] changed auction debug event handler --- modules/ixBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index 47434a7f42b..a2d690b18ee 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -1147,8 +1147,8 @@ export const spec = { */ isBidRequestValid: function (bid) { if (!hasRegisteredHandler) { - events.on(CONSTANTS.EVENTS.AUCTION_DEBUG, errorEventHandler); - events.on(CONSTANTS.EVENTS.AD_RENDER_FAILED, errorEventHandler); + events.on(CONSTANTS.EVENTS.AUCTION_DEBUG, localStorageHandler); + events.on(CONSTANTS.EVENTS.AD_RENDER_FAILED, localStorageHandler); hasRegisteredHandler = true; }