Skip to content

Commit 4c9bf6f

Browse files
madmaharpere
authored andcommitted
Update Sharethrough bid adapter endpoint (#4578)
* 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
1 parent 6b9b230 commit 4c9bf6f

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

modules/sharethroughBidAdapter.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { registerBidder } from '../src/adapters/bidderFactory';
22

3-
const VERSION = '3.1.0';
3+
const VERSION = '3.2.0';
44
const BIDDER_CODE = 'sharethrough';
55
const STR_ENDPOINT = 'https://btlr.sharethrough.com/WYu2BXv1/v1';
66
const DEFAULT_SIZE = [1, 1];
@@ -9,7 +9,8 @@ const DEFAULT_SIZE = [1, 1];
99
export const sharethroughInternal = {
1010
b64EncodeUnicode,
1111
handleIframe,
12-
isLockedInFrame
12+
isLockedInFrame,
13+
getProtocol
1314
};
1415

1516
export const sharethroughAdapterSpec = {
@@ -29,6 +30,9 @@ export const sharethroughAdapterSpec = {
2930
strVersion: VERSION
3031
};
3132

33+
const nonHttp = sharethroughInternal.getProtocol().indexOf('http') < 0;
34+
query.secure = nonHttp || (sharethroughInternal.getProtocol().indexOf('https') > -1);
35+
3236
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) {
3337
query.consent_string = bidderRequest.gdprConsent.consentString;
3438
}
@@ -236,4 +240,8 @@ function canAutoPlayHTML5Video() {
236240
}
237241
}
238242

243+
function getProtocol() {
244+
return document.location.protocol;
245+
}
246+
239247
registerBidder(sharethroughAdapterSpec);

test/spec/modules/sharethroughBidAdapter_spec.js

+30-11
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const bidRequests = [
4040
const prebidRequests = [
4141
{
4242
method: 'GET',
43-
url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1',
43+
url: 'https://btlr.sharethrough.com/WYu2BXv1/v1',
4444
data: {
4545
bidId: 'bidId',
4646
placement_key: 'pKey'
@@ -52,7 +52,7 @@ const prebidRequests = [
5252
},
5353
{
5454
method: 'GET',
55-
url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1',
55+
url: 'https://btlr.sharethrough.com/WYu2BXv1/v1',
5656
data: {
5757
bidId: 'bidId',
5858
placement_key: 'pKey'
@@ -64,7 +64,7 @@ const prebidRequests = [
6464
},
6565
{
6666
method: 'GET',
67-
url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1',
67+
url: 'https://btlr.sharethrough.com/WYu2BXv1/v1',
6868
data: {
6969
bidId: 'bidId',
7070
placement_key: 'pKey'
@@ -77,7 +77,7 @@ const prebidRequests = [
7777
},
7878
{
7979
method: 'GET',
80-
url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1',
80+
url: 'https://btlr.sharethrough.com/WYu2BXv1/v1',
8181
data: {
8282
bidId: 'bidId',
8383
placement_key: 'pKey'
@@ -89,7 +89,7 @@ const prebidRequests = [
8989
},
9090
{
9191
method: 'GET',
92-
url: 'https://btlr.sharethrough.com' + '/WYu2BXv1/v1',
92+
url: 'https://btlr.sharethrough.com/WYu2BXv1/v1',
9393
data: {
9494
bidId: 'bidId',
9595
placement_key: 'pKey'
@@ -120,9 +120,9 @@ const bidderResponse = {
120120
header: { get: (header) => header }
121121
};
122122

123-
const setUserAgent = (str) => {
123+
const setUserAgent = (uaString) => {
124124
window.navigator['__defineGetter__']('userAgent', function () {
125-
return str;
125+
return uaString;
126126
});
127127
};
128128

@@ -217,10 +217,8 @@ describe('sharethrough adapter spec', function () {
217217
it('should return an array of requests', function () {
218218
const builtBidRequests = spec.buildRequests(bidRequests);
219219

220-
expect(builtBidRequests[0].url).to.eq(
221-
'https://btlr.sharethrough.com/WYu2BXv1/v1');
222-
expect(builtBidRequests[1].url).to.eq(
223-
'https://btlr.sharethrough.com/WYu2BXv1/v1');
220+
expect(builtBidRequests[0].url).to.eq('https://btlr.sharethrough.com/WYu2BXv1/v1');
221+
expect(builtBidRequests[1].url).to.eq('https://btlr.sharethrough.com/WYu2BXv1/v1');
224222
expect(builtBidRequests[0].method).to.eq('GET');
225223
});
226224

@@ -250,6 +248,27 @@ describe('sharethrough adapter spec', function () {
250248
expect(builtBidRequests[0].data.instant_play_capable).to.be.false;
251249
});
252250

251+
it('should set the secure parameter to false when the protocol is http', function() {
252+
const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('http:');
253+
const bidRequest = spec.buildRequests(bidRequests, null)[0];
254+
expect(bidRequest.data.secure).to.be.false;
255+
stub.restore()
256+
});
257+
258+
it('should set the secure parameter to true when the protocol is https', function() {
259+
const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('https:');
260+
const bidRequest = spec.buildRequests(bidRequests, null)[0];
261+
expect(bidRequest.data.secure).to.be.true;
262+
stub.restore()
263+
});
264+
265+
it('should set the secure parameter to true when the protocol is neither http or https', function() {
266+
const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('about:');
267+
const bidRequest = spec.buildRequests(bidRequests, null)[0];
268+
expect(bidRequest.data.secure).to.be.true;
269+
stub.restore()
270+
});
271+
253272
it('should add consent parameters if gdprConsent is present', function () {
254273
const gdprConsent = { consentString: 'consent_string123', gdprApplies: true };
255274
const bidderRequest = { gdprConsent: gdprConsent };

0 commit comments

Comments
 (0)