Skip to content

Update Sharethrough bid adapter endpoint #4578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { registerBidder } from '../src/adapters/bidderFactory';

const VERSION = '3.1.0';
const VERSION = '3.2.0';
const BIDDER_CODE = 'sharethrough';
const STR_ENDPOINT = document.location.protocol + '//btlr.sharethrough.com/WYu2BXv1/v1';
const STR_ENDPOINT = 'https://btlr.sharethrough.com/WYu2BXv1/v1';
const DEFAULT_SIZE = [1, 1];

// this allows stubbing of utility function that is used internally by the sharethrough adapter
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: document.location.protocol + '//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: document.location.protocol + '//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: document.location.protocol + '//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: document.location.protocol + '//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: document.location.protocol + '//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(
'http://btlr.sharethrough.com/WYu2BXv1/v1');
expect(builtBidRequests[1].url).to.eq(
'http://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