Skip to content

Commit

Permalink
[BUGFIX] AdagioBidAdapter getDataFromLocalStorage (#5081)
Browse files Browse the repository at this point in the history
* AdagioBidAdapter: fix getDataFromLocalStorage

* AdagioBidAdapter: bump fix version 2.2.1
  • Loading branch information
osazos authored Apr 20, 2020
1 parent 198f63e commit c0c8b58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 9 additions & 5 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import sha256 from 'crypto-js/sha256.js';
import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'adagio';
const VERSION = '2.2.0';
const VERSION = '2.2.1';
const FEATURES_VERSION = '1';
const ENDPOINT = 'https://mp.4dex.io/prebid';
const SUPPORTED_MEDIA_TYPES = ['banner'];
const ADAGIO_TAG_URL = 'https://script.4dex.io/localstore.js';
const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript';
const GVLID = 617;
const storage = getStorageManager(GVLID);
const storage = getStorageManager(GVLID, 'adagio');

export const ADAGIO_PUBKEY = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9el0+OEn6fvEh1RdVHQu4cnT0
Expand All @@ -23,10 +23,8 @@ t0b0lsHN+W4n9kitS/DZ/xnxWK/9vxhv0ZtL1LL/rwR5Mup7rmJbNtDoNBw4TIGj
pV6EP3MTLosuUEpLaQIDAQAB
-----END PUBLIC KEY-----`;

export function getAdagioScript() {
export function adagioScriptFromLocalStorageCb(ls) {
try {
const ls = storage.getDataFromLocalStorage(ADAGIO_LOCALSTORAGE_KEY);

if (!ls) {
utils.logWarn('Adagio Script not found');
return;
Expand Down Expand Up @@ -58,6 +56,12 @@ export function getAdagioScript() {
}
}

export function getAdagioScript() {
storage.getDataFromLocalStorage(ADAGIO_LOCALSTORAGE_KEY, (ls) => {
adagioScriptFromLocalStorageCb(ls)
});
}

function canAccessTopWindow() {
try {
if (utils.getWindowTop().location.href) {
Expand Down
14 changes: 7 additions & 7 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai';
import { getAdagioScript, spec } from 'modules/adagioBidAdapter.js';
import { adagioScriptFromLocalStorageCb, spec } from 'modules/adagioBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import * as utils from 'src/utils.js';

describe('adagioAdapter', () => {
let utilsMock;
const adapter = newBidder(spec);
const ENDPOINT = 'https://mp.4dex.io/prebid';
const VERSION = '2.2.0';
const VERSION = '2.2.1';

beforeEach(function() {
localStorage.removeItem('adagioScript');
Expand Down Expand Up @@ -738,7 +738,7 @@ describe('adagioAdapter', () => {
});
});

describe('getAdagioScript', () => {
describe('adagioScriptFromLocalStorageCb', () => {
const VALID_HASH = 'Lddcw3AADdQDrPtbRJkKxvA+o1CtScGDIMNRpHB3NnlC/FYmy/9RKXelKrYj/sjuWusl5YcOpo+lbGSkk655i8EKuDiOvK6ae/imxSrmdziIp+S/TA6hTFJXcB8k1Q9OIp4CMCT52jjXgHwX6G0rp+uYoCR25B1jHaHnpH26A6I=';
const INVALID_HASH = 'invalid';
const VALID_SCRIPT_CONTENT = 'var _ADAGIO=function(){};(_ADAGIO)();\n';
Expand All @@ -752,7 +752,7 @@ describe('adagioAdapter', () => {
utilsMock.expects('logWarn').withExactArgs('No hash found in Adagio script').never();
utilsMock.expects('logWarn').withExactArgs('Invalid Adagio script found').never();

getAdagioScript();
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY));

expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.equals('// hash: ' + VALID_HASH + '\n' + VALID_SCRIPT_CONTENT);
utilsMock.verify();
Expand All @@ -765,7 +765,7 @@ describe('adagioAdapter', () => {
utilsMock.expects('logWarn').withExactArgs('No hash found in Adagio script').never();
utilsMock.expects('logWarn').withExactArgs('Invalid Adagio script found').once();

getAdagioScript();
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY));

expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.be.null;
utilsMock.verify();
Expand All @@ -778,7 +778,7 @@ describe('adagioAdapter', () => {
utilsMock.expects('logWarn').withExactArgs('No hash found in Adagio script').never();
utilsMock.expects('logWarn').withExactArgs('Invalid Adagio script found').once();

getAdagioScript();
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY));

expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.be.null;
utilsMock.verify();
Expand All @@ -791,7 +791,7 @@ describe('adagioAdapter', () => {
utilsMock.expects('logWarn').withExactArgs('No hash found in Adagio script').once();
utilsMock.expects('logWarn').withExactArgs('Invalid Adagio script found').never();

getAdagioScript();
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY));

expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.be.null;
utilsMock.verify();
Expand Down

0 comments on commit c0c8b58

Please sign in to comment.