Skip to content

Commit

Permalink
Core: add option to turn off Sec-Browsing-Topics header (#10776)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Nov 29, 2023
1 parent b154fc1 commit 73fb8d3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export const processBidderRequests = hook('sync', function (spec, bids, bidderRe
return Object.assign(defaults, ro, {
browsingTopics: ro?.hasOwnProperty('browsingTopics') && !ro.browsingTopics
? false
: isActivityAllowed(ACTIVITY_TRANSMIT_UFPD, activityParams(MODULE_TYPE_BIDDER, spec.code))
: (bidderSettings.get(spec.code, 'topicsHeader') ?? true) && isActivityAllowed(ACTIVITY_TRANSMIT_UFPD, activityParams(MODULE_TYPE_BIDDER, spec.code))
})
}
switch (request.method) {
Expand Down
112 changes: 71 additions & 41 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,15 @@ describe('bidderFactory', () => {
});

describe('browsingTopics ajax option', () => {
let transmitUfpdAllowed, bidder;
let transmitUfpdAllowed, bidder, origBS;
before(() => {
origBS = window.$$PREBID_GLOBAL$$.bidderSettings;
})

after(() => {
window.$$PREBID_GLOBAL$$.bidderSettings = origBS;
});

beforeEach(() => {
activityRules.isActivityAllowed.reset();
activityRules.isActivityAllowed.callsFake((activity) => activity === ACTIVITY_TRANSMIT_UFPD ? transmitUfpdAllowed : true);
Expand All @@ -448,49 +456,71 @@ describe('bidderFactory', () => {
});

Object.entries({
'allowed': true,
'not allowed': false
}).forEach(([t, allow]) => {
it(`should be set to ${allow} when transmitUfpd is ${t}`, () => {
transmitUfpdAllowed = allow;
spec.buildRequests.returns([
{
method: 'GET',
url: '1',
},
{
method: 'POST',
url: '2',
data: {}
},
{
method: 'GET',
url: '3',
options: {
browsingTopics: true
}
},
{
method: 'POST',
url: '4',
data: {},
options: {
browsingTopics: true
'omitted': [undefined, true],
'enabled': [true, true],
'disabled': [false, false]
}).forEach(([t, [topicsHeader, enabled]]) => {
describe(`when bidderSettings.topicsHeader is ${t}`, () => {
beforeEach(() => {
window.$$PREBID_GLOBAL$$.bidderSettings = {
[CODE]: {
topicsHeader: topicsHeader
}
}
]);
bidder.callBids(MOCK_BIDS_REQUEST, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
['1', '2', '3', '4'].forEach(url => {
sinon.assert.calledWith(
ajaxStub,
url,
sinon.match.any,
sinon.match.any,
sinon.match({browsingTopics: allow})
);
});
});
});

afterEach(() => {
delete window.$$PREBID_GLOBAL$$.bidderSettings[CODE];
});

Object.entries({
'allowed': true,
'not allowed': false
}).forEach(([t, allow]) => {
const shouldBeSet = allow && enabled;

it(`should be set to ${shouldBeSet} when transmitUfpd is ${t}`, () => {
transmitUfpdAllowed = allow;
spec.buildRequests.returns([
{
method: 'GET',
url: '1',
},
{
method: 'POST',
url: '2',
data: {}
},
{
method: 'GET',
url: '3',
options: {
browsingTopics: true
}
},
{
method: 'POST',
url: '4',
data: {},
options: {
browsingTopics: true
}
}
]);
bidder.callBids(MOCK_BIDS_REQUEST, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
['1', '2', '3', '4'].forEach(url => {
sinon.assert.calledWith(
ajaxStub,
url,
sinon.match.any,
sinon.match.any,
sinon.match({browsingTopics: shouldBeSet})
);
});
});
});
})
})
});

it('should not add bids for each placement code if no requests are given', function () {
Expand Down

0 comments on commit 73fb8d3

Please sign in to comment.