From ba804f9b42dc337d2a534d3b2642269746bf7c8f Mon Sep 17 00:00:00 2001 From: antoinezaz Date: Thu, 16 Jan 2025 17:30:53 +0100 Subject: [PATCH] override site.page with current location when publisher overrides ortb2 object with wrong values --- modules/oguryBidAdapter.js | 1 + test/spec/modules/oguryBidAdapter_spec.js | 28 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/oguryBidAdapter.js b/modules/oguryBidAdapter.js index 334f8a40390..d4e5fea1cf0 100644 --- a/modules/oguryBidAdapter.js +++ b/modules/oguryBidAdapter.js @@ -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, diff --git a/test/spec/modules/oguryBidAdapter_spec.js b/test/spec/modules/oguryBidAdapter_spec.js index cddfd0d0bf2..369540de668 100644 --- a/test/spec/modules/oguryBidAdapter_spec.js +++ b/test/spec/modules/oguryBidAdapter_spec.js @@ -1,7 +1,8 @@ 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' @@ -9,6 +10,8 @@ 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', @@ -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: { @@ -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() { @@ -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 }); @@ -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(); @@ -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 () {