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

DigiTrust Facade init GH Issue 3911 #3918

Merged
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1185a02
GH Issue 3911
goosemanjack Jun 17, 2019
30beafd
Fixed superfluous trailing arg issue.
goosemanjack Jun 19, 2019
570df9d
Merge branch 'master' into digitrustFacade3911
goosemanjack Jun 25, 2019
7ec30f9
Addition of unit test for digiTrustIdSystem. Fix init error in facade…
goosemanjack Jul 1, 2019
dd6d612
Merge branch 'master' into digitrustFacade3911
goosemanjack Jul 1, 2019
27f5c8b
Uncommenting init code.
goosemanjack Jul 1, 2019
c9713db
Reverting package-lock.json file.
goosemanjack Jul 1, 2019
8df8a22
Removed extraneous function parameter.
goosemanjack Jul 1, 2019
d8101dd
Removing unused code. Fixing file casing issue causing unit test to f…
goosemanjack Jul 1, 2019
796c4c0
Adding support for SameSite=none to cookie
goosemanjack Jul 1, 2019
a99fc7d
Tweaking unit test.
goosemanjack Jul 1, 2019
b4fd53a
Merge branch 'master' into digitrustFacade3911
goosemanjack Jul 1, 2019
0fd6f0d
Removing Promise from unit test as IE doesn't like it.
goosemanjack Jul 1, 2019
713fa12
Merge branch 'master' into digitrustFacade3911
goosemanjack Jul 9, 2019
6c2a751
Cleanup of unused code lines
goosemanjack Jul 9, 2019
fa3cc44
Minor comment changes.
goosemanjack Jul 9, 2019
0be2d0d
Commenting out unit tests to see if this fixes Safari timeout issue.
goosemanjack Jul 12, 2019
3226c66
Reenable test. Fixing where done was not being called.
goosemanjack Jul 12, 2019
8aa36a7
Whitespace changes for lint
goosemanjack Jul 12, 2019
7010a62
Merge branch 'master' into digitrustFacade3911
goosemanjack Jul 15, 2019
9e3101a
Capture and clear fallback timer to fix unit tests.
goosemanjack Jul 15, 2019
60c53a4
Removing unused function
goosemanjack Jul 15, 2019
90a85cb
Comment improvements. Retry CircleCI for unassociated failure.
goosemanjack Jul 15, 2019
243c011
Merge branch 'master' into digitrustFacade3911
goosemanjack Jul 18, 2019
029f1f5
Removed old call to attachIdSystem.
goosemanjack Jul 18, 2019
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
38 changes: 32 additions & 6 deletions modules/digiTrustIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
* @requires module:modules/userId
*/

// import { config } from 'src/config';
import * as utils from '../src/utils'
import { ajax } from '../src/ajax';
import { submodule } from '../src/hook';
// import { getGlobal } from 'src/prebidGlobal';
import { attachIdSystem } from '../modules/userId/index';
goosemanjack marked this conversation as resolved.
Show resolved Hide resolved

var fallbackTimeout = 1550; // timeout value that allows userId system to execute first
var fallbackTimer = 0; // timer Id for fallback init so we don't double call

/**
* Checks to see if the DigiTrust framework is initialized.
Expand Down Expand Up @@ -81,7 +83,7 @@ function writeDigiId(id) {
var date = new Date();
date.setTime(date.getTime() + 604800000);
var exp = 'expires=' + date.toUTCString();
document.cookie = key + '=' + encId(id) + '; ' + exp + '; path=/;';
document.cookie = key + '=' + encId(id) + '; ' + exp + '; path=/;SameSite=none;';
}

/**
Expand All @@ -90,6 +92,10 @@ function writeDigiId(id) {
*/
function initDigitrustFacade(config) {
var _savedId = null; // closure variable for storing Id to avoid additional requests

clearTimeout(fallbackTimer);
fallbackTimer = 0;

var facade = {
isClient: true,
isMock: true,
Expand Down Expand Up @@ -162,6 +168,10 @@ function initDigitrustFacade(config) {
}
}

if (config && isFunc(config.callback)) {
facade._internals.initCallback = config.callback;
}

if (window && window.DigiTrust == null) {
window.DigiTrust = facade;
}
Expand Down Expand Up @@ -306,11 +316,12 @@ var testHook = {};
* Exposes the test hook object by attaching to the digitrustIdModule.
* This method is called in the unit tests to surface internals.
*/
function surfaceTestHook() {
digitrustIdModule['_testHook'] = testHook;
export function surfaceTestHook() {
digiTrustIdSubmodule['_testHook'] = testHook;
return testHook;
}

testHook.initDigitrustFacade = initDigitrustFacade;
testHook.initDigitrustFacade = initDigitrustFacade; // expose for unit tests

/** @type {Submodule} */
export const digiTrustIdSubmodule = {
Expand All @@ -336,4 +347,19 @@ export const digiTrustIdSubmodule = {
_testInit: surfaceTestHook
};

// check for fallback init of DigiTrust
function fallbackInit() {
if (resultHandler.retryId == 0 && !isInitialized()) {
// this triggers an init
var conf = {
member: 'fallback',
callback: noop
};
getDigiTrustId(conf);
}
}

fallbackTimer = setTimeout(fallbackInit, fallbackTimeout);

attachIdSystem(digiTrustIdSubmodule);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this line (attachIdSystem was replaced by submodule)

submodule('userId', digiTrustIdSubmodule);
5 changes: 4 additions & 1 deletion modules/digiTrustIdSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ for further instructions.
site: 'example_site_id'
},
callback: function (digiTrustResult) {
// This callback method is optional
// This callback method is optional and used for error handling
// in many if not most cases.
/*
if (digiTrustResult.success) {
// Success in Digitrust init;
// 'DigiTrust Id (encrypted): ' + digiTrustResult.identity.id;
}
else {
// Digitrust init failed
}
*/
}
},
storage: {
Expand Down
50 changes: 50 additions & 0 deletions test/spec/modules/digitrustIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
digiTrustIdSubmodule,
surfaceTestHook
} from 'modules/digiTrustIdSystem';

let assert = require('chai').assert;
let expect = require('chai').expect;

var testHook = null;

describe('DigiTrust Id System', function () {
it('Should create the test hook', function (done) {
testHook = surfaceTestHook();
assert.isNotNull(testHook, 'The test hook failed to surface');
var conf = {
init: {
member: 'unit_test',
site: 'foo'
},
callback: function (result) {
}
};
testHook.initDigitrustFacade(conf);
window.DigiTrust.getUser(conf);
expect(window.DigiTrust).to.exist;
expect(window.DigiTrust.isMock).to.be.true;
done();
});

it('Should report as client', function (done) {
delete window.DigiTrust;
testHook = surfaceTestHook();

var conf = {
init: {
member: 'unit_test',
site: 'foo'
},
callback: function (result) {
expect(window.DigiTrust).to.exist;
expect(result).to.exist;
expect(window.DigiTrust.isMock).to.be.true;
}
};
testHook.initDigitrustFacade(conf);
expect(window.DigiTrust).to.exist;
expect(window.DigiTrust.isClient).to.be.true;
done();
});
});