Skip to content

Commit

Permalink
Adquery Bid Adapter : changes in adqueryIdSystem, fix auctionId leak (p…
Browse files Browse the repository at this point in the history
…rebid#10128)

* added referrer to bid request

* added referrer to bid request - tests

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1

* adquery/prebid_qid_work1
  • Loading branch information
adquery authored and Santiago Carabone committed Aug 22, 2023
1 parent 42db979 commit 9035097
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 75 deletions.
44 changes: 23 additions & 21 deletions modules/adqueryBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import { logInfo, buildUrl, triggerPixel, parseSizesInput } from '../src/utils.js';
import { getStorageManager } from '../src/storageManager.js';
import {buildUrl, logInfo, parseSizesInput, triggerPixel} from '../src/utils.js';

const ADQUERY_GVLID = 902;
const ADQUERY_BIDDER_CODE = 'adquery';
Expand All @@ -11,7 +10,6 @@ const ADQUERY_USER_SYNC_DOMAIN = ADQUERY_BIDDER_DOMAIN_PROTOCOL + '://' + ADQUER
const ADQUERY_DEFAULT_CURRENCY = 'PLN';
const ADQUERY_NET_REVENUE = true;
const ADQUERY_TTL = 360;
const storage = getStorageManager({bidderCode: ADQUERY_BIDDER_CODE});

/** @type {BidderSpec} */
export const spec = {
Expand Down Expand Up @@ -55,10 +53,6 @@ export const spec = {
* @return {Bid[]}
*/
interpretResponse: (response, request) => {
logInfo(request);
logInfo(response);

let qid = null;
const res = response && response.body && response.body.data;
let bidResponses = [];

Expand Down Expand Up @@ -87,17 +81,6 @@ export const spec = {
bidResponses.push(bidResponse);
logInfo('bidResponses', bidResponses);

if (res && res.qid) {
if (storage.getDataFromLocalStorage('qid')) {
qid = storage.getDataFromLocalStorage('qid');
if (qid && qid.includes('%7B%22')) {
storage.setDataInLocalStorage('qid', res.qid);
}
} else {
storage.setDataInLocalStorage('qid', res.qid);
}
}

return bidResponses;
},

Expand Down Expand Up @@ -189,8 +172,28 @@ export const spec = {
}

};

function buildRequest(validBidRequests, bidderRequest) {
let bid = validBidRequests;
logInfo('buildRequest: ', bid);

let userId = null;
if (window.qid) {
userId = window.qid;
}

if (bid.userId && bid.userId.qid) {
userId = bid.userId.qid
}

if (!userId) {
// onetime User ID
const randomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4)));
userId = randomValues.map(it => it.toString(36)).join().substring(20);

window.qid = userId;
}

let pageUrl = '';
if (bidderRequest && bidderRequest.refererInfo) {
pageUrl = bidderRequest.refererInfo.page || '';
Expand All @@ -199,11 +202,10 @@ function buildRequest(validBidRequests, bidderRequest) {
return {
v: '$prebid.version$',
placementCode: bid.params.placementId,
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
auctionId: bid.auctionId,
auctionId: null,
type: bid.params.type,
adUnitCode: bid.adUnitCode,
bidQid: storage.getDataFromLocalStorage('qid') || null,
bidQid: userId,
bidId: bid.bidId,
bidder: bid.bidder,
bidPageUrl: pageUrl,
Expand Down
75 changes: 45 additions & 30 deletions modules/adqueryIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {ajax} from '../src/ajax.js';
import {getStorageManager} from '../src/storageManager.js';
import {submodule} from '../src/hook.js';
import { isFn, isStr, isPlainObject, logError } from '../src/utils.js';
import {isFn, isPlainObject, isStr, logError, logInfo} from '../src/utils.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';

const MODULE_NAME = 'qid';
Expand Down Expand Up @@ -51,11 +51,7 @@ export const adqueryIdSubmodule = {
* @returns {{qid:Object}}
*/
decode(value) {
let qid = storage.getDataFromLocalStorage('qid');
if (isStr(qid)) {
return {qid: qid};
}
return (value && typeof value['qid'] === 'string') ? { 'qid': value['qid'] } : undefined;
return {qid: value}
},
/**
* performs action to obtain id and return a value in the callback's response argument
Expand All @@ -64,38 +60,57 @@ export const adqueryIdSubmodule = {
* @returns {IdResponse|undefined}
*/
getId(config) {
logInfo('adqueryIdSubmodule getId');
if (!isPlainObject(config.params)) {
config.params = {};
}
const url = paramOrDefault(config.params.url,

const url = paramOrDefault(
config.params.url,
`https://bidder.adquery.io/prebid/qid`,
config.params.urlArg);
config.params.urlArg
);

const resp = function (callback) {
let qid = storage.getDataFromLocalStorage('qid');
if (isStr(qid)) {
const responseObj = {qid: qid};
callback(responseObj);
} else {
const callbacks = {
success: response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
logError(error);
}
let qid = window.qid;

if (!qid) {
const ramdomValues = window.crypto.getRandomValues(new Uint32Array(4));
qid = (ramdomValues[0].toString(36) +
ramdomValues[1].toString(36) +
ramdomValues[2].toString(36) +
ramdomValues[3].toString(36))
.substring(0, 20);

const randomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4)));
qid = randomValues.map(it => it.toString(36)).join().substring(20);
logInfo('adqueryIdSubmodule ID QID GENERTAED:', qid);
}
logInfo('adqueryIdSubmodule ID QID:', qid);

const callbacks = {
success: response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
logError(error);
}
callback(responseObj);
},
error: error => {
logError(`${MODULE_NAME}: ID fetch encountered an error`, error);
callback();
}
};
ajax(url, callbacks, undefined, {method: 'GET'});
}
if (responseObj.qid) {
let myQid = responseObj.qid;
storage.setDataInLocalStorage('qid', myQid);
return callback(myQid);
}
callback();
},
error: error => {
logError(`${MODULE_NAME}: ID fetch encountered an error`, error);
callback();
}
};
ajax(url + '?qid=' + qid, callbacks, undefined, {method: 'GET'});
};
return {callback: resp};
},
Expand Down
37 changes: 13 additions & 24 deletions test/spec/modules/adqueryIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { adqueryIdSubmodule, storage } from 'modules/adqueryIdSystem.js';
import { server } from 'test/mocks/xhr.js';
import {adqueryIdSubmodule, storage} from 'modules/adqueryIdSystem.js';
import {server} from 'test/mocks/xhr.js';
import sinon from 'sinon';

