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
|
// META: script=/resources/testdriver.js
// META: script=/common/utils.js
// META: script=resources/fledge-util.js
// META: timeout=long
"use strict";
// These tests focus on trustedBiddingSignals: Requesting them, handling network
// errors, handling the keys portion of the response, and passing keys to
// worklet scripts, and handling the Data-Version header
//
// Because of request batching, left over interest groups from
// other tests may result in tests that request TRUSTED_BIDDING_SIGNALS_URL
// with certain special keys failing, if interest groups with names other than
// the default one are not successfully left after previously run tests.
// Helper for trusted bidding signals test. Runs an auction, and fails the
// test if there's no winner. "generateBidCheck" is an expression that should
// be true when evaluated in generateBid(). "interestGroupOverrides" is a
// set of overridden fields added to the default interestGroup when joining it,
// allowing trusted bidding signals keys and URL to be set, in addition to other
// fields.
async function runTrustedBiddingSignalsTest(
test, generateBidCheck, interestGroupOverrides = {}) {
interestGroupOverrides.biddingLogicUrl =
createBiddingScriptUrl({
generateBid: `if (!(${generateBidCheck})) return false;` });
await runBasicFledgeTestExpectingWinner(
test, {interestGroupOverrides: interestGroupOverrides});
}
// Much like runTrustedBiddingSignalsTest, but runs auctions through reporting
// as well, and evaluates `check` both in generateBid() and reportWin(). Also
// makes sure browserSignals.dataVersion is undefined in scoreAd() and
// reportResult().
async function runTrustedBiddingSignalsDataVersionTest(
test, check, interestGroupOverrides = {}) {
const uuid = generateUuid(test);
interestGroupOverrides.biddingLogicUrl =
createBiddingScriptUrl({
generateBid:
`if (!(${check})) return false;`,
reportWin:
`if (!(${check}))
sendReportTo('${createBidderReportUrl(uuid, 'error')}');
else
sendReportTo('${createBidderReportUrl(uuid)}');` });
await joinInterestGroup(test, uuid, interestGroupOverrides);
const auctionConfigOverrides = {
decisionLogicUrl: createDecisionScriptUrl(
uuid,
{ scoreAd:
`if (browserSignals.dataVersion !== undefined)
return false;`,
reportResult:
`if (browserSignals.dataVersion !== undefined)
sendReportTo('${createSellerReportUrl(uuid, 'error')}')
sendReportTo('${createSellerReportUrl(uuid)}')`,
})
}
await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfigOverrides);
await waitForObservedRequests(
uuid, [createBidderReportUrl(uuid), createSellerReportUrl(uuid)]);
}
promise_test(async test => {
await runTrustedBiddingSignalsTest(test, 'trustedBiddingSignals === null');
}, 'No trustedBiddingSignalsKeys or trustedBiddingSignalsUrl.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['numValue'] });
}, 'trustedBiddingSignalsKeys but no trustedBiddingSignalsUrl.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'trustedBiddingSignalsUrl without trustedBiddingSignalsKeys.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['close-connection'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'trustedBiddingSignalsUrl closes the connection without sending anything.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['http-error'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response is HTTP 404 error.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['no-content-type'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has no content-type.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['wrong-content-type'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has wrong content-type.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['fledge-not-allowed'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response does not allow fledge.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['bad-allow-fledge'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has wrong X-Allow-FLEDGE header.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['no-allow-fledge'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has no X-Allow-FLEDGE header.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['replace-body:'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has no body.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['replace-body:Not JSON'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response is not JSON.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['replace-body:[]'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response is a JSON array.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals === null',
{ trustedBiddingSignalsKeys: ['replace-body:{JSON_keys_need_quotes: 1}'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response in invalid JSON object.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals["replace-body:{}"] === null',
{ trustedBiddingSignalsKeys: ['replace-body:{}'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has no keys object.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, `trustedBiddingSignals['replace-body:{"keys":{}}'] === null`,
{ trustedBiddingSignalsKeys: ['replace-body:{"keys":{}}'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has no keys.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`trustedBiddingSignals["0"] === null &&
trustedBiddingSignals["1"] === null &&
trustedBiddingSignals["2"] === null &&
trustedBiddingSignals["length"] === null`,
{ trustedBiddingSignalsKeys:
['replace-body:{"keys":[1,2,3]}', "0", "1", "2", "length"],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response keys is incorrectly an array.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`trustedBiddingSignals["wrong-value"] === null &&
trustedBiddingSignals["another-value"] === undefined`,
{ trustedBiddingSignalsKeys: ['wrong-value'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has key not in trustedBiddingSignalsKeys.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals["null-value"] === null',
{ trustedBiddingSignalsKeys: ['null-value'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response null value for key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals["num-value"] === 1',
{ trustedBiddingSignalsKeys: ['num-value'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has a number value for key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test, 'trustedBiddingSignals["string-value"] === "1"',
{ trustedBiddingSignalsKeys: ['string-value'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has string value for key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`JSON.stringify(trustedBiddingSignals["array-value"]) === '[1,"foo",null]'`,
{ trustedBiddingSignalsKeys: ['array-value'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has array value for key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`Object.keys(trustedBiddingSignals["object-value"]).length === 2 &&
trustedBiddingSignals["object-value"]["a"] === "b" &&
JSON.stringify(trustedBiddingSignals["object-value"]["c"]) === '["d"]'`,
{ trustedBiddingSignalsKeys: ['object-value'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has object value for key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
'trustedBiddingSignals[""] === "default value"',
{ trustedBiddingSignalsKeys: [''],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals receives empty string key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`Object.keys(trustedBiddingSignals).length === 6 &&
trustedBiddingSignals["wrong-value"] === null &&
trustedBiddingSignals["null-value"] === null &&
trustedBiddingSignals["num-value"] === 1 &&
trustedBiddingSignals["string-value"] === "1" &&
JSON.stringify(trustedBiddingSignals["array-value"]) === '[1,"foo",null]' &&
trustedBiddingSignals[""] === "default value"`,
{ trustedBiddingSignalsKeys: ['wrong-value', 'null-value', 'num-value',
'string-value', 'array-value', ''],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has multiple keys.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
'trustedBiddingSignals["+%20 \x00?,3#&"] === "default value"',
{ trustedBiddingSignalsKeys: ['+%20 \x00?,3#&'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals receives escaped key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
'trustedBiddingSignals["\x00"] === "default value"',
{ trustedBiddingSignalsKeys: ['\x00'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals receives null key.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`trustedBiddingSignals["interest-group-names"] === '["${DEFAULT_INTEREST_GROUP_NAME}"]'`,
{ trustedBiddingSignalsKeys: ['interest-group-names'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals receives interest group name.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
// Interest group names is a JSONified list of JSONified names, so the
// null ends up being escaped twice.
`trustedBiddingSignals["interest-group-names"] === '["+%20 \\\\u0000?,3#&"]'`,
{ name: '+%20 \x00?,3#&',
trustedBiddingSignalsKeys: ['interest-group-names'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals receives escaped interest group name.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`trustedBiddingSignals["interest-group-names"] === '[""]'`,
{ name: '',
trustedBiddingSignalsKeys: ['interest-group-names'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals receives empty interest group name.');
promise_test(async test => {
await runTrustedBiddingSignalsTest(
test,
`trustedBiddingSignals["hostname"] === "${window.location.hostname}"`,
{ trustedBiddingSignalsKeys: ['hostname'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals receives hostname field.');
/////////////////////////////////////////////////////////////////////////////
// Data-Version tests
/////////////////////////////////////////////////////////////////////////////
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['num-value'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has no data-version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === 3',
{ trustedBiddingSignalsKeys: ['data-version:3'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has numeric Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === 0',
{ trustedBiddingSignalsKeys: ['data-version:0'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has min Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === 4294967295',
{ trustedBiddingSignalsKeys: ['data-version:4294967295'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has max Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:4294967296'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has too large Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:03'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has Data-Version with leading 0.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:-1'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has negative Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:1.3'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has decimal in Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:2 2'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has space in Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:0x4'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has hex Data-Version.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === 4',
{ name: 'data-version',
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response has Data-Version and no trustedBiddingSignalsKeys.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:3', 'replace-body:'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response with Data-Version and empty body.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:3', 'replace-body:[]'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response with Data-Version and JSON array body.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === undefined',
{ trustedBiddingSignalsKeys: ['data-version:3', 'replace-body:{} {}'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response with Data-Version and double JSON object body.');
promise_test(async test => {
await runTrustedBiddingSignalsDataVersionTest(
test,
'browserSignals.dataVersion === 3',
{ trustedBiddingSignalsKeys: ['data-version:3', 'replace-body:{"keys":5}'],
trustedBiddingSignalsUrl: TRUSTED_BIDDING_SIGNALS_URL });
}, 'Trusted bidding signals response with Data-Version and invalid keys entry');
|