Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/credentialmanager/passwordcredential-fetch.html

Issue 1868253002: Fetch: 'password' credentials mode should include credentials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Credential Manager: PasswordCredential basics.</title> 2 <title>Credential Manager: PasswordCredential basics.</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src="/serviceworker/resources/interfaces.js"></script> 5 <script src="/serviceworker/resources/interfaces.js"></script>
6 <body>
7 <input type=hidden id=thing value=sekrit>
6 <script> 8 <script>
7 var c = new PasswordCredential({ 9 var c = new PasswordCredential({
8 id: 'id', 10 id: 'id',
9 password: 'pencil', 11 password: 'pencil',
10 name: 'name', 12 name: 'name',
11 iconURL: 'https://example.com/icon.png' 13 iconURL: 'https://example.com/icon.png'
12 }); 14 });
13 15
14 promise_test(_ => { 16 promise_test(_ => {
15 var r = new Request('/', { credentials: c, body: 'this is a body', method: ' POST' }); 17 var r = new Request('/', { credentials: c, body: 'this is a body', method: ' POST' });
(...skipping 28 matching lines...) Expand all
44 promise_test(function() { 46 promise_test(function() {
45 return fetch("./resources/echo-post.php", { credentials: c, method: "POST" } ) 47 return fetch("./resources/echo-post.php", { credentials: c, method: "POST" } )
46 .then(resp => resp.json()) 48 .then(resp => resp.json())
47 .then(j => { 49 .then(j => {
48 assert_equals(j.username, 'id'); 50 assert_equals(j.username, 'id');
49 assert_equals(j.password, 'pencil'); 51 assert_equals(j.password, 'pencil');
50 }); 52 });
51 }, "Simple Fetch"); 53 }, "Simple Fetch");
52 54
53 promise_test(function() { 55 promise_test(function() {
56 document.cookie = "a=1";
57 document.cookie = "b=2";
58 return fetch("./resources/echo-cookies.php", { credentials: c, method: "POST " })
59 .then(resp => resp.json())
60 .then(j => {
61 assert_equals(j.a, '1');
62 assert_equals(j.b, '2');
63 })
64 .then(_ => {
65 document.cookie = "a=1; max-age=0";
66 document.cookie = "b=2; max-age=0";
67 });
68 }, "Simple Fetch");
Mike West 2016/04/08 18:49:25 This is the only test that has anything to do with
69
70 promise_test(function() {
54 var r1 = new Request('./resources/echo-post.php', { credentials: c, method: "POST" }); 71 var r1 = new Request('./resources/echo-post.php', { credentials: c, method: "POST" });
55 var r2 = r1.clone(); 72 var r2 = r1.clone();
56 return fetch(r1) 73 return fetch(r1)
57 .then(resp => resp.json()) 74 .then(resp => resp.json())
58 .then(j => { 75 .then(j => {
59 assert_equals(j.username, 'id'); 76 assert_equals(j.username, 'id');
60 assert_equals(j.password, 'pencil'); 77 assert_equals(j.password, 'pencil');
61 }) 78 })
62 .then(_ => fetch(r2)) 79 .then(_ => fetch(r2))
63 .then(resp => resp.json()) 80 .then(resp => resp.json())
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 }, "'additionalData': FormData properties are properly injected."); 188 }, "'additionalData': FormData properties are properly injected.");
172 189
173 promise_test(function() { 190 promise_test(function() {
174 var credential = new PasswordCredential({ 191 var credential = new PasswordCredential({
175 id: 'id', 192 id: 'id',
176 password: 'pencil', 193 password: 'pencil',
177 name: 'name', 194 name: 'name',
178 iconURL: 'https://example.com/icon.png' 195 iconURL: 'https://example.com/icon.png'
179 }); 196 });
180 197
198 credential.additionalData = new FormData();
199 credential.additionalData.append("excitingData", "exciting value");
200 credential.additionalData.append("csrf", "[randomness]");
201
202 return fetch("./resources/echo-post.php", { credentials: credential, method: "POST" })
203 .then(function (r) {
204 return r.json();
205 })
206 .then(function (j) {
207 assert_equals(j.username, 'id');
208 assert_equals(j.password, 'pencil');
209 assert_equals(j.excitingData, 'exciting value');
210 assert_equals(j.csrf, '[randomness]');
211 });
212 }, "'additionalData': FormData properties are properly injected after assignment .");
Mike West 2016/04/08 18:49:25 This is from when I thought that adding the `FormD
213
214 promise_test(function() {
215 var credential = new PasswordCredential({
216 id: 'id',
217 password: 'pencil',
218 name: 'name',
219 iconURL: 'https://example.com/icon.png'
220 });
221
181 var fd = new FormData(); 222 var fd = new FormData();
182 fd.append("username", "foo"); 223 fd.append("username", "foo");
183 fd.append("password", "bar"); 224 fd.append("password", "bar");
184 credential.additionalData = fd; 225 credential.additionalData = fd;
185 226
186 // Use post-echo.cgi since PHP doesn't give us the raw data of a POST's 227 // Use post-echo.cgi since PHP doesn't give us the raw data of a POST's
187 // body if it's multipart/form-data. 228 // body if it's multipart/form-data.
188 return fetch("/xmlhttprequest/resources/post-echo.cgi", { credentials: crede ntial, method: "POST" }) 229 return fetch("/xmlhttprequest/resources/post-echo.cgi", { credentials: crede ntial, method: "POST" })
189 .then(function (r) { 230 .then(function (r) {
190 return r.text(); 231 return r.text();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 credential.additionalData = params; 325 credential.additionalData = params;
285 326
286 return fetch("./resources/echo-raw-post.php", { credentials: credential, met hod: "POST" }) 327 return fetch("./resources/echo-raw-post.php", { credentials: credential, met hod: "POST" })
287 .then(function (r) { 328 .then(function (r) {
288 return r.text(); 329 return r.text();
289 }) 330 })
290 .then(function (t) { 331 .then(function (t) {
291 assert_equals(t, 'a=1&a=2&a=3&username=id&password=pencil'); 332 assert_equals(t, 'a=1&a=2&a=3&username=id&password=pencil');
292 }); 333 });
293 }, "'additionalData': URLSearchParams properties are properly injected (ordering matters)."); 334 }, "'additionalData': URLSearchParams properties are properly injected (ordering matters).");
335
336 promise_test(_ => {
337 var id = "id";
338 var name = "name";
339 var icon = "http://example.com/";
340 var password = "pencil";
341
342 if (window.testRunner)
343 testRunner.addMockCredentialManagerResponse(id, name, icon, password);
344
345 return navigator.credentials.get({ password: true })
346 .then(c => {
347 return fetch("./resources/echo-post.php", { credentials: c, method: "POST" })
348 .then(resp => resp.json())
349 .then(j => {
350 assert_equals(j.username, 'id');
351 assert_equals(j.password, 'pencil')
352 });
353 });
354 }, 'fetch() after get()');
Mike West 2016/04/08 18:49:25 And this is when I managed to convince myself that
355
356 promise_test(_ => {
357 var id = "id";
358 var name = "name";
359 var icon = "http://example.com/";
360 var password = "pencil";
361
362 if (window.testRunner)
363 testRunner.addMockCredentialManagerResponse(id, name, icon, password);
364
365 return navigator.credentials.get({ password: true })
366 .then(c => {
367
368 var fd = new FormData();
369 fd.append('csrf_token', 'sekrit');
370 c.additionalData = fd;
371
372 return fetch("./resources/echo-post.php", { credentials: c, method: "POST" })
373 .then(resp => resp.json())
374 .then(j => {
375 assert_equals(j.username, 'id');
376 assert_equals(j.password, 'pencil')
377 assert_equals(j.csrf_token, 'sekrit')
378 });
379 });
380 }, 'fetch() after get() with additionalData');
Mike West 2016/04/08 18:49:25 Maybe it was `get()` with a `FormData`?
381
382 promise_test(_ => {
383 var id = "id";
384 var name = "name";
385 var icon = "http://example.com/";
386 var password = "pencil";
387
388 if (window.testRunner)
389 testRunner.addMockCredentialManagerResponse(id, name, icon, password);
390
391 return navigator.credentials.get({ password: true })
392 .then(c => {
393 var fd = new FormData();
394 fd.append('csrf_token', document.querySelector('#thing').value);
395 c.additionalData = fd;
396
397 return fetch("./resources/echo-post.php", { credentials: c, method: "POST" })
398 .then(resp => resp.json())
399 .then(j => {
400 assert_equals(j.username, 'id');
401 assert_equals(j.password, 'pencil')
402 assert_equals(j.csrf_token, 'sekrit')
403 });
404 });
405 }, 'fetch() after get() with additionalData from DOM');
Mike West 2016/04/08 18:49:25 Maybe pulling data from the DOM is somehow broken?
294 </script> 406 </script>
Mike West 2016/04/08 18:49:25 There were lots more. All of them equally worthles
estark 2016/04/08 20:03:36 Aw, but on the bright side, you improved test cove
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698