const config = {
storage: {
Expand All @@ -18,7 +19,7 @@ describe('AdqueryIdSystem', function () {
});
});

describe('getId', function() {
describe('getId', function () {
let getDataFromLocalStorageStub;

beforeEach(function() {
Expand All @@ -29,44 +30,32 @@ describe('AdqueryIdSystem', function () {
getDataFromLocalStorageStub.restore();
});

it('gets a adqueryId', function() {
it('gets a adqueryId', function () {
const config = {
params: {}
};
const callbackSpy = sinon.spy();
const callback = adqueryIdSubmodule.getId(config).callback;
callback(callbackSpy);
const request = server.requests[0];
expect(request.url).to.eq(`https://bidder.adquery.io/prebid/qid`);
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'qid' }));
expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'});
expect(request.url).to.contains(`https://bidder.adquery.io/prebid/qid?qid=`);
request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({qid: '6dd9eab7dfeab7df6dd9ea'}));
expect(callbackSpy.lastCall.lastArg).to.deep.equal('6dd9eab7dfeab7df6dd9ea');
});

it('gets a cached adqueryId', function() {
const config = {
params: {}
};
getDataFromLocalStorageStub.withArgs('qid').returns('qid');

const callbackSpy = sinon.spy();
const callback = adqueryIdSubmodule.getId(config).callback;
callback(callbackSpy);
expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'});
});

it('allows configurable id url', function() {
it('allows configurable id url', function () {
const config = {
params: {
url: 'https://bidder.adquery.io'
url: 'https://another_bidder.adquery.io/qid'
}
};
const callbackSpy = sinon.spy();
const callback = adqueryIdSubmodule.getId(config).callback;
callback(callbackSpy);
const request = server.requests[0];
expect(request.url).to.eq('https://bidder.adquery.io');
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'testqid' }));
expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'testqid'});
expect(request.url).to.contains('https://another_bidder.adquery.io');
request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({qid: 'testqid'}));
expect(callbackSpy.lastCall.lastArg).to.deep.equal('testqid');
});
});
});

0 comments on commit 9035097

Please sign in to comment.