Skip to content

Commit

Permalink
Update Sharethrough bid adapter endpoint (prebid#4578)
Browse files Browse the repository at this point in the history
* Send parameter indicating the protocol of the requesting page

- `secure` parameter will equal `true` if the requesting page uses `https` and `false` otherwise

Story: [#169736764](https://www.pivotaltracker.com/story/show/169736764)

* Add fallback logic to catch protocol of iframe when prebid does not reach window.top

* Wrap location.protocol for testing; Add specs

* Use only https butler endpoints in tests
  • Loading branch information
madma authored and sa1omon committed Dec 19, 2019
1 parent 9796064 commit a81cb71
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
12 changes: 10 additions & 2 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -9,7 +9,8 @@ const DEFAULT_SIZE = [1, 1];
export const sharethroughInternal = {
b64EncodeUnicode,
handleIframe,
isLockedInFrame
isLockedInFrame,
getProtocol
};

export const sharethroughAdapterSpec = {
Expand All @@ -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;
}
Expand Down Expand Up @@ -236,4 +240,8 @@ function canAutoPlayHTML5Video() {
}
}

function getProtocol() {
return document.location.protocol;
}

registerBidder(sharethroughAdapterSpec);
41 changes: 30 additions & 11 deletions test/spec/modules/sharethroughBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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;
});
};

Expand Down Expand Up @@ -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');
});

Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit a81cb71

Please sign in to comment.