prebid.js 7.51.0 → 7.53.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 (277) hide show
  1. package/dist/1plusXRtdProvider.js +1 -1
  2. package/dist/33acrossBidAdapter.js +1 -1
  3. package/dist/33acrossIdSystem.js +1 -1
  4. package/dist/adagioBidAdapter.js +1 -1
  5. package/dist/adbookpspBidAdapter.js +1 -1
  6. package/dist/adgenerationBidAdapter.js +1 -1
  7. package/dist/adkernelBidAdapter.js +1 -1
  8. package/dist/adqueryBidAdapter.js +1 -1
  9. package/dist/adrelevantisBidAdapter.js +1 -1
  10. package/dist/adriverIdSystem.js +1 -1
  11. package/dist/adtrgtmeBidAdapter.js +1 -1
  12. package/dist/adxcgBidAdapter.js +1 -1
  13. package/dist/adyoulikeBidAdapter.js +1 -1
  14. package/dist/airgridRtdProvider.js +1 -1
  15. package/dist/ajaBidAdapter.js +1 -1
  16. package/dist/allowActivities.js +1 -0
  17. package/dist/amxBidAdapter.js +1 -1
  18. package/dist/amxIdSystem.js +1 -1
  19. package/dist/appierAnalyticsAdapter.js +1 -1
  20. package/dist/appnexusBidAdapter.js +1 -1
  21. package/dist/asoBidAdapter.js +1 -1
  22. package/dist/axonixBidAdapter.js +1 -1
  23. package/dist/beopBidAdapter.js +1 -1
  24. package/dist/bidglassBidAdapter.js +1 -1
  25. package/dist/big-richmediaBidAdapter.js +1 -1
  26. package/dist/bridgewellBidAdapter.js +1 -1
  27. package/dist/brightMountainMediaBidAdapter.js +1 -1
  28. package/dist/carodaBidAdapter.js +1 -1
  29. package/dist/chtnwBidAdapter.js +1 -1
  30. package/dist/conceptxBidAdapter.js +1 -0
  31. package/dist/concertBidAdapter.js +1 -1
  32. package/dist/connectIdSystem.js +1 -1
  33. package/dist/connectadBidAdapter.js +1 -1
  34. package/dist/consumableBidAdapter.js +1 -1
  35. package/dist/conversantAnalyticsAdapter.js +1 -1
  36. package/dist/conversantBidAdapter.js +1 -1
  37. package/dist/craftBidAdapter.js +1 -1
  38. package/dist/criteoBidAdapter.js +1 -1
  39. package/dist/cwireBidAdapter.js +1 -1
  40. package/dist/dependencies.json +6 -0
  41. package/dist/dspxBidAdapter.js +1 -1
  42. package/dist/eplanningBidAdapter.js +1 -1
  43. package/dist/eskimiBidAdapter.js +1 -1
  44. package/dist/euidIdSystem.js +1 -0
  45. package/dist/feedadBidAdapter.js +1 -1
  46. package/dist/finativeBidAdapter.js +1 -1
  47. package/dist/freepassIdSystem.js +1 -0
  48. package/dist/freewheel-sspBidAdapter.js +1 -1
  49. package/dist/gdprEnforcement.js +1 -1
  50. package/dist/glimpseBidAdapter.js +1 -1
  51. package/dist/gmosspBidAdapter.js +1 -1
  52. package/dist/goldbachBidAdapter.js +1 -1
  53. package/dist/greenbidsAnalyticsAdapter.js +1 -1
  54. package/dist/greenbidsRtdProvider.js +1 -1
  55. package/dist/gridBidAdapter.js +1 -1
  56. package/dist/growthCodeRtdProvider.js +1 -0
  57. package/dist/gumgumBidAdapter.js +1 -1
  58. package/dist/h12mediaBidAdapter.js +1 -1
  59. package/dist/id5IdSystem.js +1 -1
  60. package/dist/improvedigitalBidAdapter.js +1 -1
  61. package/dist/inmarBidAdapter.js +1 -1
  62. package/dist/insticatorBidAdapter.js +1 -1
  63. package/dist/ixBidAdapter.js +1 -1
  64. package/dist/justpremiumBidAdapter.js +1 -1
  65. package/dist/kargoBidAdapter.js +1 -1
  66. package/dist/konduitAnalyticsAdapter.js +1 -1
  67. package/dist/kueezBidAdapter.js +1 -1
  68. package/dist/kueezRtbBidAdapter.js +1 -1
  69. package/dist/kulturemediaBidAdapter.js +1 -1
  70. package/dist/lassoBidAdapter.js +1 -1
  71. package/dist/lifestreetBidAdapter.js +1 -1
  72. package/dist/limelightDigitalBidAdapter.js +1 -1
  73. package/dist/liveyieldAnalyticsAdapter.js +1 -1
  74. package/dist/logicadBidAdapter.js +1 -1
  75. package/dist/loglyliftBidAdapter.js +1 -1
  76. package/dist/magniteAnalyticsAdapter.js +1 -1
  77. package/dist/malltvAnalyticsAdapter.js +1 -1
  78. package/dist/marsmediaBidAdapter.js +1 -1
  79. package/dist/mediafuseBidAdapter.js +1 -1
  80. package/dist/mediasquareBidAdapter.js +1 -1
  81. package/dist/mgidBidAdapter.js +1 -1
  82. package/dist/minutemediaBidAdapter.js +1 -1
  83. package/dist/minutemediaplusBidAdapter.js +1 -1
  84. package/dist/nexx360BidAdapter.js +1 -1
  85. package/dist/not-for-prod/prebid.js +154 -146
  86. package/dist/objectGuard.js +1 -0
  87. package/dist/oguryBidAdapter.js +1 -1
  88. package/dist/onetagBidAdapter.js +1 -1
  89. package/dist/ooloAnalyticsAdapter.js +1 -1
  90. package/dist/optidigitalBidAdapter.js +1 -1
  91. package/dist/outbrainBidAdapter.js +1 -1
  92. package/dist/oxxionAnalyticsAdapter.js +1 -0
  93. package/dist/pairIdSystem.js +1 -1
  94. package/dist/parrableIdSystem.js +1 -1
  95. package/dist/pixfutureBidAdapter.js +1 -1
  96. package/dist/prebid-core.js +1 -1
  97. package/dist/proxistoreBidAdapter.js +1 -1
  98. package/dist/publinkIdSystem.js +1 -1
  99. package/dist/pubmaticBidAdapter.js +1 -1
  100. package/dist/pubwiseAnalyticsAdapter.js +1 -1
  101. package/dist/pxyzBidAdapter.js +1 -1
  102. package/dist/quantcastBidAdapter.js +1 -1
  103. package/dist/readpeakBidAdapter.js +1 -1
  104. package/dist/relaidoBidAdapter.js +1 -1
  105. package/dist/retailspotBidAdapter.js +1 -1
  106. package/dist/rhythmoneBidAdapter.js +1 -1
  107. package/dist/richaudienceBidAdapter.js +1 -1
  108. package/dist/riseBidAdapter.js +1 -1
  109. package/dist/rtdModule.js +1 -1
  110. package/dist/rubiconAnalyticsAdapter.js +1 -1
  111. package/dist/rubiconBidAdapter.js +1 -1
  112. package/dist/schain.js +1 -1
  113. package/dist/seedingAllianceBidAdapter.js +1 -1
  114. package/dist/seedtagBidAdapter.js +1 -1
  115. package/dist/sharethroughAnalyticsAdapter.js +1 -1
  116. package/dist/sharethroughBidAdapter.js +1 -1
  117. package/dist/shinezBidAdapter.js +1 -1
  118. package/dist/sirdataRtdProvider.js +1 -1
  119. package/dist/smaatoBidAdapter.js +1 -1
  120. package/dist/smartadserverBidAdapter.js +1 -1
  121. package/dist/smartxBidAdapter.js +1 -1
  122. package/dist/smilewantedBidAdapter.js +1 -1
  123. package/dist/sonobiBidAdapter.js +1 -1
  124. package/dist/sovrnAnalyticsAdapter.js +1 -1
  125. package/dist/sovrnBidAdapter.js +1 -1
  126. package/dist/sspBCBidAdapter.js +1 -1
  127. package/dist/stroeerCoreBidAdapter.js +1 -1
  128. package/dist/stvBidAdapter.js +1 -1
  129. package/dist/sublimeBidAdapter.js +1 -1
  130. package/dist/synacormediaBidAdapter.js +1 -1
  131. package/dist/targetVideoBidAdapter.js +1 -1
  132. package/dist/teadsBidAdapter.js +1 -1
  133. package/dist/trionBidAdapter.js +1 -1
  134. package/dist/tripleliftBidAdapter.js +1 -1
  135. package/dist/ttdBidAdapter.js +1 -1
  136. package/dist/ucfunnelAnalyticsAdapter.js +1 -1
  137. package/dist/uid2IdSystem.js +1 -1
  138. package/dist/uid2IdSystem_shared.js +1 -0
  139. package/dist/underdogmediaBidAdapter.js +1 -1
  140. package/dist/undertoneBidAdapter.js +1 -1
  141. package/dist/userId.js +1 -1
  142. package/dist/vidazooBidAdapter.js +1 -1
  143. package/dist/videobyteBidAdapter.js +1 -1
  144. package/dist/viouslyBidAdapter.js +1 -1
  145. package/dist/visxBidAdapter.js +1 -1
  146. package/dist/vuukleBidAdapter.js +1 -1
  147. package/dist/weboramaRtdProvider.js +1 -1
  148. package/dist/widespaceBidAdapter.js +1 -1
  149. package/dist/winrBidAdapter.js +1 -1
  150. package/dist/yahoosspBidAdapter.js +1 -1
  151. package/dist/yieldlabBidAdapter.js +1 -1
  152. package/dist/yieldmoBidAdapter.js +1 -1
  153. package/dist/yieldoneAnalyticsAdapter.js +1 -1
  154. package/dist/zeta_global_sspBidAdapter.js +1 -1
  155. package/integrationExamples/gpt/growthcode.html +20 -9
  156. package/integrationExamples/gpt/userId_example.html +20 -6
  157. package/libraries/objectGuard/objectGuard.js +108 -0
  158. package/libraries/objectGuard/ortbGuard.js +88 -0
  159. package/modules/.submodules.json +3 -1
  160. package/modules/1plusXRtdProvider.js +31 -60
  161. package/modules/adagioBidAdapter.js +86 -24
  162. package/modules/adgenerationBidAdapter.js +14 -5
  163. package/modules/adkernelBidAdapter.js +2 -2
  164. package/modules/adriverIdSystem.js +1 -1
  165. package/modules/airgridRtdProvider.js +11 -12
  166. package/modules/allowActivities.js +74 -0
  167. package/modules/asoBidAdapter.js +2 -1
  168. package/modules/beopBidAdapter.js +6 -0
  169. package/modules/conceptxBidAdapter.js +70 -0
  170. package/modules/conceptxBidAdapter.md +36 -0
  171. package/modules/connectIdSystem.js +89 -13
  172. package/modules/connectIdSystem.md +4 -7
  173. package/modules/criteoBidAdapter.js +18 -2
  174. package/modules/eskimiBidAdapter.js +171 -41
  175. package/modules/eskimiBidAdapter.md +35 -16
  176. package/modules/euidIdSystem.js +121 -0
  177. package/modules/euidIdSystem.md +131 -0
  178. package/modules/freepassIdSystem.js +61 -0
  179. package/modules/freepassIdSystem.md +47 -0
  180. package/modules/gdprEnforcement.js +98 -169
  181. package/modules/greenbidsAnalyticsAdapter.js +1 -1
  182. package/modules/growthCodeRtdProvider.js +131 -0
  183. package/modules/growthCodeRtdProvider.md +55 -0
  184. package/modules/id5IdSystem.js +3 -5
  185. package/modules/ixBidAdapter.js +17 -3
  186. package/modules/limelightDigitalBidAdapter.js +1 -1
  187. package/modules/logicadBidAdapter.js +14 -1
  188. package/modules/mediasquareBidAdapter.js +13 -5
  189. package/modules/nexx360BidAdapter.js +1 -0
  190. package/modules/oxxionAnalyticsAdapter.js +212 -0
  191. package/modules/oxxionAnalyticsAdapter.md +33 -0
  192. package/modules/pairIdSystem.js +16 -11
  193. package/modules/proxistoreBidAdapter.js +11 -14
  194. package/modules/richaudienceBidAdapter.js +10 -1
  195. package/modules/riseBidAdapter.js +1 -1
  196. package/modules/rtdModule/index.js +12 -1
  197. package/modules/schain.js +2 -2
  198. package/modules/sharethroughBidAdapter.js +2 -2
  199. package/modules/sirdataRtdProvider.js +73 -146
  200. package/modules/smartadserverBidAdapter.js +5 -0
  201. package/modules/sovrnBidAdapter.js +4 -1
  202. package/modules/stroeerCoreBidAdapter.js +55 -6
  203. package/modules/stvBidAdapter.js +34 -1
  204. package/modules/uid2IdSystem.js +27 -210
  205. package/modules/uid2IdSystem.md +104 -23
  206. package/modules/uid2IdSystem_shared.js +232 -0
  207. package/modules/undertoneBidAdapter.js +9 -1
  208. package/modules/userId/eids.js +8 -0
  209. package/modules/userId/index.js +69 -41
  210. package/modules/userId/userId.md +2 -1
  211. package/modules/viouslyBidAdapter.js +2 -2
  212. package/modules/weboramaRtdProvider.js +25 -95
  213. package/modules/weboramaRtdProvider.md +4 -4
  214. package/modules/yahoosspBidAdapter.js +45 -3
  215. package/modules/yahoosspBidAdapter.md +1 -1
  216. package/modules/yieldlabBidAdapter.js +23 -14
  217. package/modules/zeta_global_sspBidAdapter.js +28 -22
  218. package/package.json +1 -1
  219. package/src/activities/activities.js +47 -0
  220. package/src/activities/activityParams.js +8 -0
  221. package/src/activities/modules.js +1 -1
  222. package/src/activities/params.js +59 -0
  223. package/src/activities/redactor.js +157 -0
  224. package/src/activities/rules.js +95 -0
  225. package/src/adapterManager.js +45 -8
  226. package/src/adloader.js +1 -0
  227. package/src/fpd/rootDomain.js +1 -1
  228. package/src/prebid.js +1 -1
  229. package/src/storageManager.js +57 -44
  230. package/src/userSync.js +35 -18
  231. package/test/spec/activities/allowActivites_spec.js +138 -0
  232. package/test/spec/activities/objectGuard_spec.js +144 -0
  233. package/test/spec/activities/ortbGuard_spec.js +140 -0
  234. package/test/spec/activities/params_spec.js +25 -0
  235. package/test/spec/activities/redactor_spec.js +296 -0
  236. package/test/spec/activities/rules_spec.js +135 -0
  237. package/test/spec/modules/1plusXRtdProvider_spec.js +98 -149
  238. package/test/spec/modules/adagioBidAdapter_spec.js +46 -17
  239. package/test/spec/modules/adgenerationBidAdapter_spec.js +52 -12
  240. package/test/spec/modules/airgridRtdProvider_spec.js +2 -0
  241. package/test/spec/modules/beopBidAdapter_spec.js +24 -0
  242. package/test/spec/modules/conceptxBidAdapter_spec.js +136 -0
  243. package/test/spec/modules/connectIdSystem_spec.js +291 -23
  244. package/test/spec/modules/criteoBidAdapter_spec.js +85 -1
  245. package/test/spec/modules/eids_spec.js +15 -0
  246. package/test/spec/modules/eskimiBidAdapter_spec.js +264 -112
  247. package/test/spec/modules/euidIdSystem_spec.js +130 -0
  248. package/test/spec/modules/freepassIdSystem_spec.js +186 -0
  249. package/test/spec/modules/gdprEnforcement_spec.js +127 -414
  250. package/test/spec/modules/growthCodeRtdProvider_spec.js +127 -0
  251. package/test/spec/modules/id5IdSystem_spec.js +10 -3
  252. package/test/spec/modules/ixBidAdapter_spec.js +32 -1
  253. package/test/spec/modules/logicadBidAdapter_spec.js +122 -2
  254. package/test/spec/modules/mediasquareBidAdapter_spec.js +4 -0
  255. package/test/spec/modules/oxxionAnalyticsAdapter_spec.js +324 -0
  256. package/test/spec/modules/pairIdSystem_spec.js +16 -3
  257. package/test/spec/modules/realTimeDataModule_spec.js +1 -1
  258. package/test/spec/modules/richaudienceBidAdapter_spec.js +44 -0
  259. package/test/spec/modules/schain_spec.js +9 -0
  260. package/test/spec/modules/sharethroughBidAdapter_spec.js +1 -1
  261. package/test/spec/modules/sirdataRtdProvider_spec.js +110 -17
  262. package/test/spec/modules/smartadserverBidAdapter_spec.js +42 -0
  263. package/test/spec/modules/sovrnBidAdapter_spec.js +13 -0
  264. package/test/spec/modules/stroeerCoreBidAdapter_spec.js +151 -6
  265. package/test/spec/modules/stvBidAdapter_spec.js +13 -1
  266. package/test/spec/modules/uid2IdSystem_helpers.js +70 -0
  267. package/test/spec/modules/uid2IdSystem_spec.js +131 -86
  268. package/test/spec/modules/undertoneBidAdapter_spec.js +57 -1
  269. package/test/spec/modules/userId_spec.js +96 -33
  270. package/test/spec/modules/weboramaRtdProvider_spec.js +331 -205
  271. package/test/spec/modules/yahoosspBidAdapter_spec.js +103 -51
  272. package/test/spec/modules/yieldlabBidAdapter_spec.js +42 -2
  273. package/test/spec/modules/zeta_global_sspBidAdapter_spec.js +204 -4
  274. package/test/spec/unit/core/adapterManager_spec.js +181 -1
  275. package/test/spec/unit/core/storageManager_spec.js +76 -68
  276. package/test/spec/unit/pbjs_api_spec.js +15 -25
  277. package/test/spec/userSync_spec.js +45 -16
