diff --git a/modules/sharethroughBidAdapter.js b/modules/sharethroughBidAdapter.js index 68b2a23b8e4..ba683406588 100644 --- a/modules/sharethroughBidAdapter.js +++ b/modules/sharethroughBidAdapter.js @@ -1,6 +1,6 @@ import { registerBidder } from '../src/adapters/bidderFactory'; -const VERSION = '3.1.0'; +const VERSION = '3.2.0'; const BIDDER_CODE = 'sharethrough'; const STR_ENDPOINT = 'https://btlr.sharethrough.com/WYu2BXv1/v1'; const DEFAULT_SIZE = [1, 1]; @@ -9,7 +9,8 @@ const DEFAULT_SIZE = [1, 1]; export const sharethroughInternal = { b64EncodeUnicode, handleIframe, - isLockedInFrame + isLockedInFrame, + getProtocol }; export const sharethroughAdapterSpec = { @@ -29,6 +30,9 @@ export const sharethroughAdapterSpec = { strVersion: VERSION }; + const nonHttp = sharethroughInternal.getProtocol().indexOf('http') < 0; + query.secure = nonHttp || (sharethroughInternal.getProtocol().indexOf('https') > -1); + if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) { query.consent_string = bidderRequest.gdprConsent.consentString; } @@ -236,4 +240,8 @@ function canAutoPlayHTML5Video() { } } +function getProtocol() { + return document.location.protocol; +} + registerBidder(sharethroughAdapterSpec); diff --git a/test/spec/modules/sharethroughBidAdapter_spec.js b/test/spec/modules/sharethroughBidAdapter_spec.js index a8caefc5240..e3bd5aa079a 100644 --- a/test/spec/modules/sharethroughBidAdapter_spec.js +++ b/test/spec/modules/sharethroughBidAdapter_spec.js @@ -40,7 +40,7 @@ const bidRequests = [ const prebidRequests = [ { method: 'GET', - url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', data: { bidId: 'bidId', placement_key: 'pKey' @@ -52,7 +52,7 @@ const prebidRequests = [ }, { method: 'GET', - url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', data: { bidId: 'bidId', placement_key: 'pKey' @@ -64,7 +64,7 @@ const prebidRequests = [ }, { method: 'GET', - url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', data: { bidId: 'bidId', placement_key: 'pKey' @@ -77,7 +77,7 @@ const prebidRequests = [ }, { method: 'GET', - url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', data: { bidId: 'bidId', placement_key: 'pKey' @@ -89,7 +89,7 @@ const prebidRequests = [ }, { method: 'GET', - url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', data: { bidId: 'bidId', placement_key: 'pKey' @@ -120,9 +120,9 @@ const bidderResponse = { header: { get: (header) => header } }; -const setUserAgent = (str) => { +const setUserAgent = (uaString) => { window.navigator['__defineGetter__']('userAgent', function () { - return str; + return uaString; }); }; @@ -217,10 +217,8 @@ describe('sharethrough adapter spec', function () { it('should return an array of requests', function () { const builtBidRequests = spec.buildRequests(bidRequests); - expect(builtBidRequests[0].url).to.eq( - 'https://btlr.sharethrough.com/WYu2BXv1/v1'); - expect(builtBidRequests[1].url).to.eq( - 'https://btlr.sharethrough.com/WYu2BXv1/v1'); + expect(builtBidRequests[0].url).to.eq('https://btlr.sharethrough.com/WYu2BXv1/v1'); + expect(builtBidRequests[1].url).to.eq('https://btlr.sharethrough.com/WYu2BXv1/v1'); expect(builtBidRequests[0].method).to.eq('GET'); }); @@ -250,6 +248,27 @@ describe('sharethrough adapter spec', function () { expect(builtBidRequests[0].data.instant_play_capable).to.be.false; }); + it('should set the secure parameter to false when the protocol is http', function() { + const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('http:'); + const bidRequest = spec.buildRequests(bidRequests, null)[0]; + expect(bidRequest.data.secure).to.be.false; + stub.restore() + }); + + it('should set the secure parameter to true when the protocol is https', function() { + const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('https:'); + const bidRequest = spec.buildRequests(bidRequests, null)[0]; + expect(bidRequest.data.secure).to.be.true; + stub.restore() + }); + + it('should set the secure parameter to true when the protocol is neither http or https', function() { + const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('about:'); + const bidRequest = spec.buildRequests(bidRequests, null)[0]; + expect(bidRequest.data.secure).to.be.true; + stub.restore() + }); + it('should add consent parameters if gdprConsent is present', function () { const gdprConsent = { consentString: 'consent_string123', gdprApplies: true }; const bidderRequest = { gdprConsent: gdprConsent };