Skip to content

Commit

Permalink
override site.page with current location when publisher overrides ort…
Browse files Browse the repository at this point in the history
…b2 object with wrong values
  • Loading branch information
antoinezaz committed Jan 16, 2025
1 parent 862893d commit ba804f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions modules/oguryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const converter = ortbConverter({
const req = buildRequest(imps, bidderRequest, context);
req.tmax = DEFAULT_TIMEOUT;
deepSetValue(req, 'device.pxratio', window.devicePixelRatio);
deepSetValue(req, 'site.page', getWindowContext().location.href);

req.ext = mergeDeep({}, req.ext, {
adapterversion: ADAPTER_VERSION,
Expand Down
28 changes: 25 additions & 3 deletions test/spec/modules/oguryBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { spec } from 'modules/oguryBidAdapter';
import * as utils from 'src/utils.js';
import {server} from '../../mocks/xhr.js';
import { server } from '../../mocks/xhr.js';

const BID_URL = 'https://mweb-hb.presage.io/api/header-bidding-request';
const TIMEOUT_URL = 'https://ms-ads-monitoring-events.presage.io/bid_timeout'

describe('OguryBidAdapter', () => {
let bidRequests, bidderRequestBase, ortb2;

const currentLocation = 'https://mwtt.ogury.tech/advanced';

bidRequests = [
{
adUnitCode: 'adUnitCode',
Expand Down Expand Up @@ -76,8 +79,8 @@ describe('OguryBidAdapter', () => {
site: {
domain: 'mwtt.ogury.tech',
publisher: { domain: 'ogury.tech', id: 'ca06d4199b92bf6808e5ce15b28c6d30' },
page: 'https://mwtt.ogury.tech/advanced',
ref: 'https://mwtt.ogury.tech/advanced'
page: currentLocation,
ref: 'https://google.com'
},
user: {
ext: {
Expand Down Expand Up @@ -661,6 +664,7 @@ describe('OguryBidAdapter', () => {
});

describe('buildRequests', () => {
let windowTopStub;
const stubbedCurrentTime = 1234567890
const stubbedDevicePixelRatio = 1
const stubbedCurrentTimeMethod = sinon.stub(document.timeline, 'currentTime').get(function() {
Expand Down Expand Up @@ -703,6 +707,7 @@ describe('OguryBidAdapter', () => {
expect(dataRequest.regs).to.deep.equal(ortb2.regs);
expect(dataRequest.site).to.deep.equal({
...ortb2.site,
page: currentLocation,
id: bidRequests[0].params.assetKey
});

Expand All @@ -727,6 +732,15 @@ describe('OguryBidAdapter', () => {
expect(dataRequest.device.pxratio).to.be.a('number');
}

beforeEach(() => {
windowTopStub = sinon.stub(utils, 'getWindowTop');
windowTopStub.returns({ location: { href: currentLocation } });
});

afterEach(() => {
windowTopStub.restore();
});

after(() => {
stubbedCurrentTimeMethod.restore();
stubbedDevicePixelMethod.restore();
Expand Down Expand Up @@ -836,6 +850,14 @@ describe('OguryBidAdapter', () => {
const request = spec.buildRequests(validBidRequests, bidderRequest);
expect(request.data.imp[0].ext.gpid).to.equal(bidRequests[0].adUnitCode);
});

it('should set the actual site location in site.page when the ORTB object contains the referrer instead of the current location', () => {
const bidderRequest = utils.deepClone(bidderRequestBase);
bidderRequest.ortb2.site.page = 'https://google.com';

const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.data.site.page).to.equal(currentLocation);
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit ba804f9

Please sign in to comment.