prebid.js 7.50.0 → 7.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/dist/33acrossBidAdapter.js +1 -1
  2. package/dist/33acrossIdSystem.js +1 -1
  3. package/dist/adagioBidAdapter.js +1 -1
  4. package/dist/adbookpspBidAdapter.js +1 -1
  5. package/dist/adgenerationBidAdapter.js +1 -1
  6. package/dist/adhashBidAdapter.js +1 -1
  7. package/dist/adkernelBidAdapter.js +1 -1
  8. package/dist/admanBidAdapter.js +1 -1
  9. package/dist/adnuntiusBidAdapter.js +1 -1
  10. package/dist/adqueryBidAdapter.js +1 -1
  11. package/dist/adrelevantisBidAdapter.js +1 -1
  12. package/dist/adrinoBidAdapter.js +1 -1
  13. package/dist/adriverIdSystem.js +1 -1
  14. package/dist/adtelligentBidAdapter.js +1 -1
  15. package/dist/adtrgtmeBidAdapter.js +1 -1
  16. package/dist/adxcgBidAdapter.js +1 -1
  17. package/dist/adyoulikeBidAdapter.js +1 -1
  18. package/dist/ajaBidAdapter.js +1 -1
  19. package/dist/allowActivities.js +1 -0
  20. package/dist/amxBidAdapter.js +1 -1
  21. package/dist/amxIdSystem.js +1 -1
  22. package/dist/appierAnalyticsAdapter.js +1 -1
  23. package/dist/appnexusBidAdapter.js +1 -1
  24. package/dist/asoBidAdapter.js +1 -1
  25. package/dist/axonixBidAdapter.js +1 -1
  26. package/dist/bidglassBidAdapter.js +1 -1
  27. package/dist/big-richmediaBidAdapter.js +1 -1
  28. package/dist/bridgewellBidAdapter.js +1 -1
  29. package/dist/brightMountainMediaBidAdapter.js +1 -1
  30. package/dist/carodaBidAdapter.js +1 -1
  31. package/dist/chtnwBidAdapter.js +1 -1
  32. package/dist/cleanioRtdProvider.js +1 -1
  33. package/dist/concertBidAdapter.js +1 -1
  34. package/dist/connectIdSystem.js +1 -1
  35. package/dist/connectadBidAdapter.js +1 -1
  36. package/dist/consumableBidAdapter.js +1 -1
  37. package/dist/conversantAnalyticsAdapter.js +1 -1
  38. package/dist/conversantBidAdapter.js +1 -1
  39. package/dist/craftBidAdapter.js +1 -1
  40. package/dist/criteoBidAdapter.js +1 -1
  41. package/dist/cwireBidAdapter.js +1 -1
  42. package/dist/dependencies.json +6 -0
  43. package/dist/dspxBidAdapter.js +1 -1
  44. package/dist/eplanningBidAdapter.js +1 -1
  45. package/dist/feedadBidAdapter.js +1 -1
  46. package/dist/finativeBidAdapter.js +1 -1
  47. package/dist/freewheel-sspBidAdapter.js +1 -1
  48. package/dist/gdprEnforcement.js +1 -1
  49. package/dist/glimpseBidAdapter.js +1 -1
  50. package/dist/gmosspBidAdapter.js +1 -1
  51. package/dist/goldbachBidAdapter.js +1 -1
  52. package/dist/greenbidsAnalyticsAdapter.js +1 -1
  53. package/dist/greenbidsRtdProvider.js +1 -1
  54. package/dist/gridBidAdapter.js +1 -1
  55. package/dist/growthCodeRtdProvider.js +1 -0
  56. package/dist/gumgumBidAdapter.js +1 -1
  57. package/dist/h12mediaBidAdapter.js +1 -1
  58. package/dist/id5IdSystem.js +1 -1
  59. package/dist/improvedigitalBidAdapter.js +1 -1
  60. package/dist/inmarBidAdapter.js +1 -1
  61. package/dist/insticatorBidAdapter.js +1 -1
  62. package/dist/ixBidAdapter.js +1 -1
  63. package/dist/justpremiumBidAdapter.js +1 -1
  64. package/dist/kargoBidAdapter.js +1 -1
  65. package/dist/konduitAnalyticsAdapter.js +1 -1
  66. package/dist/kueezBidAdapter.js +1 -1
  67. package/dist/kueezRtbBidAdapter.js +1 -1
  68. package/dist/kulturemediaBidAdapter.js +1 -1
  69. package/dist/lassoBidAdapter.js +1 -1
  70. package/dist/lifestreetBidAdapter.js +1 -1
  71. package/dist/liveyieldAnalyticsAdapter.js +1 -1
  72. package/dist/logicadBidAdapter.js +1 -1
  73. package/dist/loglyliftBidAdapter.js +1 -1
  74. package/dist/magniteAnalyticsAdapter.js +1 -1
  75. package/dist/malltvAnalyticsAdapter.js +1 -1
  76. package/dist/marsmediaBidAdapter.js +1 -1
  77. package/dist/mediafuseBidAdapter.js +1 -1
  78. package/dist/mediasquareBidAdapter.js +1 -1
  79. package/dist/mgidBidAdapter.js +1 -1
  80. package/dist/minutemediaBidAdapter.js +1 -1
  81. package/dist/minutemediaplusBidAdapter.js +1 -1
  82. package/dist/nexx360BidAdapter.js +1 -1
  83. package/dist/not-for-prod/prebid.js +144 -140
  84. package/dist/objectGuard.js +1 -0
  85. package/dist/oguryBidAdapter.js +1 -1
  86. package/dist/onetagBidAdapter.js +1 -1
  87. package/dist/ooloAnalyticsAdapter.js +1 -1
  88. package/dist/optidigitalBidAdapter.js +1 -1
  89. package/dist/outbrainBidAdapter.js +1 -1
  90. package/dist/oxxionAnalyticsAdapter.js +1 -0
  91. package/dist/pairIdSystem.js +1 -1
  92. package/dist/parrableIdSystem.js +1 -1
  93. package/dist/pixfutureBidAdapter.js +1 -1
  94. package/dist/prebid-core.js +1 -1
  95. package/dist/prebidServerBidAdapter.js +1 -1
  96. package/dist/publinkIdSystem.js +1 -1
  97. package/dist/pubmaticBidAdapter.js +1 -1
  98. package/dist/pubwiseAnalyticsAdapter.js +1 -1
  99. package/dist/pxyzBidAdapter.js +1 -1
  100. package/dist/quantcastBidAdapter.js +1 -1
  101. package/dist/readpeakBidAdapter.js +1 -1
  102. package/dist/relaidoBidAdapter.js +1 -1
  103. package/dist/retailspotBidAdapter.js +1 -1
  104. package/dist/rhythmoneBidAdapter.js +1 -1
  105. package/dist/riseBidAdapter.js +1 -1
  106. package/dist/rtdModule.js +1 -1
  107. package/dist/rubiconAnalyticsAdapter.js +1 -1
  108. package/dist/rubiconBidAdapter.js +1 -1
  109. package/dist/seedingAllianceBidAdapter.js +1 -1
  110. package/dist/seedtagBidAdapter.js +1 -1
  111. package/dist/sharethroughAnalyticsAdapter.js +1 -1
  112. package/dist/sharethroughBidAdapter.js +1 -1
  113. package/dist/shinezBidAdapter.js +1 -1
  114. package/dist/smaatoBidAdapter.js +1 -1
  115. package/dist/smartadserverBidAdapter.js +1 -1
  116. package/dist/smartxBidAdapter.js +1 -1
  117. package/dist/smilewantedBidAdapter.js +1 -1
  118. package/dist/sonobiBidAdapter.js +1 -1
  119. package/dist/sovrnAnalyticsAdapter.js +1 -1
  120. package/dist/sovrnBidAdapter.js +1 -1
  121. package/dist/sspBCBidAdapter.js +1 -1
  122. package/dist/stvBidAdapter.js +1 -1
  123. package/dist/sublimeBidAdapter.js +1 -1
  124. package/dist/synacormediaBidAdapter.js +1 -1
  125. package/dist/targetVideoBidAdapter.js +1 -1
  126. package/dist/teadsBidAdapter.js +1 -1
  127. package/dist/trionBidAdapter.js +1 -1
  128. package/dist/tripleliftBidAdapter.js +1 -1
  129. package/dist/ttdBidAdapter.js +1 -1
  130. package/dist/ucfunnelAnalyticsAdapter.js +1 -1
  131. package/dist/uid2IdSystem.js +1 -1
  132. package/dist/underdogmediaBidAdapter.js +1 -1
  133. package/dist/undertoneBidAdapter.js +1 -1
  134. package/dist/userId.js +1 -1
  135. package/dist/vidazooBidAdapter.js +1 -1
  136. package/dist/videobyteBidAdapter.js +1 -1
  137. package/dist/visxBidAdapter.js +1 -1
  138. package/dist/vuukleBidAdapter.js +1 -1
  139. package/dist/widespaceBidAdapter.js +1 -1
  140. package/dist/winrBidAdapter.js +1 -1
  141. package/dist/yahoosspBidAdapter.js +1 -1
  142. package/dist/yieldmoBidAdapter.js +1 -1
  143. package/dist/yieldoneAnalyticsAdapter.js +1 -1
  144. package/dist/zeta_global_sspBidAdapter.js +1 -1
  145. package/integrationExamples/gpt/growthcode.html +20 -9
  146. package/libraries/objectGuard/objectGuard.js +108 -0
  147. package/libraries/objectGuard/ortbGuard.js +88 -0
  148. package/modules/adgenerationBidAdapter.js +14 -5
  149. package/modules/adhashBidAdapter.js +28 -17
  150. package/modules/adkernelBidAdapter.js +2 -1
  151. package/modules/admanBidAdapter.js +30 -22
  152. package/modules/adnuntiusBidAdapter.js +98 -79
  153. package/modules/adnuntiusBidAdapter.md +2 -1
  154. package/modules/adqueryBidAdapter.js +7 -1
  155. package/modules/adrinoBidAdapter.js +1 -0
  156. package/modules/adriverIdSystem.js +1 -1
  157. package/modules/adtelligentBidAdapter.js +4 -2
  158. package/modules/allowActivities.js +74 -0
  159. package/modules/appnexusBidAdapter.js +1 -0
  160. package/modules/cleanioRtdProvider.js +2 -4
  161. package/modules/connectIdSystem.js +89 -13
  162. package/modules/connectIdSystem.md +4 -7
  163. package/modules/criteoBidAdapter.js +50 -3
  164. package/modules/freewheel-sspBidAdapter.js +10 -2
  165. package/modules/gdprEnforcement.js +98 -169
  166. package/modules/growthCodeRtdProvider.js +131 -0
  167. package/modules/growthCodeRtdProvider.md +55 -0
  168. package/modules/gumgumBidAdapter.js +5 -0
  169. package/modules/ixBidAdapter.js +5 -2
  170. package/modules/minutemediaBidAdapter.js +13 -3
  171. package/modules/oxxionAnalyticsAdapter.js +212 -0
  172. package/modules/oxxionAnalyticsAdapter.md +33 -0
  173. package/modules/pairIdSystem.js +6 -6
  174. package/modules/prebidServerBidAdapter/index.js +7 -8
  175. package/modules/pubmaticBidAdapter.js +1 -0
  176. package/modules/riseBidAdapter.js +13 -3
  177. package/modules/rtbhouseBidAdapter.md +24 -0
  178. package/modules/rtdModule/index.js +12 -1
  179. package/modules/sharethroughBidAdapter.js +2 -2
  180. package/modules/smartadserverBidAdapter.js +5 -0
  181. package/modules/stvBidAdapter.js +34 -1
  182. package/modules/undertoneBidAdapter.js +9 -1
  183. package/modules/userId/index.js +69 -41
  184. package/modules/yahoosspBidAdapter.js +45 -3
  185. package/modules/yahoosspBidAdapter.md +1 -1
  186. package/modules/zeta_global_sspBidAdapter.js +1 -0
  187. package/package.json +1 -1
  188. package/src/activities/activities.js +47 -0
  189. package/src/activities/activityParams.js +8 -0
  190. package/src/activities/modules.js +1 -1
  191. package/src/activities/params.js +59 -0
  192. package/src/activities/redactor.js +157 -0
  193. package/src/activities/rules.js +95 -0
  194. package/src/adapterManager.js +45 -8
  195. package/src/adloader.js +2 -1
  196. package/src/fpd/rootDomain.js +1 -1
  197. package/src/native.js +20 -4
  198. package/src/prebid.js +1 -1
  199. package/src/storageManager.js +57 -44
  200. package/src/userSync.js +35 -18
  201. package/test/spec/activities/allowActivites_spec.js +138 -0
  202. package/test/spec/activities/objectGuard_spec.js +144 -0
  203. package/test/spec/activities/ortbGuard_spec.js +140 -0
  204. package/test/spec/activities/params_spec.js +25 -0
  205. package/test/spec/activities/redactor_spec.js +296 -0
  206. package/test/spec/activities/rules_spec.js +135 -0
  207. package/test/spec/modules/adgenerationBidAdapter_spec.js +52 -12
  208. package/test/spec/modules/adhashBidAdapter_spec.js +51 -1
  209. package/test/spec/modules/admanBidAdapter_spec.js +1 -2
  210. package/test/spec/modules/adnuntiusBidAdapter_spec.js +535 -264
  211. package/test/spec/modules/adqueryBidAdapter_spec.js +9 -0
  212. package/test/spec/modules/adrinoBidAdapter_spec.js +4 -0
  213. package/test/spec/modules/adtelligentBidAdapter_spec.js +1 -0
  214. package/test/spec/modules/cleanioRtdProvider_spec.js +7 -8
  215. package/test/spec/modules/connectIdSystem_spec.js +291 -23
  216. package/test/spec/modules/criteoBidAdapter_spec.js +134 -2
  217. package/test/spec/modules/freewheel-sspBidAdapter_spec.js +5 -2
  218. package/test/spec/modules/gdprEnforcement_spec.js +127 -414
  219. package/test/spec/modules/growthCodeRtdProvider_spec.js +127 -0
  220. package/test/spec/modules/gumgumBidAdapter_spec.js +14 -0
  221. package/test/spec/modules/ixBidAdapter_spec.js +2 -1
  222. package/test/spec/modules/minutemediaBidAdapter_spec.js +69 -1
  223. package/test/spec/modules/oxxionAnalyticsAdapter_spec.js +324 -0
  224. package/test/spec/modules/pairIdSystem_spec.js +16 -3
  225. package/test/spec/modules/prebidServerBidAdapter_spec.js +3 -1
  226. package/test/spec/modules/pubmaticBidAdapter_spec.js +7 -0
  227. package/test/spec/modules/realTimeDataModule_spec.js +1 -1
  228. package/test/spec/modules/riseBidAdapter_spec.js +69 -1
  229. package/test/spec/modules/sharethroughBidAdapter_spec.js +1 -1
  230. package/test/spec/modules/smartadserverBidAdapter_spec.js +42 -0
  231. package/test/spec/modules/stvBidAdapter_spec.js +13 -1
  232. package/test/spec/modules/undertoneBidAdapter_spec.js +57 -1
  233. package/test/spec/modules/userId_spec.js +80 -21
  234. package/test/spec/modules/yahoosspBidAdapter_spec.js +103 -51
  235. package/test/spec/modules/zeta_global_sspBidAdapter_spec.js +4 -0
  236. package/test/spec/native_spec.js +12 -12
  237. package/test/spec/unit/core/adapterManager_spec.js +181 -1
  238. package/test/spec/unit/core/storageManager_spec.js +76 -68
  239. package/test/spec/unit/pbjs_api_spec.js +15 -25
  240. package/test/spec/userSync_spec.js +45 -16