@@ -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
+ })
@@ -0,0 +1,135 @@
1
+ import {ruleRegistry} from '../../../src/activities/rules.js';
2
+
3
+ describe('Activity control rules', () => {
4
+ const MOCK_ACTIVITY = 'mockActivity';
5
+ const MOCK_RULE = 'mockRule';
6
+
7
+ let registerRule, isAllowed, logger;
8
+
9
+ beforeEach(() => {
10
+ logger = {
11
+ logInfo: sinon.stub(),
12
+ logWarn: sinon.stub(),
13
+ logError: sinon.stub(),
14
+ };
15
+ [registerRule, isAllowed] = ruleRegistry(logger);
16
+ });
17
+
18
+ it('allows by default', () => {
19
+ expect(isAllowed(MOCK_ACTIVITY, {})).to.be.true;
20
+ });
21
+
22
+ it('denies if a rule throws', () => {
23
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => {
24
+ throw new Error('argh');
25
+ });
26
+ expect(isAllowed(MOCK_ACTIVITY, {})).to.be.false;
27
+ });
28
+
29
+ it('denies if a rule denies', () => {
30
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false}));
31
+ expect(isAllowed(MOCK_ACTIVITY, {})).to.be.false;
32
+ });
33
+
34
+ it('partitions rules by activity', () => {
35
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false}));
36
+ expect(isAllowed('other', {})).to.be.true;
37
+ });
38
+
39
+ it('passes params to rules', () => {
40
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, (params) => ({allow: params.foo !== 'bar'}));
41
+ expect(isAllowed(MOCK_ACTIVITY, {foo: 'notbar'})).to.be.true;
42
+ expect(isAllowed(MOCK_ACTIVITY, {foo: 'bar'})).to.be.false;
43
+ });
44
+
45
+ it('allows if rules do not opine', () => {
46
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => null);
47
+ expect(isAllowed(MOCK_ACTIVITY, {foo: 'bar'})).to.be.true;
48
+ });
49
+
50
+ it('denies if any rule denies', () => {
51
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => null);
52
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: true}));
53
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false}));
54
+ expect(isAllowed(MOCK_ACTIVITY, {foo: 'bar'})).to.be.false;
55
+ });
56
+
57
+ it('allows if higher priority allow rule trumps a lower priority deny rule', () => {
58
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false}));
59
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: true}), 0);
60
+ expect(isAllowed(MOCK_ACTIVITY, {})).to.be.true;
61
+ });
62
+
63
+ it('denies if a higher priority deny rule trumps a lower priority allow rule', () => {
64
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: true}));
65
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false}), 0);
66
+ expect(isAllowed(MOCK_ACTIVITY, {})).to.be.false;
67
+ });
68
+
69
+ it('can unregister rules', () => {
70
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: true}));
71
+ const r = registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false}), 0);
72
+ expect(isAllowed(MOCK_ACTIVITY, {})).to.be.false;
73
+ r();
74
+ expect(isAllowed(MOCK_ACTIVITY, {})).to.be.true;
75
+ })
76
+
77
+ it('logs INFO when explicit allow is found', () => {
78
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: true}));
79
+ isAllowed(MOCK_ACTIVITY, {});
80
+ sinon.assert.calledWithMatch(logger.logInfo, new RegExp(MOCK_RULE));
81
+ });
82
+
83
+ it('logs INFO with reason if the rule provides one', () => {
84
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: true, reason: 'because'}));
85
+ isAllowed(MOCK_ACTIVITY, {});
86
+ sinon.assert.calledWithMatch(logger.logInfo, new RegExp(MOCK_RULE), /because/);
87
+ });
88
+
89
+ it('logs WARN when a deny is found', () => {
90
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false}));
91
+ isAllowed(MOCK_ACTIVITY, {});
92
+ sinon.assert.calledWithMatch(logger.logWarn, new RegExp(MOCK_RULE));
93
+ });
94
+
95
+ it('logs WARN with reason if the rule provides one', () => {
96
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({allow: false, reason: 'fail'}));
97
+ isAllowed(MOCK_ACTIVITY, {});
98
+ sinon.assert.calledWithMatch(logger.logWarn, new RegExp(MOCK_RULE), /fail/);
99
+ });
100
+
101
+ describe('log message deduping', () => {
102
+ let clock, allow;
103
+ beforeEach(() => {
104
+ allow = false;
105
+ registerRule(MOCK_ACTIVITY, MOCK_RULE, () => ({ allow }));
106
+ clock = sinon.useFakeTimers();
107
+ });
108
+ afterEach(() => {
109
+ clock.restore();
110
+ });
111
+
112
+ it('is applied to identical messages that are close in time', () => {
113
+ isAllowed(MOCK_ACTIVITY, {});
114
+ clock.tick(100);
115
+ isAllowed(MOCK_ACTIVITY, {});
116
+ expect(logger.logWarn.callCount).to.equal(1);
117
+ });
118
+
119
+ it('not to messages that show different results', () => {
120
+ isAllowed(MOCK_ACTIVITY, {});
121
+ allow = true;
122
+ clock.tick(100);
123
+ isAllowed(MOCK_ACTIVITY, {});
124
+ expect(logger.logWarn.callCount).to.equal(1);
125
+ expect(logger.logInfo.callCount).to.equal(1);
126
+ });
127
+
128
+ it('not to messages that are further apart in time', () => {
129
+ isAllowed(MOCK_ACTIVITY, {});
130
+ clock.tick(2000);
131
+ isAllowed(MOCK_ACTIVITY, {});
132
+ expect(logger.logWarn.callCount).to.equal(2);
133
+ })
134
+ })
135
+ });