Skip to content

Commit

Permalink
[ParrableIdSystem] Accept lowercase timezone names in timezone filter (
Browse files Browse the repository at this point in the history
…#6282)

* Add lower case comparison for allowedZones

* Lowercase blocked zones also

* Fixed timezone lowercase tests

* Handle IE missing timeZone field

* Improve lowercase timezone comparison

Co-authored-by: Victor <[email protected]>
  • Loading branch information
icflournoy and victorigualada authored Feb 16, 2021
1 parent 59ef811 commit 942afbe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
13 changes: 10 additions & 3 deletions modules/parrableIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import * as utils from '../src/utils.js'
import find from 'core-js-pure/features/array/find.js';
import { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { getRefererInfo } from '../src/refererDetection.js';
Expand Down Expand Up @@ -137,12 +138,18 @@ function shouldFilterImpression(configParams, parrableId) {
const offset = (new Date()).getTimezoneOffset() / 60;
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;

function isZoneListed(list, zone) {
// IE does not provide a timeZone in IANA format so zone will be empty
const zoneLowercase = zone && zone.toLowerCase();
return !!(list && zone && find(list, zn => zn.toLowerCase() === zoneLowercase));
}

function isAllowed() {
if (utils.isEmpty(config.allowedZones) &&
utils.isEmpty(config.allowedOffsets)) {
return true;
}
if (utils.contains(config.allowedZones, zone)) {
if (isZoneListed(config.allowedZones, zone)) {
return true;
}
if (utils.contains(config.allowedOffsets, offset)) {
Expand All @@ -156,7 +163,7 @@ function shouldFilterImpression(configParams, parrableId) {
utils.isEmpty(config.blockedOffsets)) {
return false;
}
if (utils.contains(config.blockedZones, zone)) {
if (isZoneListed(config.blockedZones, zone)) {
return true;
}
if (utils.contains(config.blockedOffsets, offset)) {
Expand All @@ -165,7 +172,7 @@ function shouldFilterImpression(configParams, parrableId) {
return false;
}

return !isAllowed() || isBlocked();
return isBlocked() || !isAllowed();
}

function fetchId(configParams, gdprConsentData) {
Expand Down
28 changes: 28 additions & 0 deletions test/spec/modules/parrableIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ describe('Parrable ID System', function() {
expect(resolvedOptions.called).to.equal(true);
});

it('permits an impression from a lower cased allowed timezone', function() {
const allowedZone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: allowedZone });
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
timezoneFilter: {
allowedZones: [ allowedZone.toLowerCase() ]
}
} })).to.have.property('callback');
expect(resolvedOptions.called).to.equal(true);
});

it('permits an impression from a timezone that is not blocked', function() {
const blockedZone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: 'Iceland' });
Expand Down Expand Up @@ -333,6 +347,20 @@ describe('Parrable ID System', function() {
expect(resolvedOptions.called).to.equal(true);
});

it('does not permit an impression from a lower cased blocked timezone', function() {
const blockedZone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: blockedZone });
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
timezoneFilter: {
blockedZones: [ blockedZone.toLowerCase() ]
}
} })).to.equal(null);
expect(resolvedOptions.called).to.equal(true);
});

it('does not permit an impression from a blocked timezone even when also allowed', function() {
const timezone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: timezone });
Expand Down

0 comments on commit 942afbe

Please sign in to comment.