@@ -0,0 +1,144 @@
1
+ import {objectGuard, writeProtectRule} from '../../../libraries/objectGuard/objectGuard.js';
2
+
3
+ describe('objectGuard', () => {
4
+ describe('read rule', () => {
5
+ let rule, applies;
6
+ beforeEach(() => {
7
+ applies = true;
8
+ rule = {
9
+ paths: ['foo', 'outer.inner.foo'],
10
+ name: 'testRule',
11
+ applies: sinon.stub().callsFake(() => applies),
12
+ get(val) { return `repl${val}` },
13
+ }
14
+ })
15
+ it('can prevent top level read access', () => {
16
+ const {obj} = objectGuard([rule])({'foo': 1, 'other': 2});
17
+ expect(obj).to.eql({
18
+ foo: 'repl1',
19
+ other: 2
20
+ });
21
+ });
22
+
23
+ it('does not choke if a guarded property is missing', () => {
24
+ const {obj} = objectGuard([rule])({});
25
+ expect(obj.foo).to.not.exist;
26
+ });
27
+
28
+ it('does not prevent access if applies returns false', () => {
29
+ applies = false;
30
+ const {obj} = objectGuard([rule])({foo: 1});
31
+ expect(obj).to.eql({
32
+ foo: 1
33
+ });
34
+ })
35
+
36
+ it('can prevent nested property access', () => {
37
+ const {obj} = objectGuard([rule])({
38
+ other: 0,
39
+ outer: {
40
+ foo: 1,
41
+ inner: {
42
+ foo: 2
43
+ },
44
+ bar: {
45
+ foo: 3
46
+ }
47
+ }
48
+ });
49
+ expect(obj).to.eql({
50
+ other: 0,
51
+ outer: {
52
+ foo: 1,
53
+ inner: {
54
+ foo: 'repl2',
55
+ },
56
+ bar: {
57
+ foo: 3
58
+ }
59
+ }
60
+ })
61
+ });
62
+
63
+ it('does not call applies more than once', () => {
64
+ JSON.stringify(objectGuard([rule])({
65
+ foo: 0,
66
+ outer: {
67
+ inner: {
68
+ foo: 1
69
+ }
70
+ }
71
+ }).obj);
72
+ expect(rule.applies.callCount).to.equal(1);
73
+ })
74
+ });
75
+
76
+ describe('write protection', () => {
77
+ let applies, rule;
78
+
79
+ beforeEach(() => {
80
+ applies = true;
81
+ rule = writeProtectRule({
82
+ paths: ['foo', 'bar', 'outer.inner.foo', 'outer.inner.bar'],
83
+ applies: sinon.stub().callsFake(() => applies)
84
+ });
85
+ });
86
+
87
+ it('should undo top-level writes', () => {
88
+ const obj = {bar: {nested: 'val'}, other: 'val'};
89
+ const guard = objectGuard([rule])(obj);
90
+ guard.obj.foo = 'denied';
91
+ guard.obj.bar.nested = 'denied';
92
+ guard.obj.bar.other = 'denied';
93
+ guard.obj.other = 'allowed';
94
+ guard.verify();
95
+ expect(obj).to.eql({bar: {nested: 'val'}, other: 'allowed'});
96
+ });
97
+
98
+ it('should undo top-level deletes', () => {
99
+ const obj = {foo: {nested: 'val'}, bar: 'val'};
100
+ const guard = objectGuard([rule])(obj);
101
+ delete guard.obj.foo.nested;
102
+ delete guard.obj.bar;
103
+ guard.verify();
104
+ expect(obj).to.eql({foo: {nested: 'val'}, bar: 'val'});
105
+ })
106
+
107
+ it('should undo nested writes', () => {
108
+ const obj = {outer: {inner: {bar: {nested: 'val'}, other: 'val'}}};
109
+ const guard = objectGuard([rule])(obj);
110
+ guard.obj.outer.inner.bar.other = 'denied';
111
+ guard.obj.outer.inner.bar.nested = 'denied';
112
+ guard.obj.outer.inner.foo = 'denied';
113
+ guard.obj.outer.inner.other = 'allowed';
114
+ guard.verify();
115
+ expect(obj).to.eql({
116
+ outer: {
117
+ inner: {
118
+ bar: {
119
+ nested: 'val'
120
+ },
121
+ other: 'allowed'
122
+ }
123
+ }
124
+ })
125
+ });
126
+
127
+ it('should undo nested deletes', () => {
128
+ const obj = {outer: {inner: {foo: {nested: 'val'}, bar: 'val'}}};
129
+ const guard = objectGuard([rule])(obj);
130
+ delete guard.obj.outer.inner.foo.nested;
131
+ delete guard.obj.outer.inner.bar;
132
+ guard.verify();
133
+ expect(obj).to.eql({outer: {inner: {foo: {nested: 'val'}, bar: 'val'}}})
134
+ });
135
+
136
+ it('should work on null properties', () => {
137
+ const obj = {foo: null};
138
+ const guard = objectGuard([rule])(obj);
139
+ guard.obj.foo = 'denied';
140
+ guard.verify();
141
+ expect(obj).to.eql({foo: null});
142
+ });
143
+ });
144
+ });
@@ -0,0 +1,140 @@
1
+ import {ortb2FragmentsGuardFactory, ortb2GuardFactory} from '../../../libraries/objectGuard/ortbGuard.js';
2
+ import {ACTIVITY_PARAM_COMPONENT_NAME, ACTIVITY_PARAM_COMPONENT_TYPE} from '../../../src/activities/params.js';
3
+ import {
4
+ ACTIVITY_ENRICH_EIDS, ACTIVITY_ENRICH_UFPD,
5
+ ACTIVITY_TRANSMIT_EIDS,
6
+ ACTIVITY_TRANSMIT_UFPD
7
+ } from '../../../src/activities/activities.js';
8
+ import {activityParams} from '../../../src/activities/activityParams.js';
9
+ import {deepAccess, deepClone, deepSetValue, mergeDeep} from '../../../src/utils.js';
10
+ import {ORTB_EIDS_PATHS, ORTB_UFPD_PATHS} from '../../../src/activities/redactor.js';
11
+ import {objectGuard, writeProtectRule} from '../../../libraries/objectGuard/objectGuard.js';
12
+
13
+ describe('ortb2Guard', () => {
14
+ const MOD_TYPE = 'test';
15
+ const MOD_NAME = 'mock';
16
+ let isAllowed, ortb2Guard;
17
+ beforeEach(() => {
18
+ isAllowed = sinon.stub();
19
+ ortb2Guard = ortb2GuardFactory(function (activity, params) {
20
+ if (params[ACTIVITY_PARAM_COMPONENT_TYPE] === MOD_TYPE && params[ACTIVITY_PARAM_COMPONENT_NAME] === MOD_NAME) {
21
+ return isAllowed(activity)
22
+ } else {
23
+ throw new Error('wrong component')
24
+ }
25
+ })
26
+ });
27
+
28
+ function testAllowDeny(transmitActivity, enrichActivity, fn) {
29
+ Object.entries({
30
+ allowed: true,
31
+ denied: false
32
+ }).forEach(([t, allowed]) => {
33
+ describe(`when '${enrichActivity}' is ${t}`, () => {
34
+ beforeEach(() => {
35
+ isAllowed.callsFake((activity) => {
36
+ if (activity === transmitActivity) return true;
37
+ if (activity === enrichActivity) return allowed;
38
+ throw new Error('wrong activity');
39
+ })
40
+ });
41
+ fn(allowed);
42
+ })
43
+ })
44
+ }
45
+
46
+ function testPropertiesAreProtected(properties, allowed) {
47
+ properties.forEach(prop => {
48
+ it(`should ${allowed ? 'keep' : 'undo'} additions to ${prop}`, () => {
49
+ const orig = [{n: 'orig'}];
50
+ const ortb2 = {};
51
+ deepSetValue(ortb2, prop, deepClone(orig));
52
+ const guard = ortb2Guard(ortb2, activityParams(MOD_TYPE, MOD_NAME));
53
+ const mod = {};
54
+ const insert = [{n: 'new'}];
55
+ deepSetValue(mod, prop, insert);
56
+ mergeDeep(guard.obj, mod);
57
+ guard.verify();
58
+ const actual = deepAccess(ortb2, prop);
59
+ if (allowed) {
60
+ expect(actual).to.eql(orig.concat(insert))
61
+ } else {
62
+ expect(actual).to.eql(orig);
63
+ }
64
+ });
65
+
66
+ it(`should ${allowed ? 'keep' : 'undo'} modifications to ${prop}`, () => {
67
+ const orig = [{n: 'orig'}];
68
+ const ortb2 = {};
69
+ deepSetValue(ortb2, prop, orig);
70
+ const guard = ortb2Guard(ortb2, activityParams(MOD_TYPE, MOD_NAME));
71
+ deepSetValue(guard.obj, `${prop}.0.n`, 'new');
72
+ guard.verify();
73
+ const actual = deepAccess(ortb2, prop);
74
+ if (allowed) {
75
+ expect(actual).to.eql([{n: 'new'}]);
76
+ } else {
77
+ expect(actual).to.eql([{n: 'orig'}]);
78
+ }
79
+ });
80
+ })
81
+ }
82
+
83
+ testAllowDeny(ACTIVITY_TRANSMIT_EIDS, ACTIVITY_ENRICH_EIDS, (allowed) => {
84
+ testPropertiesAreProtected(ORTB_EIDS_PATHS, allowed);
85
+ });
86
+
87
+ testAllowDeny(ACTIVITY_TRANSMIT_UFPD, ACTIVITY_ENRICH_UFPD, (allowed) => {
88
+ testPropertiesAreProtected(ORTB_UFPD_PATHS, allowed);
89
+ });
90
+ });
91
+
92
+ describe('ortb2FragmentsGuard', () => {
93
+ let guardFragments
94
+ beforeEach(() => {
95
+ const testGuard = objectGuard([
96
+ writeProtectRule({
97
+ paths: ['foo'],
98
+ applies: () => true,
99
+ name: 'testRule'
100
+ })
101
+ ])
102
+ guardFragments = ortb2FragmentsGuardFactory(testGuard);
103
+ });
104
+
105
+ it('should undo changes to global FPD', () => {
106
+ const fragments = {
107
+ global: {
108
+ foo: {inner: 'val'}
109
+ }
110
+ }
111
+ const guard = guardFragments(fragments);
112
+ guard.obj.global.foo = 'other';
113
+ guard.verify();
114
+ expect(fragments.global.foo).to.eql({inner: 'val'});
115
+ });
116
+
117
+ it('should undo changes to bidder FPD', () => {
118
+ const fragments = {
119
+ bidder: {
120
+ A: {
121
+ foo: 'val'
122
+ }
123
+ }
124
+ };
125
+ const guard = guardFragments(fragments);
126
+ guard.obj.bidder.A.foo = 'denied';
127
+ guard.verify();
128
+ expect(fragments.bidder.A).to.eql({foo: 'val'});
129
+ });
130
+
131
+ it('should undo changes to bidder FPD that was not initially there', () => {
132
+ const fragments = {
133
+ bidder: {}
134
+ };
135
+ const guard = guardFragments(fragments);
136
+ guard.obj.bidder.A = {foo: 'denied', other: 'allowed'};
137
+ guard.verify();
138
+ expect(fragments.bidder.A).to.eql({other: 'allowed'});
139
+ });
140
+ })
@@ -0,0 +1,25 @@
1
+ import {
2
+ ACTIVITY_PARAM_ADAPTER_CODE,
3
+ ACTIVITY_PARAM_COMPONENT, ACTIVITY_PARAM_COMPONENT_NAME,
4
+ ACTIVITY_PARAM_COMPONENT_TYPE
5
+ } from '../../../src/activities/params.js';
6
+ import adapterManager from '../../../src/adapterManager.js';
7
+ import {MODULE_TYPE_BIDDER} from '../../../src/activities/modules.js';
8
+ import {activityParams} from '../../../src/activities/activityParams.js';
9
+
10
+ describe('activityParams', () => {
11
+ it('fills out component params', () => {
12
+ sinon.assert.match(activityParams('bidder', 'mockBidder', {foo: 'bar'}), {
13
+ [ACTIVITY_PARAM_COMPONENT]: 'bidder.mockBidder',
14
+ [ACTIVITY_PARAM_COMPONENT_TYPE]: 'bidder',
15
+ [ACTIVITY_PARAM_COMPONENT_NAME]: 'mockBidder',
16
+ foo: 'bar'
17
+ })
18
+ });
19
+
20
+ it('fills out adapterCode', () => {
21
+ adapterManager.registerBidAdapter({callBids: sinon.stub(), getSpec: sinon.stub().returns({})}, 'mockBidder')
22
+ adapterManager.aliasBidAdapter('mockBidder', 'mockAlias');
23
+ expect(activityParams(MODULE_TYPE_BIDDER, 'mockAlias')[ACTIVITY_PARAM_ADAPTER_CODE]).to.equal('mockBidder');
24
+ });
25
+ });
@@ -0,0 +1,296 @@
1
+ import {
2
+ objectTransformer,
3
+ ORTB_EIDS_PATHS, ORTB_GEO_PATHS,
4
+ ORTB_UFPD_PATHS,
5
+ redactorFactory, redactRule
6
+ } from '../../../src/activities/redactor.js';
7
+ import {ACTIVITY_PARAM_COMPONENT_NAME, ACTIVITY_PARAM_COMPONENT_TYPE} from '../../../src/activities/params.js';
8
+ import {
9
+ ACTIVITY_TRANSMIT_EIDS,
10
+ ACTIVITY_TRANSMIT_PRECISE_GEO,
11
+ ACTIVITY_TRANSMIT_UFPD
12
+ } from '../../../src/activities/activities.js';
13
+ import {deepAccess, deepSetValue} from '../../../src/utils.js';
14
+ import {activityParams} from '../../../src/activities/activityParams.js';
15
+
16
+ describe('objectTransformer', () => {
17
+ describe('using dummy rules', () => {
18
+ let rule, applies, run;
19
+ beforeEach(() => {
20
+ run = sinon.stub();
21
+ applies = sinon.stub().callsFake(() => true)
22
+ rule = {
23
+ name: 'mockRule',
24
+ paths: ['foo', 'bar.baz'],
25
+ applies,
26
+ run,
27
+ }
28
+ });
29
+
30
+ it('runs rule for each path', () => {
31
+ const obj = {foo: 'val'};
32
+ objectTransformer([rule])({}, obj);
33
+ sinon.assert.calledWith(run, obj, null, obj, 'foo');
34
+ sinon.assert.calledWith(run, obj, 'bar', undefined, 'baz');
35
+ });
36
+
37
+ it('does not run rule once it is known that it does not apply', () => {
38
+ applies.reset();
39
+ applies.callsFake(() => false);
40
+ run.callsFake((_1, _2, _3, _4, applies) => applies());
41
+ objectTransformer([rule])({}, {});
42
+ expect(applies.callCount).to.equal(1);
43
+ expect(run.callCount).to.equal(1);
44
+ });
45
+
46
+ it('does not call apply more than once', () => {
47
+ run.callsFake((_1, _2, _3, _4, applies) => {
48
+ applies();
49
+ applies();
50
+ });
51
+ objectTransformer([rule])({}, {});
52
+ expect(applies.callCount).to.equal(1);
53
+ });
54
+
55
+ it('does not call apply if session already contains a result for the rule', () => {
56
+ objectTransformer([rule])({[rule.name]: false}, {});
57
+ expect(applies.callCount).to.equal(0);
58
+ expect(run.callCount).to.equal(0);
59
+ })
60
+
61
+ it('passes arguments to applies', () => {
62
+ run.callsFake((_1, _2, _3, _4, applies) => applies());
63
+ const arg1 = {n: 0};
64
+ const arg2 = {n: 1};
65
+ objectTransformer([rule])({}, {}, arg1, arg2);
66
+ sinon.assert.calledWith(applies, arg1, arg2);
67
+ });
68
+
69
+ it('collects rule results', () => {
70
+ let i = 0;
71
+ run.callsFake(() => i++);
72
+ const result = objectTransformer([rule])({}, {});
73
+ expect(result).to.eql([0, 1]);
74
+ })
75
+ });
76
+
77
+ describe('using redact rules', () => {
78
+ Object.entries({
79
+ replacement: {
80
+ get(path, val) {
81
+ return `repl${val}`
82
+ },
83
+ expectation(parent, prop, val) {
84
+ sinon.assert.match(parent, {
85
+ [prop]: val
86
+ })
87
+ }
88
+ },
89
+ removal: {
90
+ get(path, val) {},
91
+ expectation(parent, prop, val) {
92
+ expect(Object.keys(parent)).to.not.include.members([prop]);
93
+ }
94
+ }
95
+ }).forEach(([t, {get, expectation}]) => {
96
+ describe(`property ${t}`, () => {
97
+ it('should work on top level properties', () => {
98
+ const obj = {foo: 1, bar: 2};
99
+ objectTransformer([
100
+ redactRule({
101
+ name: 'test',
102
+ get,
103
+ paths: ['foo'],
104
+ applies() { return true }
105
+ })
106
+ ])({}, obj);
107
+ sinon.assert.match(obj, {
108
+ bar: 2
109
+ });
110
+ expectation(obj, 'foo', get(1));
111
+ });
112
+ it('should work on nested properties', () => {
113
+ const obj = {outer: {inner: {foo: 'bar'}, baz: 0}};
114
+ objectTransformer([
115
+ redactRule({
116
+ name: 'test',
117
+ get,
118
+ paths: ['outer.inner.foo'],
119
+ applies() { return true; }
120
+ })
121
+ ])({}, obj);
122
+ sinon.assert.match(obj, {
123
+ outer: {
124
+ baz: 0
125
+ }
126
+ });
127
+ expectation(obj.outer.inner, 'foo', get('bar'))
128
+ })
129
+ });
130
+ });
131
+ describe('should not run rule if property is', () => {
132
+ Object.entries({
133
+ 'missing': {},
134
+ 'empty array': {foo: []},
135
+ 'empty object': {foo: {}},
136
+ 'null': {foo: null},
137
+ 'undefined': {foo: undefined}
138
+ }).forEach(([t, obj]) => {
139
+ it(t, () => {
140
+ const get = sinon.stub();
141
+ const applies = sinon.stub()
142
+ objectTransformer([redactRule({
143
+ name: 'test',
144
+ paths: ['foo'],
145
+ applies,
146
+ get,
147
+ })])({}, obj);
148
+ expect(get.called).to.be.false;
149
+ expect(applies.called).to.be.false;
150
+ })
151
+ })
152
+ });
153
+
154
+ describe('should run rule on falsy, but non-empty, value', () => {
155
+ Object.entries({
156
+ zero: 0,
157
+ false: false
158
+ }).forEach(([t, val]) => {
159
+ it(t, () => {
160
+ const obj = {foo: val};
161
+ objectTransformer([redactRule({
162
+ name: 'test',
163
+ paths: ['foo'],
164
+ applies() { return true },
165
+ get(val) { return 'repl' },
166
+ })])({}, obj);
167
+ expect(obj).to.eql({foo: 'repl'});
168
+ })
169
+ })
170
+ });
171
+
172
+ it('should not run applies twice for the same name/session combination', () => {
173
+ const applies = sinon.stub().callsFake(() => true);
174
+ const notApplies = sinon.stub().callsFake(() => false);
175
+ const t1 = objectTransformer([
176
+ {
177
+ name: 'applies',
178
+ paths: ['foo'],
179
+ applies,
180
+ get(val) { return `repl_r1_${val}`; },
181
+ },
182
+ {
183
+ name: 'notApplies',
184
+ paths: ['notFoo'],
185
+ applies: notApplies,
186
+ }
187
+ ].map(redactRule));
188
+ const t2 = objectTransformer([
189
+ {
190
+ name: 'applies',
191
+ paths: ['bar'],
192
+ applies,
193
+ get(val) { return `repl_r2_${val}` }
194
+ },
195
+ {
196
+ name: 'notApplies',
197
+ paths: ['notBar'],
198
+ applies: notApplies,
199
+ }
200
+ ].map(redactRule));
201
+ const obj = {
202
+ foo: '1',
203
+ notFoo: '2',
204
+ bar: '3',
205
+ notBar: '4'
206
+ }
207
+ const session = {};
208
+ t1(session, obj);
209
+ t2(session, obj);
210
+ expect(obj).to.eql({
211
+ foo: 'repl_r1_1',
212
+ notFoo: '2',
213
+ bar: 'repl_r2_3',
214
+ notBar: '4'
215
+ });
216
+ expect(applies.callCount).to.equal(1);
217
+ expect(notApplies.callCount).to.equal(1);
218
+ })
219
+ });
220
+ });
221
+
222
+ describe('redactor', () => {
223
+ const MODULE_TYPE = 'mockType';
224
+ const MODULE_NAME = 'mockModule';
225
+
226
+ let isAllowed, redactor;
227
+
228
+ beforeEach(() => {
229
+ isAllowed = sinon.stub();
230
+ redactor = redactorFactory((activity, params) => {
231
+ if (params[ACTIVITY_PARAM_COMPONENT_TYPE] === MODULE_TYPE && params[ACTIVITY_PARAM_COMPONENT_NAME] === MODULE_NAME) {
232
+ return isAllowed(activity)
233
+ } else {
234
+ throw new Error('wrong component')
235
+ }
236
+ })(activityParams(MODULE_TYPE, MODULE_NAME));
237
+ });
238
+
239
+ function testAllowDeny(activity, fn) {
240
+ Object.entries({
241
+ allowed: true,
242
+ denied: false
243
+ }).forEach(([t, allowed]) => {
244
+ describe(`when '${activity}' is ${t}`, () => {
245
+ beforeEach(() => {
246
+ isAllowed.callsFake((act) => {
247
+ if (act === activity) {
248
+ return allowed;
249
+ } else {
250
+ throw new Error('wrong activity');
251
+ }
252
+ });
253
+ });
254
+ fn(allowed);
255
+ });
256
+ });
257
+ }
258
+
259
+ function testPropertiesAreRemoved(method, properties, allowed) {
260
+ properties.forEach(prop => {
261
+ it(`should ${allowed ? 'NOT ' : ''}remove ${prop}`, () => {
262
+ const obj = {};
263
+ deepSetValue(obj, prop, 'mockVal');
264
+ method()(obj);
265
+ expect(deepAccess(obj, prop)).to.eql(allowed ? 'mockVal' : undefined);
266
+ })
267
+ })
268
+ }
269
+
270
+ describe('.bidRequest', () => {
271
+ testAllowDeny(ACTIVITY_TRANSMIT_EIDS, (allowed) => {
272
+ testPropertiesAreRemoved(() => redactor.bidRequest, ['userId', 'userIdAsEids'], allowed);
273
+ });
274
+ });
275
+
276
+ describe('.ortb2', () => {
277
+ testAllowDeny(ACTIVITY_TRANSMIT_EIDS, (allowed) => {
278
+ testPropertiesAreRemoved(() => redactor.ortb2, ORTB_EIDS_PATHS, allowed)
279
+ });
280
+
281
+ testAllowDeny(ACTIVITY_TRANSMIT_UFPD, (allowed) => {
282
+ testPropertiesAreRemoved(() => redactor.ortb2, ORTB_UFPD_PATHS, allowed)
283
+ });
284
+
285
+ testAllowDeny(ACTIVITY_TRANSMIT_PRECISE_GEO, (allowed) => {
286
+ ORTB_GEO_PATHS.forEach(path => {
287
+ it(`should ${allowed ? 'NOT ' : ''} round down ${path}`, () => {
288
+ const ortb2 = {};
289
+ deepSetValue(ortb2, path, 1.2345);
290
+ redactor.ortb2(ortb2);
291
+ expect(deepAccess(ortb2, path)).to.eql(allowed ? 1.2345 : 1.23);
292
+ })
293
+ })
294
+ })
295
+ });
296
+ })