1 // META: script=/common/dispatcher/dispatcher.js
2 // META: script=/common/utils.js
3 // META: script=resources/support.sub.js
4 // META: script=/fenced-frame/resources/utils.js
6 // Spec: https://wicg.github.io/private-network-access/#integration-fetch
8 // These tests verify that contexts can navigate fenced frames to less-public
9 // address spaces iff the target server responds affirmatively to preflight
13 assert_true(window.isSecureContext);
16 // Source: secure local context.
18 // All fetches unaffected by Private Network Access.
20 promise_test_parallel(
21 t => fencedFrameTest(t, {
22 source: {server: Server.HTTPS_LOCAL},
23 target: {server: Server.HTTPS_LOCAL},
24 expected: FrameTestResult.SUCCESS,
26 'local to local: no preflight required.');
28 promise_test_parallel(
29 t => fencedFrameTest(t, {
30 source: {server: Server.HTTPS_LOCAL},
31 target: {server: Server.HTTPS_PRIVATE},
32 expected: FrameTestResult.SUCCESS,
34 'local to private: no preflight required.');
36 promise_test_parallel(
37 t => fencedFrameTest(t, {
38 source: {server: Server.HTTPS_LOCAL},
39 target: {server: Server.HTTPS_PUBLIC},
40 expected: FrameTestResult.SUCCESS,
42 'local to public: no preflight required.');
44 // Generates tests of preflight behavior for a single (source, target) pair.
48 // - parent navigates child:
49 // - preflight response has non-2xx HTTP code
50 // - preflight response is missing CORS headers
51 // - preflight response is missing the PNA-specific `Access-Control` header
52 // - preflight response has the required PNA related headers, but still fails
53 // because of the limitation of fenced frame that subjects to PNA checks.
55 function makePreflightTests({
62 const prefix = `${sourceName} to ${targetName}: `;
66 treatAsPublic: sourceTreatAsPublic,
69 promise_test_parallel(
70 t => fencedFrameTest(t, {
74 behavior: {preflight: PreflightBehavior.failure()},
76 expected: FrameTestResult.FAILURE,
78 prefix + 'failed preflight.');
80 promise_test_parallel(
81 t => fencedFrameTest(t, {
85 behavior: {preflight: PreflightBehavior.noCorsHeader(token())},
87 expected: FrameTestResult.FAILURE,
89 prefix + 'missing CORS headers.');
91 promise_test_parallel(
92 t => fencedFrameTest(t, {
96 behavior: {preflight: PreflightBehavior.noPnaHeader(token())},
98 expected: FrameTestResult.FAILURE,
100 prefix + 'missing PNA header.');
102 promise_test_parallel(
103 t => fencedFrameTest(t, {
106 server: targetServer,
108 preflight: PreflightBehavior.success(token()),
109 response: ResponseBehavior.allowCrossOrigin()
112 expected: FrameTestResult.FAILURE,
114 prefix + 'failed because fenced frames are incompatible with PNA.');
117 // Source: private secure context.
119 // Fetches to the local address space require a successful preflight response
120 // carrying a PNA-specific header.
123 sourceServer: Server.HTTPS_PRIVATE,
124 sourceName: 'private',
125 targetServer: Server.HTTPS_LOCAL,
129 promise_test_parallel(
130 t => fencedFrameTest(t, {
131 source: {server: Server.HTTPS_PRIVATE},
132 target: {server: Server.HTTPS_PRIVATE},
133 expected: FrameTestResult.SUCCESS,
135 'private to private: no preflight required.');
137 promise_test_parallel(
138 t => fencedFrameTest(t, {
139 source: {server: Server.HTTPS_PRIVATE},
140 target: {server: Server.HTTPS_PUBLIC},
141 expected: FrameTestResult.SUCCESS,
143 'private to public: no preflight required.');
145 // Source: public secure context.
147 // Fetches to the local and private address spaces require a successful
148 // preflight response carrying a PNA-specific header.
151 sourceServer: Server.HTTPS_PUBLIC,
152 sourceName: 'public',
153 targetServer: Server.HTTPS_LOCAL,
158 sourceServer: Server.HTTPS_PUBLIC,
159 sourceName: 'public',
160 targetServer: Server.HTTPS_PRIVATE,
161 targetName: 'private',
164 promise_test_parallel(
165 t => fencedFrameTest(t, {
166 source: {server: Server.HTTPS_PUBLIC},
167 target: {server: Server.HTTPS_PUBLIC},
168 expected: FrameTestResult.SUCCESS,
170 'public to public: no preflight required.');
172 // The following tests verify that `CSP: treat-as-public-address` makes
173 // documents behave as if they had been served from a public IP address.
176 sourceServer: Server.HTTPS_LOCAL,
177 sourceTreatAsPublic: true,
178 sourceName: 'treat-as-public-address',
179 targetServer: Server.OTHER_HTTPS_LOCAL,
183 promise_test_parallel(
184 t => fencedFrameTest(t, {
186 server: Server.HTTPS_LOCAL,
189 target: {server: Server.HTTPS_LOCAL},
190 expected: FrameTestResult.FAILURE,
192 'treat-as-public-address to local (same-origin): fenced frame embedder ' +
193 'initiated navigation has opaque origin.');
196 sourceServer: Server.HTTPS_LOCAL,
197 sourceTreatAsPublic: true,
198 sourceName: 'treat-as-public-address',
199 targetServer: Server.HTTPS_PRIVATE,
200 targetName: 'private',
203 promise_test_parallel(
204 t => fencedFrameTest(t, {
206 server: Server.HTTPS_LOCAL,
209 target: {server: Server.HTTPS_PUBLIC},
210 expected: FrameTestResult.SUCCESS,
212 'treat-as-public-address to public: no preflight required.');
214 promise_test_parallel(
215 t => fencedFrameTest(t, {
217 server: Server.HTTPS_LOCAL,
221 server: Server.HTTPS_PUBLIC,
222 behavior: {preflight: PreflightBehavior.optionalSuccess(token())}
224 expected: FrameTestResult.SUCCESS,
226 'treat-as-public-address to local: optional preflight');