Skip to content

Commit

Permalink
Nativo Bid Adapter: added ntv_url qs param value validation (prebid#9334
Browse files Browse the repository at this point in the history
)

* Initial nativoBidAdapter document creation (js, md and spec)

* Fulling working prebid using nativoBidAdapter. Support for GDPR and CCPA in user syncs.

* Added defult size settings based on the largest ad unit. Added response body validation. Added consent to request url qs params.

* Changed bidder endpoint url

* Changed double quotes to single quotes.

* Reverted package-json.lock to remove modifications from PR

* Added optional bidder param 'url' so the ad server can force- match an existing placement

* Lint fix. Added space after if.

* Added new QS param to send various adUnit data to adapter endpopint

* Updated unit test for new QS param

* Added qs param to keep track of ad unit refreshes

* Updated bidMap key default value

* Updated refresh increment logic

* Refactored spread operator for IE11 support

* Updated isBidRequestValid check

* Refactored Object.enties to use Object.keys to fix CircleCI testing errors

* Updated bid mapping key creation to prioritize ad unit code over placementId

* Added filtering by ad, advertiser and campaign.

* Merged master

* Added more robust bidDataMap with multiple key access

* Deduped filer values

* Rolled back package.json

* Duped upstream/master's package.lock file ... not sure how it got changed in the first place

* Small refactor of filterData length check. Removed comparison with 0 since a length value of 0 is already falsy.

* Added bid sizes to request

* Fixed function name in spec. Added unit tests.

* Added priceFloor module support

* Added protection agains empty url parameter

* Changed ntv_url QS param to use referrer.location instead of referrer.page

* Removed testing 'only' flag

* Added ntv_url QS param value validation
  • Loading branch information
jsfledd authored and JacobKlein26 committed Feb 8, 2023
1 parent 54c2a40 commit fe9c46d
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 12 deletions.
56 changes: 44 additions & 12 deletions modules/nativoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,9 @@ export const spec = {
const floorPriceData = {}
let placementId, pageUrl
validBidRequests.forEach((bidRequest) => {
pageUrl = deepAccess(
bidRequest,
'params.url',
)
if (pageUrl == undefined || pageUrl === '') {
pageUrl = bidderRequest.refererInfo.location
}
pageUrl =
getPageUrlFromBidRequest(bidRequest) ||
bidderRequest.refererInfo.location

placementId = deepAccess(bidRequest, 'params.placementId')

Expand Down Expand Up @@ -380,10 +376,12 @@ export const spec = {
return syncs
}

body =
typeof response.body === 'string'
? JSON.parse(response.body)
: response.body
try {
body =
typeof response.body === 'string'
? JSON.parse(response.body)
: response.body
} catch (err) { return }

// Make sure we have valid content
if (!body || !body.seatbid || body.seatbid.length === 0) return
Expand Down Expand Up @@ -465,7 +463,7 @@ export function parseFloorPriceData(bidRequest) {
// Setup price floor data per media type
let mediaTypeData = bidMediaTypes[mediaType]
let mediaTypeFloorPriceData = {}
let mediaTypeSizes = mediaTypeData.sizes || mediaTypeData.playerSize || [];
let mediaTypeSizes = mediaTypeData.sizes || mediaTypeData.playerSize || []
// Step through each size of the media type so we can get floor data for each size per media type
mediaTypeSizes.forEach((size) => {
// Get floor price data per the getFloor method and respective media type / size combination
Expand Down Expand Up @@ -634,3 +632,37 @@ function appendFilterData(filter, filterData) {
filterData.forEach((ad) => filter.add(ad))
}
}

export function getPageUrlFromBidRequest(bidRequest) {
let paramPageUrl = deepAccess(bidRequest, 'params.url')

if (paramPageUrl == undefined) return

if (hasProtocol(paramPageUrl)) return paramPageUrl

paramPageUrl = addProtocol(paramPageUrl)

try {
const url = new URL(paramPageUrl)
return url.href
} catch (err) {}
}

export function hasProtocol(url) {
const protocolRegexp = /^http[s]?\:/
return protocolRegexp.test(url)
}

export function addProtocol(url) {
if (hasProtocol(url)) {
return url
}

let protocolPrefix = 'https:'

if (url.indexOf('//') !== 0) {
protocolPrefix += '//'
}

return `${protocolPrefix}${url}`
}
84 changes: 84 additions & 0 deletions test/spec/modules/nativoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
getMediaWildcardPrices,
sizeToString,
parseFloorPriceData,
getPageUrlFromBidRequest,
hasProtocol,
addProtocol,
} from '../../../modules/nativoBidAdapter'

describe('bidDataMap', function () {
Expand Down Expand Up @@ -647,3 +650,84 @@ describe('parseFloorPriceData', () => {
})
})
})

describe('hasProtocol', () => {
it('https://www.testpage.com', () => {
expect(hasProtocol('https://www.testpage.com')).to.be.true
})
it('http://www.testpage.com', () => {
expect(hasProtocol('http://www.testpage.com')).to.be.true
})
it('//www.testpage.com', () => {
expect(hasProtocol('//www.testpage.com')).to.be.false
})
it('www.testpage.com', () => {
expect(hasProtocol('www.testpage.com')).to.be.false
})
it('httpsgsjhgflih', () => {
expect(hasProtocol('httpsgsjhgflih')).to.be.false
})
})

describe('addProtocol', () => {
it('www.testpage.com', () => {
expect(addProtocol('www.testpage.com')).to.be.equal('https://www.testpage.com')
})
it('//www.testpage.com', () => {
expect(addProtocol('//www.testpage.com')).to.be.equal('https://www.testpage.com')
})
it('http://www.testpage.com', () => {
expect(addProtocol('http://www.testpage.com')).to.be.equal('http://www.testpage.com')
})
it('https://www.testpage.com', () => {
expect(addProtocol('https://www.testpage.com')).to.be.equal('https://www.testpage.com')
})
})

describe('getPageUrlFromBidRequest', () => {
const bidRequest = {}

beforeEach(() => {
bidRequest.params = {}
})

it('Returns undefined for no url param', () => {
const url = getPageUrlFromBidRequest(bidRequest)
expect(url).to.be.undefined
})

it('@testUrl', () => {
const url = getPageUrlFromBidRequest(bidRequest)
expect(url).to.be.undefined
})

it('https://www.testpage.com', () => {
bidRequest.params.url = 'https://www.testpage.com'
const url = getPageUrlFromBidRequest(bidRequest)
expect(url).not.to.be.undefined
})

it('https://www.testpage.com/test/path', () => {
bidRequest.params.url = 'https://www.testpage.com/test/path'
const url = getPageUrlFromBidRequest(bidRequest)
expect(url).not.to.be.undefined
})

it('www.testpage.com', () => {
bidRequest.params.url = 'www.testpage.com'
const url = getPageUrlFromBidRequest(bidRequest)
expect(url).not.to.be.undefined
})

it('http://www.testpage.com', () => {
bidRequest.params.url = 'http://www.testpage.com'
const url = getPageUrlFromBidRequest(bidRequest)
expect(url).not.to.be.undefined
})

it('//www.testpage.com', () => {
bidRequest.params.url = '//www.testpage.com'
const url = getPageUrlFromBidRequest(bidRequest)
expect(url).not.to.be.undefined
})
})

0 comments on commit fe9c46d

Please sign in to comment.