Skip to content
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

ID5 User ID Module: store privacy object from id5 response in local storage #6169

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const MODULE_NAME = 'id5Id';
const GVLID = 131;
const NB_EXP_DAYS = 30;
export const ID5_STORAGE_NAME = 'id5id';
export const ID5_PRIVACY_STORAGE_NAME = `${ID5_STORAGE_NAME}_privacy`;
const LOCAL_STORAGE = 'html5';

// order the legacy cookie names in reverse priority order so the last
Expand Down Expand Up @@ -137,6 +138,9 @@ export const id5IdSubmodule = {
try {
responseObj = JSON.parse(response);
resetNb(config.params.partner);
if (responseObj.privacy) {
storeInLocalStorage(ID5_PRIVACY_STORAGE_NAME, JSON.stringify(responseObj.privacy), NB_EXP_DAYS);
}

// TODO: remove after requiring publishers to use localstorage and
// all publishers have upgraded
Expand Down
46 changes: 37 additions & 9 deletions test/spec/modules/id5IdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
id5IdSubmodule,
ID5_STORAGE_NAME,
ID5_PRIVACY_STORAGE_NAME,
getFromLocalStorage,
storeInLocalStorage,
expDaysStr,
Expand Down Expand Up @@ -180,10 +181,10 @@ describe('ID5 ID System', function() {
it('should call the ID5 server with pd field when pd config is set', function () {
const pubData = 'b50ca08271795a8e7e4012813f23d505193d75c0f2e2bb99baa63aa822f66ed3';

let config = getId5FetchConfig();
config.params.pd = pubData;
let id5Config = getId5FetchConfig();
id5Config.params.pd = pubData;

let submoduleCallback = id5IdSubmodule.getId(config, undefined, ID5_STORED_OBJ).callback;
let submoduleCallback = id5IdSubmodule.getId(id5Config, undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];
Expand All @@ -194,10 +195,10 @@ describe('ID5 ID System', function() {
});

it('should call the ID5 server with empty pd field when pd config is not set', function () {
let config = getId5FetchConfig();
config.params.pd = undefined;
let id5Config = getId5FetchConfig();
id5Config.params.pd = undefined;

let submoduleCallback = id5IdSubmodule.getId(config, undefined, ID5_STORED_OBJ).callback;
let submoduleCallback = id5IdSubmodule.getId(id5Config, undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];
Expand Down Expand Up @@ -236,6 +237,33 @@ describe('ID5 ID System', function() {

expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(0);
});

it('should store the privacy object from the ID5 server response', function () {
let submoduleCallback = id5IdSubmodule.getId(getId5FetchConfig(), undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];

let responseObject = utils.deepClone(ID5_JSON_RESPONSE);
responseObject.privacy = {
jurisdiction: 'gdpr',
id5_consent: true
};
request.respond(200, responseHeader, JSON.stringify(responseObject));
expect(getFromLocalStorage(ID5_PRIVACY_STORAGE_NAME)).to.be.eq(JSON.stringify(responseObject.privacy));
coreStorage.removeDataFromLocalStorage(ID5_PRIVACY_STORAGE_NAME);
});

it('should not store a privacy object if not part of ID5 server response', function () {
coreStorage.removeDataFromLocalStorage(ID5_PRIVACY_STORAGE_NAME);
let submoduleCallback = id5IdSubmodule.getId(getId5FetchConfig(), undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];

request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));
expect(getFromLocalStorage(ID5_PRIVACY_STORAGE_NAME)).to.be.null;
});
});

describe('Request Bids Hook', function() {
Expand Down Expand Up @@ -309,7 +337,7 @@ describe('ID5 ID System', function() {
config.setConfig(getFetchLocalStorageConfig());

let innerAdUnits;
requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits});
requestBidsHook((adUnitConfig) => { innerAdUnits = adUnitConfig.adUnits }, {adUnits});

expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(1);
});
Expand All @@ -323,7 +351,7 @@ describe('ID5 ID System', function() {
config.setConfig(getFetchLocalStorageConfig());

let innerAdUnits;
requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits});
requestBidsHook((adUnitConfig) => { innerAdUnits = adUnitConfig.adUnits }, {adUnits});

expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(2);
});
Expand All @@ -341,7 +369,7 @@ describe('ID5 ID System', function() {
config.setConfig(id5Config);

let innerAdUnits;
requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits});
requestBidsHook((adUnitConfig) => { innerAdUnits = adUnitConfig.adUnits }, {adUnits});

expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(2);

Expand Down