Skip to content

Commit

Permalink
Replace deprecated getWindowTopLocation with referrer detection module (
Browse files Browse the repository at this point in the history
prebid#3380)

* Backward compatible update & reduced TTL

* replaced deprecated getWindowTopLocation with referer detection module
  • Loading branch information
ix-prebid-support authored and mike-chowla committed Jan 2, 2019
1 parent be77fa5 commit 10a9111
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 55 deletions.
60 changes: 33 additions & 27 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ const ENDPOINT_VERSION = 7.2;
const CENT_TO_DOLLAR_FACTOR = 100;
const TIME_TO_LIVE = 35;
const NET_REVENUE = true;

// Always start by assuming the protocol is HTTPS. This way, it will work
// whether the page protocol is HTTP or HTTPS. Then check if the page is
// actually HTTP.If we can guarantee it is, then, and only then, set protocol to
// HTTP.
let isSecureWeb = true;
if (utils.getTopWindowLocation().protocol.indexOf('https') !== 0) {
isSecureWeb = false;
}
const baseUrl = isSecureWeb ? BANNER_SECURE_BID_URL : BANNER_INSECURE_BID_URL;

const PRICE_TO_DOLLAR_FACTOR = {
JPY: 1
};
Expand Down Expand Up @@ -193,6 +182,11 @@ export const spec = {
const bannerImps = [];
let validBidRequest = null;
let bannerImp = null;
// Always start by assuming the protocol is HTTPS. This way, it will work
// whether the page protocol is HTTP or HTTPS. Then check if the page is
// actually HTTP.If we can guarantee it is, then, and only then, set protocol to
// HTTP.
let baseUrl = BANNER_SECURE_BID_URL;

for (let i = 0; i < validBidRequests.length; i++) {
validBidRequest = validBidRequests[i];
Expand All @@ -209,29 +203,41 @@ export const spec = {

r.imp = bannerImps;
r.site = {};
r.site.page = utils.getTopWindowUrl();
r.site.ref = utils.getTopWindowReferrer();
r.ext = {};
r.ext.source = 'prebid';

if (document.referrer && document.referrer !== '') {
r.site.ref = document.referrer;
}

// Apply GDPR information to the request if GDPR is enabled.
if (options && options.gdprConsent) {
const gdprConsent = options.gdprConsent;
if (options) {
if (options.gdprConsent) {
const gdprConsent = options.gdprConsent;

if (gdprConsent.hasOwnProperty('gdprApplies')) {
r.regs = {
ext: {
gdpr: gdprConsent.gdprApplies ? 1 : 0
}
};
}

if (gdprConsent.hasOwnProperty('gdprApplies')) {
r.regs = {
ext: {
gdpr: gdprConsent.gdprApplies ? 1 : 0
}
};
if (gdprConsent.hasOwnProperty('consentString')) {
r.user = {
ext: {
consent: gdprConsent.consentString || ''
}
};
}
}

if (gdprConsent.hasOwnProperty('consentString')) {
r.user = {
ext: {
consent: gdprConsent.consentString || ''
}
};
if (options.refererInfo) {
r.site.page = options.refererInfo.referer;

if (options.refererInfo.referer && options.refererInfo.referer.indexOf('https') !== 0) {
baseUrl = BANNER_INSECURE_BID_URL;
}
}
}

Expand Down
90 changes: 62 additions & 28 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { newBidder } from 'src/adapters/bidderFactory';
import { spec } from 'modules/ixBidAdapter';

describe('IndexexchangeAdapter', function () {
const IX_ENDPOINT = 'http://as.casalemedia.com/cygnus';
const IX_INSECURE_ENDPOINT = 'http://as.casalemedia.com/cygnus';
const IX_SECURE_ENDPOINT = 'https://as-sec.casalemedia.com/cygnus';
const BIDDER_VERSION = 7.2;

const DEFAULT_BANNER_VALID_BID = [
Expand All @@ -28,6 +29,17 @@ describe('IndexexchangeAdapter', function () {
auctionId: '1aa2bb3cc4dd'
}
];
const DEFAULT_BANNER_OPTION = {
gdprConsent: {
gdprApplies: true,
consentString: '3huaa11=qu3198ae',
vendorData: {}
},
refererInfo: {
referer: 'http://www.prebid.org',
canonicalUrl: 'http://www.prebid.org/the/link/to/the/page'
}
};
const DEFAULT_BANNER_BID_RESPONSE = {
cur: 'USD',
id: '11a22b33c44d',
Expand Down Expand Up @@ -198,20 +210,20 @@ describe('IndexexchangeAdapter', function () {
});

describe('buildRequestsBanner', function () {
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID);
const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
const requestUrl = request.url;
const requestMethod = request.method;
const query = request.data;

const bidWithoutMediaType = utils.deepClone(DEFAULT_BANNER_VALID_BID);
delete bidWithoutMediaType[0].mediaTypes;
bidWithoutMediaType[0].sizes = [[300, 250], [300, 600]];
const requestWithoutMediaType = spec.buildRequests(bidWithoutMediaType);
const requestWithoutMediaType = spec.buildRequests(bidWithoutMediaType, DEFAULT_BANNER_OPTION);
const queryWithoutMediaType = requestWithoutMediaType.data;

it('request should be made to IX endpoint with GET method', function () {
expect(requestMethod).to.equal('GET');
expect(requestUrl).to.equal(IX_ENDPOINT);
expect(requestUrl).to.equal(IX_INSECURE_ENDPOINT);
});

it('query object (version, siteID and request) should be correct', function () {
Expand All @@ -227,10 +239,8 @@ describe('IndexexchangeAdapter', function () {

expect(payload.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidderRequestId);
expect(payload.site).to.exist;
expect(payload.site.page).to.exist;
expect(payload.site.page).to.contain('http');
expect(payload.site.ref).to.exist;
expect(payload.site.ref).to.be.a('string');
expect(payload.site.page).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer);
expect(payload.site.ref).to.equal(document.referrer);
expect(payload.ext).to.exist;
expect(payload.ext.source).to.equal('prebid');
expect(payload.imp).to.exist;
Expand Down Expand Up @@ -269,10 +279,8 @@ describe('IndexexchangeAdapter', function () {

expect(payload.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidderRequestId);
expect(payload.site).to.exist;
expect(payload.site.page).to.exist;
expect(payload.site.page).to.contain('http');
expect(payload.site.ref).to.exist;
expect(payload.site.ref).to.be.a('string');
expect(payload.site.page).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer);
expect(payload.site.ref).to.equal(document.referrer);
expect(payload.ext).to.exist;
expect(payload.ext.source).to.equal('prebid');
expect(payload.imp).to.exist;
Expand Down Expand Up @@ -340,9 +348,9 @@ describe('IndexexchangeAdapter', function () {
}
});

const requestWithFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID);
const requestWithFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
const pageUrl = JSON.parse(requestWithFirstPartyData.data.r).site.page;
const expectedPageUrl = `${utils.getTopWindowUrl()}?ab=123&cd=123%23ab&e%2Ff=456&h%3Fg=456%23cd`;
const expectedPageUrl = DEFAULT_BANNER_OPTION.refererInfo.referer + '?ab=123&cd=123%23ab&e%2Ff=456&h%3Fg=456%23cd';

expect(pageUrl).to.equal(expectedPageUrl);
});
Expand All @@ -354,29 +362,29 @@ describe('IndexexchangeAdapter', function () {
}
});

const requestFirstPartyDataNumber = spec.buildRequests(DEFAULT_BANNER_VALID_BID);
const requestFirstPartyDataNumber = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
const pageUrl = JSON.parse(requestFirstPartyDataNumber.data.r).site.page;

expect(pageUrl).to.equal(utils.getTopWindowUrl());
expect(pageUrl).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer);
});

it('should not set first party or timeout if it is not present', function () {
config.setConfig({
ix: {}
});

const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID);
const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
const pageUrl = JSON.parse(requestWithoutConfig.data.r).site.page;

expect(pageUrl).to.equal(utils.getTopWindowUrl());
expect(pageUrl).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer);
expect(requestWithoutConfig.data.t).to.be.undefined;
});

it('should not set first party or timeout if it is setConfig is not called', function () {
const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID);
const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
const pageUrl = JSON.parse(requestWithoutConfig.data.r).site.page;

expect(pageUrl).to.equal(utils.getTopWindowUrl());
expect(pageUrl).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer);
expect(requestWithoutConfig.data.t).to.be.undefined;
});

Expand Down Expand Up @@ -487,14 +495,7 @@ describe('IndexexchangeAdapter', function () {
});

it('bidrequest should have consent info if gdprApplies and consentString exist', function () {
const options = {
gdprConsent: {
gdprApplies: true,
consentString: '3huaa11=qu3198ae',
vendorData: {}
}
};
const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options);
const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION);
const requestWithConsent = JSON.parse(validBidWithConsent.data.r);

expect(requestWithConsent.regs.ext.gdpr).to.equal(1);
Expand Down Expand Up @@ -537,5 +538,38 @@ describe('IndexexchangeAdapter', function () {
expect(requestWithConsent.regs).to.be.undefined;
expect(requestWithConsent.user).to.be.undefined;
});

it('bidrequest should not have page if options is undefined', function () {
const options = {};
const validBidWithoutreferInfo = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options);
const requestWithoutreferInfo = JSON.parse(validBidWithoutreferInfo.data.r);

expect(requestWithoutreferInfo.site.page).to.be.undefined;
expect(validBidWithoutreferInfo.url).to.equal(IX_SECURE_ENDPOINT);
});

it('bidrequest should not have page if options.refererInfo is an empty object', function () {
const options = {
refererInfo: {}
};
const validBidWithoutreferInfo = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options);
const requestWithoutreferInfo = JSON.parse(validBidWithoutreferInfo.data.r);

expect(requestWithoutreferInfo.site.page).to.be.undefined;
expect(validBidWithoutreferInfo.url).to.equal(IX_SECURE_ENDPOINT);
});

it('bidrequest should sent to secure endpoint if page url is secure', function () {
const options = {
refererInfo: {
referer: 'https://www.prebid.org'
}
};
const validBidWithoutreferInfo = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options);
const requestWithoutreferInfo = JSON.parse(validBidWithoutreferInfo.data.r);

expect(requestWithoutreferInfo.site.page).to.equal(options.refererInfo.referer);
expect(validBidWithoutreferInfo.url).to.equal(IX_SECURE_ENDPOINT);
});
});
});

0 comments on commit 10a9111

Please sign in to comment.