Repository navigation
Expand file tree
/
Copy pathacxiomRealIdSystem_spec.js
More file actions
595 lines (516 loc) · 19.5 KB
/
Copy pathacxiomRealIdSystem_spec.js
File metadata and controls
595 lines (516 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
import { acxiomRealIdSubmodule, dep } from 'modules/acxiomRealIdSystem.ts';
import { gdprDataHandler, uspDataHandler, gppDataHandler } from 'src/adapterManager.js';
import { expect } from 'chai';
const PARTNER_ID = 'TEST_PARTNER_01';
const REAL_ID_TOKEN = 'acxiom-real-id-token-abc123';
const HEM = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
const STORAGE_NAME = 'acxiomRealId';
function mockHandle() {
return { get: sinon.spy(), manage: sinon.spy(), set: sinon.spy(), touch: sinon.spy(), remove: sinon.spy() };
}
function getId(config, consentData, storedId = undefined, handle = mockHandle()) {
return acxiomRealIdSubmodule.getId(config, consentData, storedId, handle);
}
function makeEidResponse(token, atype) {
return JSON.stringify({
requestId: '4b61d73a-test',
generatedAt: '2026-01-27T19:27:40Z',
expiresAt: '2026-02-26T19:27:40Z',
user: {
eids: [{
source: 'acxiom.id',
uids: [{ id: token, atype: atype || 1 }]
}]
}
});
}
function makeEmptyResponse() {
return JSON.stringify({
requestId: '4b61d73a-test',
generatedAt: '2026-01-27T19:27:40Z',
user: {
eids: []
}
});
}
describe('acxiomRealIdSystem', () => {
describe('name', () => {
it('should expose the correct module name', () => {
expect(acxiomRealIdSubmodule.name).to.equal('acxiomRealId');
});
});
describe('decode', () => {
it('should return acxiomRealId object when given an object with id and atype', () => {
const stored = { id: REAL_ID_TOKEN, atype: 1 };
const result = acxiomRealIdSubmodule.decode(stored);
expect(result).to.deep.equal({ acxiomRealId: { id: REAL_ID_TOKEN, atype: 1 } });
});
it('should handle legacy string values with default atype', () => {
const result = acxiomRealIdSubmodule.decode(REAL_ID_TOKEN);
expect(result).to.deep.equal({ acxiomRealId: { id: REAL_ID_TOKEN, atype: 1 } });
});
it('should preserve atype from stored object', () => {
const stored = { id: REAL_ID_TOKEN, atype: 3 };
const result = acxiomRealIdSubmodule.decode(stored);
expect(result).to.deep.equal({ acxiomRealId: { id: REAL_ID_TOKEN, atype: 3 } });
});
it('should return undefined for null', () => {
expect(acxiomRealIdSubmodule.decode(null)).to.be.undefined;
});
it('should return undefined for empty string', () => {
expect(acxiomRealIdSubmodule.decode('')).to.be.undefined;
});
it('should return undefined for object without id', () => {
expect(acxiomRealIdSubmodule.decode({ atype: 1 })).to.be.undefined;
});
describe('post-load consent suppression', () => {
let gdprStub, uspStub, gppStub;
beforeEach(() => {
gdprStub = sinon.stub(gdprDataHandler, 'getConsentData');
uspStub = sinon.stub(uspDataHandler, 'getConsentData');
gppStub = sinon.stub(gppDataHandler, 'getConsentData');
gdprStub.returns(null);
uspStub.returns(null);
gppStub.returns(null);
});
afterEach(() => {
sinon.restore();
});
it('should return EID when no consent signals block', () => {
const result = acxiomRealIdSubmodule.decode(REAL_ID_TOKEN);
expect(result).to.deep.equal({ acxiomRealId: { id: REAL_ID_TOKEN, atype: 1 } });
});
it('should suppress when GDPR handler reports gdprApplies', () => {
gdprStub.returns({ gdprApplies: true, consentString: 'BOtest' });
const result = acxiomRealIdSubmodule.decode(REAL_ID_TOKEN);
expect(result).to.be.undefined;
});
it('should suppress when USP handler reports opt-out', () => {
uspStub.returns('1YYN');
const result = acxiomRealIdSubmodule.decode(REAL_ID_TOKEN);
expect(result).to.be.undefined;
});
it('should suppress when GPP handler reports SaleOptOut', () => {
gppStub.returns({
applicableSections: [7],
parsedSections: { usnat: { Version: 1, SaleOptOut: 1, SharingOptOut: 2 } }
});
const result = acxiomRealIdSubmodule.decode(REAL_ID_TOKEN);
expect(result).to.be.undefined;
});
it('should suppress when GPP handler reports SharingOptOut', () => {
gppStub.returns({
applicableSections: [8],
parsedSections: { usca: { Version: 1, SaleOptOut: 2, SharingOptOut: 1 } }
});
const result = acxiomRealIdSubmodule.decode(REAL_ID_TOKEN);
expect(result).to.be.undefined;
});
});
});
describe('getId', () => {
it('should return undefined when partnerId is missing', () => {
const result = acxiomRealIdSubmodule.getId({ params: {} });
expect(result).to.be.undefined;
});
it('should return undefined when params are missing', () => {
const result = acxiomRealIdSubmodule.getId({});
expect(result).to.be.undefined;
});
it('should return a callback function', () => {
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
expect(result).to.have.property('callback');
expect(result.callback).to.be.a('function');
});
describe('consent suppression', () => {
describe('EU/UK — TCF passive suppression', () => {
it('should suppress when gdprApplies is true and consentString is present', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{ gdpr: { gdprApplies: true, consentString: 'BOtest' } }
);
expect(result).to.be.undefined;
});
it('should suppress when gdprApplies is true even without consentString', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{ gdpr: { gdprApplies: true } }
);
expect(result).to.be.undefined;
});
it('should suppress when consentString is present even if gdprApplies is false', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{ gdpr: { gdprApplies: false, consentString: 'BOtest' } }
);
expect(result).to.be.undefined;
});
});
describe('US — CCPA', () => {
it('should suppress when us_privacy position 3 = Y (opted out of sale)', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{ usp: '1YYN' }
);
expect(result).to.be.undefined;
});
it('should not suppress when us_privacy position 3 = N (not opted out)', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{ usp: '1YNN' }
);
expect(result).to.have.property('callback');
});
it('should not suppress when us_privacy string is too short', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{ usp: '1Y' }
);
expect(result).to.have.property('callback');
});
});
describe('US — GPP', () => {
it('should suppress when GPP usnat SaleOptOut = 1', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{
gpp: {
applicableSections: [7],
parsedSections: { usnat: { Version: 1, SaleOptOut: 1, SharingOptOut: 2 } }
}
}
);
expect(result).to.be.undefined;
});
it('should suppress when GPP usnat SharingOptOut = 1', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{
gpp: {
applicableSections: [7],
parsedSections: { usnat: { Version: 1, SaleOptOut: 2, SharingOptOut: 1 } }
}
}
);
expect(result).to.be.undefined;
});
it('should suppress when GPP usca (California) SaleOptOut = 1', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{
gpp: {
applicableSections: [8],
parsedSections: { usca: { Version: 1, SaleOptOut: 1, SharingOptOut: 2 } }
}
}
);
expect(result).to.be.undefined;
});
it('should not suppress when GPP section has no opt-out', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{
gpp: {
applicableSections: [7],
parsedSections: { usnat: { Version: 1, SaleOptOut: 2, SharingOptOut: 2 } }
}
}
);
expect(result).to.have.property('callback');
});
it('should not suppress when applicable section is non-US', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{
gpp: {
applicableSections: [2],
parsedSections: {}
}
}
);
expect(result).to.have.property('callback');
});
it('should handle subsection arrays by flattening', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{
gpp: {
applicableSections: [7],
parsedSections: { usnat: [{ Version: 1, SaleOptOut: 2 }, { SaleOptOut: 1 }] }
}
}
);
expect(result).to.be.undefined;
});
});
describe('token deletion on consent block', () => {
it('should delete the stored token through the storage handle when consent is blocked', () => {
const handle = mockHandle();
getId({ params: { partnerId: PARTNER_ID }, storage: { name: STORAGE_NAME } }, { usp: '1YYN' }, 'stored', handle);
sinon.assert.calledOnce(handle.remove);
});
it('should not delete the stored token when consent is not blocked', () => {
const handle = mockHandle();
getId({ params: { partnerId: PARTNER_ID }, storage: { name: STORAGE_NAME } }, { usp: '1YNN' }, 'stored', handle);
sinon.assert.notCalled(handle.remove);
});
});
it('should not suppress when no consent data is provided', () => {
const result = getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
expect(result).to.have.property('callback');
});
});
describe('API call', () => {
let ajaxBuilderStub;
afterEach(() => {
if (ajaxBuilderStub) {
ajaxBuilderStub.restore();
ajaxBuilderStub = null;
}
});
it('should POST to the default API URL with partnerId and default sourceId in body', (done) => {
let capturedUrl, capturedBody, capturedOptions;
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks, body, options) => {
capturedUrl = url;
capturedBody = body;
capturedOptions = options;
callbacks.success(makeEidResponse(REAL_ID_TOKEN, 1));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
result.callback((id) => {
expect(capturedUrl).to.equal('https://ids.api.gcprivacy.id/v1/eid/l');
const payload = JSON.parse(capturedBody);
expect(payload.partnerId).to.equal(PARTNER_ID);
expect(payload.sourceId).to.equal('acxiom.id');
expect(payload.userAgent).to.be.a('string');
expect(payload.ip).to.equal('');
expect(capturedOptions.method).to.equal('POST');
expect(capturedOptions.contentType).to.equal('application/json');
expect(capturedOptions.withCredentials).to.be.true;
expect(id).to.deep.equal({ id: REAL_ID_TOKEN, atype: 1 });
done();
});
});
it('should include HEM in POST body when provided', (done) => {
let capturedBody;
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks, body) => {
capturedBody = body;
callbacks.success(makeEidResponse(REAL_ID_TOKEN, 1));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID, hem: HEM } },
{}
);
result.callback((id) => {
const payload = JSON.parse(capturedBody);
expect(payload.hem).to.equal(HEM);
expect(id).to.deep.equal({ id: REAL_ID_TOKEN, atype: 1 });
done();
});
});
it('should not include HEM in POST body when not provided', (done) => {
let capturedBody;
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks, body) => {
capturedBody = body;
callbacks.success(makeEidResponse(REAL_ID_TOKEN, 1));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
result.callback(() => {
const payload = JSON.parse(capturedBody);
expect(payload).to.not.have.property('hem');
done();
});
});
it('should use custom sourceId in POST body when provided', (done) => {
let capturedBody;
const customSourceId = 'custom.source';
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks, body) => {
capturedBody = body;
callbacks.success(makeEidResponse(REAL_ID_TOKEN, 1));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID, sourceId: customSourceId } },
{}
);
result.callback((id) => {
const payload = JSON.parse(capturedBody);
expect(payload.sourceId).to.equal(customSourceId);
expect(id).to.deep.equal({ id: REAL_ID_TOKEN, atype: 1 });
done();
});
});
it('should use custom API URL when provided', (done) => {
let capturedUrl;
const customUrl = 'https://custom.example.com/v1/eid/l';
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks) => {
capturedUrl = url;
callbacks.success(makeEidResponse(REAL_ID_TOKEN, 1));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID, apiUrl: customUrl } },
{}
);
result.callback((id) => {
expect(capturedUrl).to.equal(customUrl);
expect(id).to.deep.equal({ id: REAL_ID_TOKEN, atype: 1 });
done();
});
});
it('should strip trailing slashes from custom API URL', (done) => {
let capturedUrl;
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks) => {
capturedUrl = url;
callbacks.success(makeEidResponse(REAL_ID_TOKEN, 1));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID, apiUrl: 'https://custom.example.com/v1/eid/l///' } },
{}
);
result.callback(() => {
expect(capturedUrl).to.equal('https://custom.example.com/v1/eid/l');
done();
});
});
it('should preserve atype from API response', (done) => {
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks) => {
callbacks.success(makeEidResponse(REAL_ID_TOKEN, 3));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
result.callback((id) => {
expect(id).to.deep.equal({ id: REAL_ID_TOKEN, atype: 3 });
done();
});
});
it('should call callback with undefined on no-match response', (done) => {
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks) => {
callbacks.success(JSON.stringify({ requestId: 'test', user: {} }));
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
result.callback((id) => {
expect(id).to.be.undefined;
done();
});
});
it('should call callback with undefined when eids array is empty', (done) => {
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks) => {
callbacks.success(makeEmptyResponse());
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
result.callback((id) => {
expect(id).to.be.undefined;
done();
});
});
it('should call callback with undefined on API error', (done) => {
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks) => {
callbacks.error('server error');
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
result.callback((id) => {
expect(id).to.be.undefined;
done();
});
});
it('should call callback with undefined on malformed JSON response', (done) => {
ajaxBuilderStub = sinon.stub(dep, 'ajaxBuilder').returns(
(url, callbacks) => {
callbacks.success('not json');
}
);
const result = acxiomRealIdSubmodule.getId(
{ params: { partnerId: PARTNER_ID } },
{}
);
result.callback((id) => {
expect(id).to.be.undefined;
done();
});
});
});
});
describe('extendId', () => {
const config = { params: { partnerId: PARTNER_ID }, storage: { name: STORAGE_NAME } };
[
['GDPR applies', { gdpr: { gdprApplies: true, consentString: 'BOtest' } }],
['USP opts out of sale', { usp: '1YYN' }],
['GPP opts out of sale', { gpp: { applicableSections: [7], parsedSections: { usnat: { SaleOptOut: 1 } } } }]
].forEach(([desc, consentData]) => {
it(`should delete the stored token when ${desc}`, () => {
const handle = mockHandle();
expect(acxiomRealIdSubmodule.extendId(config, consentData, REAL_ID_TOKEN, handle)).to.be.undefined;
sinon.assert.calledOnce(handle.remove);
});
});
it('should leave storage and the ID untouched when consent is not blocked', () => {
const handle = mockHandle();
expect(acxiomRealIdSubmodule.extendId(config, { usp: '1YNN' }, REAL_ID_TOKEN, handle)).to.be.undefined;
Object.values(handle).forEach(method => sinon.assert.notCalled(method));
});
});
describe('eids', () => {
it('should be a function that builds EID from decoded data', () => {
const eidFn = acxiomRealIdSubmodule.eids.acxiomRealId;
expect(eidFn).to.be.a('function');
});
it('should produce correct EID with atype from data', () => {
const eidFn = acxiomRealIdSubmodule.eids.acxiomRealId;
const result = eidFn([{ id: REAL_ID_TOKEN, atype: 1 }]);
expect(result).to.deep.equal([{
source: 'acxiom.id',
uids: [{ id: REAL_ID_TOKEN, atype: 1 }]
}]);
});
it('should preserve atype 3 from data', () => {
const eidFn = acxiomRealIdSubmodule.eids.acxiomRealId;
const result = eidFn([{ id: REAL_ID_TOKEN, atype: 3 }]);
expect(result).to.deep.equal([{
source: 'acxiom.id',
uids: [{ id: REAL_ID_TOKEN, atype: 3 }]
}]);
});
});
});