forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauction-config.https.sub.window.js
271 lines (236 loc) · 7.89 KB
/
auction-config.https.sub.window.js
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
// META: script=/resources/testdriver.js
// META: script=/common/utils.js
// META: script=resources/fledge-util.js
"use strict;"
// The tests in this file focus on calls to runAdAuction with various
// auctionConfigs.
// We handle promise rejections ourselves.
setup({ allow_uncaught_exception: true });
// Helper for when we expect it to happen.
const interceptUnhandledRejection = () => {
let invokePromiseResolved;
let eventHandler = event => {
event.preventDefault();
invokePromiseResolved(event.reason);
}
window.addEventListener("unhandledrejection", eventHandler, {once: true});
return new Promise((resolved) => {
invokePromiseResolved = resolved;
});
}
// Helper for when we expect it to not happen. This relies on the event
// dispatching being sync.
const unexpectedUnhandledRejection = () => {
let o = { sawError : false }
window.addEventListener("unhandledrejection", event => {
o.sawError = true;
}, {once: true});
return o;
}
const makeTest = ({
// Test name
name,
// Expectation function (EXPECT_NULL, etc.)
expect,
// Overrides to the auction config.
auctionConfigOverrides = {},
// Expectation for a promise error.
expectPromiseError,
}) => {
promise_test(async test => {
let waitPromiseError, dontExpectPromiseError;
if (expectPromiseError) {
waitPromiseError = interceptUnhandledRejection();
} else {
dontExpectPromiseError = unexpectedUnhandledRejection();
}
const uuid = generateUuid(test);
// Join an interest group so the auction actually runs.
await joinInterestGroup(test, uuid);
let auctionResult;
try {
auctionResult = await runBasicFledgeAuction(test, uuid, auctionConfigOverrides);
} catch (e) {
auctionResult = e;
}
expect(auctionResult);
if (expectPromiseError) {
expectPromiseError(await waitPromiseError);
} else {
assert_false(dontExpectPromiseError.sawError,
"Should not see a promise error");
}
}, name);
};
// Expect an unsuccessful auction (yielding null).
const EXPECT_NO_WINNER = auctionResult => {
assert_equals(auctionResult, null, 'Auction unexpected had a winner');
};
// Expect an exception of the given type.
const EXPECT_EXCEPTION = exceptionType => auctionResult => {
assert_not_equals(auctionResult, null, "got null instead of expected error");
assert_true(auctionResult instanceof Error, "did not get expected error: " + auctionResult);
assert_throws_js(exceptionType, () => { throw auctionResult; });
};
const EXPECT_PROMISE_ERROR = auctionResult => {
assert_not_equals(auctionResult, null, "got null instead of expected error");
// TODO(morlovich): I suspect this will end up being spec'd differently.
assert_true(typeof auctionResult === "string",
"did not get expected error: " + auctionResult);
}
makeTest({
name: 'no buyers => no winners',
expect: EXPECT_NO_WINNER,
auctionConfigOverrides: {interestGroupBuyers: []},
});
makeTest({
name: 'seller is not an https URL',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {seller: "ftp://not-https"},
});
makeTest({
name: 'decisionLogicURL is invalid',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { decisionLogicURL: "https://foo:99999999999" },
});
makeTest({
name: 'decisionLogicURL is cross-origin with seller',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { decisionLogicURL: "https://example.com" },
});
makeTest({
name: 'trustedScoringSignalsURL is invalid',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { trustedScoringSignalsURL: "https://foo:99999999999" },
});
makeTest({
name: 'trustedScoringSignalsURL is cross-origin with seller',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { trustedScoringSignalsURL: "https://example.com" },
});
makeTest({
name: 'interestGroupBuyer is invalid',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { interestGroupBuyers: ["https://foo:99999999999"] },
});
makeTest({
name: 'interestGroupBuyer is not https',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { interestGroupBuyers: ["http://example.com"] },
});
makeTest({
name: 'only one interestGroupBuyer is invalid',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {
interestGroupBuyers: ["https://example.com", "https://foo:99999999999"],
},
});
makeTest({
name: 'only one interestGroupBuyer is not https',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {
interestGroupBuyers: ["https://example.com", "http://example.com"],
},
});
makeTest({
name: 'auctionSignals is invalid as JSON',
expect: EXPECT_PROMISE_ERROR,
expectPromiseError: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { auctionSignals: { sig: BigInt(13) } },
});
makeTest({
name: 'sellerSignals is invalid as JSON',
expect: EXPECT_PROMISE_ERROR,
expectPromiseError: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { sellerSignals: { sig: BigInt(13) } },
});
makeTest({
name: 'directFromSellerSignals is invalid',
expect: EXPECT_PROMISE_ERROR,
expectPromiseError: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { directFromSellerSignals: "https://foo:99999999999" },
});
makeTest({
name: 'directFromSellerSignals is cross-origin with seller',
expect: EXPECT_PROMISE_ERROR,
expectPromiseError: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { directFromSellerSignals: "https://example.com" },
});
makeTest({
name: 'directFromSellerSignals has nonempty query',
expect: EXPECT_PROMISE_ERROR,
expectPromiseError: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { directFromSellerSignals: window.location.origin + "?foo=bar" },
});
makeTest({
name: 'perBuyerSignals has invalid URL in a key',
expect: EXPECT_PROMISE_ERROR,
expectPromiseError: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { perBuyerSignals: { "https://foo:99999999999" : {} }},
});
makeTest({
name: 'perBuyerSignals value is invalid as JSON',
expect: EXPECT_PROMISE_ERROR,
expectPromiseError: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {
perBuyerSignals: { "https://example.com" : { sig: BigInt(1) },
}},
});
makeTest({
name: 'perBuyerGroupLimits has invalid URL in a key',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { perBuyerGroupLimits: { "https://foo:99999999999" : 5 }},
});
makeTest({
name: 'perBuyerExperimentGroupIds has invalid URL in a key',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: { perBuyerExperimentGroupIds: { "https://foo:99999999999" : 11 }},
});
makeTest({
name: 'perBuyerPrioritySignals has invalid URL in a key',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {
perBuyerPrioritySignals: { "https://foo:99999999999" : { sig: 2.5} },
},
});
makeTest({
name: 'perBuyerPrioritySignals has a value with a key with prefix "browserSignals"',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {
perBuyerPrioritySignals: { "https://example.com" : { "browserSignals.foo" : true } },
},
});
makeTest({
name: 'component auctions are not allowed within component auctions',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {
interestGroupBuyers: undefined,
componentAuctions: [
{
seller: window.location.origin,
decisionLogicURL: window.location.origin,
interestGroupBuyers: undefined,
componentAuctions: [
{
seller: window.location.origin,
decisionLogicURL: window.location.origin,
}
],
},
],
},
});
makeTest({
name: 'component auctions are not allowed with interestGroupBuyers',
expect: EXPECT_EXCEPTION(TypeError),
auctionConfigOverrides: {
interestGroupBuyers: ["https://example.com"],
componentAuctions: [
{
seller: window.location.origin,
decisionLogicURL: window.location.origin,
interestGroupBuyers: [],
},
],
},
});