Skip to content
Open
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
23 changes: 19 additions & 4 deletions modules/adoceanBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _each, isStr, isArray, parseSizesInput } from '../src/utils.js';
import { _each, isStr, isArray, isPlainObject, parseSizesInput } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

Expand All @@ -8,14 +8,18 @@ const URL_SAFE_FIELDS = {
slaves: true
};

function buildEndpointUrl(emitter, payloadMap) {
function buildEndpointUrl(emitter, payloadMap, emitterRequestParams) {
const payload = [];
_each(payloadMap, function(v, k) {
payload.push(k + '=' + (URL_SAFE_FIELDS[k] ? v : encodeURIComponent(v)));
});

const randomizedPart = Math.random().toString().slice(2);
return 'https://' + emitter + '/_' + randomizedPart + '/ad.json?' + payload.join('&');
let request = 'https://' + emitter + '/_' + randomizedPart + '/ad.json?' + payload.join('&');
if (emitterRequestParams.length) {
request += '&' + emitterRequestParams.join('&');
}
return request;
}
Comment on lines +11 to 23

function buildRequest(bid, gdprConsent) {
Expand All @@ -35,6 +39,13 @@ function buildRequest(bid, gdprConsent) {
payload.aouserid = bid.userId.gemiusId;
}

const emitterRequestParams = [];
if (bid.params.emitterRequestParams) {
_each(bid.params.emitterRequestParams, function(v, k) {
emitterRequestParams.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject emitterRequestParams that overwrite generated query fields

When a publisher config includes a key that the adapter already generates, such as id, slaves, gdpr, gdpr_consent, or aosize, this appends a second copy of that query parameter after the trusted value. For parsers that take the last value, the bidder can receive a different placement, consent flag, or size than Prebid computed; at minimum the request becomes ambiguous for those inputs. Since these are documented as extra parameters, please skip or reject keys that collide with the adapter payload before appending them.

Useful? React with 👍 / 👎.

});
}
Comment on lines +42 to +47

const bidIdMap = {};
const uniquePartLength = 10;

Expand All @@ -60,7 +71,7 @@ function buildRequest(bid, gdprConsent) {

return {
method: 'GET',
url: buildEndpointUrl(emitter, payload),
url: buildEndpointUrl(emitter, payload, emitterRequestParams),
data: '',
bidIdMap: bidIdMap
};
Expand Down Expand Up @@ -110,6 +121,10 @@ export const spec = {
return false;
}

if (bid.params.emitterRequestParams && !isPlainObject(bid.params.emitterRequestParams)) {
return false;
}

if (bid.mediaTypes.banner) {
return true;
}
Expand Down
10 changes: 8 additions & 2 deletions modules/adoceanBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ Banner and video formats are supported.
params: {
slaveId: 'adoceanmyaotcpiltmmnj',
masterId: 'ek1AWtSWh3BOa_x2P1vlMQ_uXXJpJcbhsHAY5PFQjWD.D7',
emitter: 'myao.adocean.pl'
emitter: 'myao.adocean.pl',
emitterRequestParams: { // optional, extra parameters
"test_parameter": "1"
}
}
}
]
Expand All @@ -49,7 +52,10 @@ Banner and video formats are supported.
params: {
slaveId: 'adoceanmyaonenfcoqfnd',
masterId: '2k6gA7RWl08Zn0bi42RV8LNCANpKb6LqhvKzbmK3pzP.U7',
emitter: 'myao.adocean.pl'
emitter: 'myao.adocean.pl',
emitterRequestParams: { // optional, extra parameters
"test_parameter": "1"
}
}
}
]
Expand Down
40 changes: 40 additions & 0 deletions test/spec/modules/adoceanBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ describe('AdoceanAdapter', function () {
it('should return false for outstream video', function () {
expect(spec.isBidRequestValid(videoOutstreamBid)).to.equal(false);
});

it('should return true when emitterRequestParams is a plain object', function () {
const bid = Object.assign({}, bannerBid, {
params: Object.assign({}, bannerBid.params, { emitterRequestParams: { foo: 'bar' } })
});
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return true when emitterRequestParams is not provided', function () {
expect(spec.isBidRequestValid(bannerBid)).to.equal(true);
});

it('should return false when emitterRequestParams is an array', function () {
const bid = Object.assign({}, bannerBid, {
params: Object.assign({}, bannerBid.params, { emitterRequestParams: ['foo', 'bar'] })
});
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should return false when emitterRequestParams is a string', function () {
const bid = Object.assign({}, bannerBid, {
params: Object.assign({}, bannerBid.params, { emitterRequestParams: 'foo=bar' })
});
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests', function () {
Expand Down Expand Up @@ -211,6 +236,21 @@ describe('AdoceanAdapter', function () {
expect(request.url).to.include('maxdur=60');
expect(request.url).to.include('mindur=10');
});

it('should attach emitterRequestParams to url', function () {
const bidWithParams = deepClone(bidRequests[0]);
bidWithParams.params.emitterRequestParams = { myParam: 'myValue', another: 'test' };
const request = spec.buildRequests([bidWithParams], bidderRequest)[0];
expect(request.url).to.include('myParam=myValue');
expect(request.url).to.include('another=test');
});

it('should encode emitterRequestParams keys and values', function () {
const bidWithParams = deepClone(bidRequests[0]);
bidWithParams.params.emitterRequestParams = { 'special key': 'special value' };
const request = spec.buildRequests([bidWithParams], bidderRequest)[0];
expect(request.url).to.include('special%20key=special%20value');
});
});

describe('interpretResponseBanner', function () {
Expand Down
Loading