Skip to content

Commit fc988a3

Browse files
goosemanjackAlex
authored andcommitted
DigiTrust Facade init GH Issue 3911 (prebid#3918)
* GH Issue 3911 Fix to init the DigiTrust facade object if the userId framework would not normally execute the call due to an ID being found. * Fixed superfluous trailing arg issue. * Addition of unit test for digiTrustIdSystem. Fix init error in facade callback. * Uncommenting init code. * Reverting package-lock.json file. * Removed extraneous function parameter. * Removing unused code. Fixing file casing issue causing unit test to fail. * Adding support for SameSite=none to cookie * Tweaking unit test. * Removing Promise from unit test as IE doesn't like it. * Cleanup of unused code lines * Minor comment changes. * Commenting out unit tests to see if this fixes Safari timeout issue. * Reenable test. Fixing where done was not being called. * Whitespace changes for lint * Capture and clear fallback timer to fix unit tests. * Removing unused function * Comment improvements. Retry CircleCI for unassociated failure. * Removed old call to attachIdSystem.
1 parent 1d84f40 commit fc988a3

File tree

3 files changed

+84
-7
lines changed

3 files changed

+84
-7
lines changed

modules/digiTrustIdSystem.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
* @requires module:modules/userId
1010
*/
1111

12-
// import { config } from 'src/config';
1312
import * as utils from '../src/utils'
1413
import { ajax } from '../src/ajax';
1514
import { submodule } from '../src/hook';
16-
// import { getGlobal } from 'src/prebidGlobal';
15+
16+
var fallbackTimeout = 1550; // timeout value that allows userId system to execute first
17+
var fallbackTimer = 0; // timer Id for fallback init so we don't double call
1718

1819
/**
1920
* Checks to see if the DigiTrust framework is initialized.
@@ -81,7 +82,7 @@ function writeDigiId(id) {
8182
var date = new Date();
8283
date.setTime(date.getTime() + 604800000);
8384
var exp = 'expires=' + date.toUTCString();
84-
document.cookie = key + '=' + encId(id) + '; ' + exp + '; path=/;';
85+
document.cookie = key + '=' + encId(id) + '; ' + exp + '; path=/;SameSite=none;';
8586
}
8687

8788
/**
@@ -90,6 +91,10 @@ function writeDigiId(id) {
9091
*/
9192
function initDigitrustFacade(config) {
9293
var _savedId = null; // closure variable for storing Id to avoid additional requests
94+
95+
clearTimeout(fallbackTimer);
96+
fallbackTimer = 0;
97+
9398
var facade = {
9499
isClient: true,
95100
isMock: true,
@@ -162,6 +167,10 @@ function initDigitrustFacade(config) {
162167
}
163168
}
164169

170+
if (config && isFunc(config.callback)) {
171+
facade._internals.initCallback = config.callback;
172+
}
173+
165174
if (window && window.DigiTrust == null) {
166175
window.DigiTrust = facade;
167176
}
@@ -306,11 +315,12 @@ var testHook = {};
306315
* Exposes the test hook object by attaching to the digitrustIdModule.
307316
* This method is called in the unit tests to surface internals.
308317
*/
309-
function surfaceTestHook() {
310-
digitrustIdModule['_testHook'] = testHook;
318+
export function surfaceTestHook() {
319+
digiTrustIdSubmodule['_testHook'] = testHook;
320+
return testHook;
311321
}
312322

313-
testHook.initDigitrustFacade = initDigitrustFacade;
323+
testHook.initDigitrustFacade = initDigitrustFacade; // expose for unit tests
314324

315325
/** @type {Submodule} */
316326
export const digiTrustIdSubmodule = {
@@ -336,4 +346,18 @@ export const digiTrustIdSubmodule = {
336346
_testInit: surfaceTestHook
337347
};
338348

349+
// check for fallback init of DigiTrust
350+
function fallbackInit() {
351+
if (resultHandler.retryId == 0 && !isInitialized()) {
352+
// this triggers an init
353+
var conf = {
354+
member: 'fallback',
355+
callback: noop
356+
};
357+
getDigiTrustId(conf);
358+
}
359+
}
360+
361+
fallbackTimer = setTimeout(fallbackInit, fallbackTimeout);
362+
339363
submodule('userId', digiTrustIdSubmodule);

modules/digiTrustIdSystem.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ for further instructions.
2424
site: 'example_site_id'
2525
},
2626
callback: function (digiTrustResult) {
27-
// This callback method is optional
27+
// This callback method is optional and used for error handling
28+
// in many if not most cases.
29+
/*
2830
if (digiTrustResult.success) {
2931
// Success in Digitrust init;
3032
// 'DigiTrust Id (encrypted): ' + digiTrustResult.identity.id;
3133
}
3234
else {
3335
// Digitrust init failed
3436
}
37+
*/
3538
}
3639
},
3740
storage: {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {
2+
digiTrustIdSubmodule,
3+
surfaceTestHook
4+
} from 'modules/digiTrustIdSystem';
5+
6+
let assert = require('chai').assert;
7+
let expect = require('chai').expect;
8+
9+
var testHook = null;
10+
11+
describe('DigiTrust Id System', function () {
12+
it('Should create the test hook', function (done) {
13+
testHook = surfaceTestHook();
14+
assert.isNotNull(testHook, 'The test hook failed to surface');
15+
var conf = {
16+
init: {
17+
member: 'unit_test',
18+
site: 'foo'
19+
},
20+
callback: function (result) {
21+
}
22+
};
23+
testHook.initDigitrustFacade(conf);
24+
window.DigiTrust.getUser(conf);
25+
expect(window.DigiTrust).to.exist;
26+
expect(window.DigiTrust.isMock).to.be.true;
27+
done();
28+
});
29+
30+
it('Should report as client', function (done) {
31+
delete window.DigiTrust;
32+
testHook = surfaceTestHook();
33+
34+
var conf = {
35+
init: {
36+
member: 'unit_test',
37+
site: 'foo'
38+
},
39+
callback: function (result) {
40+
expect(window.DigiTrust).to.exist;
41+
expect(result).to.exist;
42+
expect(window.DigiTrust.isMock).to.be.true;
43+
}
44+
};
45+
testHook.initDigitrustFacade(conf);
46+
expect(window.DigiTrust).to.exist;
47+
expect(window.DigiTrust.isClient).to.be.true;
48+
done();
49+
});
50+
});

0 commit comments

Comments
 (0)