Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <script> | 6 <script> |
| 7 var c = new PasswordCredential({ | |
| 8 id: 'id', | |
| 9 password: 'pencil', | |
| 10 name: 'name', | |
| 11 iconURL: 'https://example.com/icon.png' | |
| 12 }); | |
| 13 | |
| 14 promise_test(_ => { | |
| 15 var r = new Request('/', { credentials: c, method: 'POST' }); | |
| 16 var clone = r.clone(); | |
| 17 assert_equals(r.credentials, "password"); | |
| 18 assert_equals(clone.credentials, "password"); | |
| 19 r.text().then(t => assert_equals(t, "")); | |
| 20 clone.text().then(t => assert_equals(t, "")); | |
| 21 }, "Creating a 'Request' does not expose the credential."); | |
| 22 | |
| 23 promise_test(_ => { | |
| 24 assert_throws(new TypeError(), _ => new Request("https://cross-origin.exampl e.test/", { credentials: c, method: 'POST' })); | |
| 25 assert_throws(new TypeError(), _ => new Request("/", { credentials: c, metho d: 'GET' })); | |
| 26 assert_throws(new TypeError(), _ => new Request("/", { credentials: c, metho d: 'HEAD' })); | |
| 27 assert_throws(new TypeError(), _ => new Request("/", { credentials: 'passwor d', method: 'POST' })); | |
| 28 assert_throws(new TypeError(), _ => new Request("/", { credentials: 'passwor d', method: 'GET' })); | |
| 29 assert_throws(new TypeError(), _ => new Request("/", { credentials: 'passwor d', body: "Body", method: 'GET' })); | |
| 30 }, "Creating a 'Request' throws in various ways."); | |
| 31 | |
| 7 promise_test(function() { | 32 promise_test(function() { |
| 8 var credential = new PasswordCredential({ | 33 return fetch("./resources/echo-post.php", { credentials: c, method: "POST" } ) |
| 9 id: 'id', | 34 .then(resp => resp.json()) |
| 10 password: 'pencil', | 35 .then(j => { |
| 11 name: 'name', | |
| 12 iconURL: 'https://example.com/icon.png' | |
| 13 }); | |
| 14 | |
| 15 return fetch("./resources/echo-post.php", { body: credential, method: "POST" }) | |
| 16 .then(function (r) { | |
| 17 return r.json(); | |
| 18 }) | |
| 19 .then(function (j) { | |
| 20 assert_equals(j.username, 'id'); | 36 assert_equals(j.username, 'id'); |
| 21 assert_equals(j.password, 'pencil'); | 37 assert_equals(j.password, 'pencil'); |
| 22 }); | 38 }); |
| 23 }, "Simple Fetch"); | 39 }, "Simple Fetch"); |
| 24 | 40 |
| 25 promise_test(function() { | 41 promise_test(function() { |
| 42 var req = new Request('./resources/echo-post.php', { credentials: c, method: "POST" }); | |
| 43 var clone = req.clone(); | |
| 44 fetch(clone) | |
|
horo
2016/04/04 14:13:04
You have to return the promise.
Line 44 must be "r
| |
| 45 .then(resp => resp.json()) | |
| 46 .then(j => { | |
| 47 assert_equals(j.username, 'id'); | |
| 48 assert_equals(j.password, 'pencil'); | |
| 49 }); | |
| 50 }, "Fetch with cloned Request"); | |
| 51 | |
| 52 promise_test(function() { | |
| 26 var credential = new PasswordCredential({ | 53 var credential = new PasswordCredential({ |
| 27 id: 'id', | 54 id: 'id', |
| 28 password: 'pencil', | 55 password: 'pencil', |
| 29 name: 'name', | 56 name: 'name', |
| 30 iconURL: 'https://example.com/icon.png' | 57 iconURL: 'https://example.com/icon.png' |
| 31 }); | 58 }); |
| 32 | 59 |
| 33 credential.idName = "notUsername"; | 60 credential.idName = "notUsername"; |
| 34 credential.passwordName = "notPassword"; | 61 credential.passwordName = "notPassword"; |
| 35 | 62 |
| 36 return fetch("./resources/echo-post.php", { body: credential, method: "POST" }) | 63 return fetch("./resources/echo-post.php", { credentials: credential, method: "POST" }) |
| 37 .then(function (r) { | 64 .then(function (r) { |
| 38 return r.json() | 65 return r.json() |
| 39 }) | 66 }) |
| 40 .then(function (j) { | 67 .then(function (j) { |
| 41 assert_equals(j.username, undefined); | 68 assert_equals(j.username, undefined); |
| 42 assert_equals(j.password, undefined); | 69 assert_equals(j.password, undefined); |
| 43 assert_equals(j.notUsername, 'id'); | 70 assert_equals(j.notUsername, 'id'); |
| 44 assert_equals(j.notPassword, 'pencil'); | 71 assert_equals(j.notPassword, 'pencil'); |
| 45 }); | 72 }); |
| 46 }, "'idName' and 'passwordName'"); | 73 }, "'idName' and 'passwordName'"); |
| 47 | 74 |
| 48 promise_test(function() { | 75 promise_test(function() { |
| 49 var credential = new PasswordCredential({ | 76 var credential = new PasswordCredential({ |
| 50 id: 'id', | 77 id: 'id', |
| 51 password: 'pencil', | 78 password: 'pencil', |
| 52 name: 'name', | 79 name: 'name', |
| 53 iconURL: 'https://example.com/icon.png' | 80 iconURL: 'https://example.com/icon.png' |
| 54 }); | 81 }); |
| 55 | 82 |
| 56 var fd = new FormData(); | 83 var fd = new FormData(); |
| 57 credential.additionalData = fd; | 84 credential.additionalData = fd; |
| 58 | 85 |
| 59 return fetch("./resources/echo-post.php", { body: credential, method: "POST" }) | 86 return fetch("./resources/echo-post.php", { credentials: credential, method: "POST" }) |
| 60 .then(function (r) { | 87 .then(function (r) { |
| 61 return r.json(); | 88 return r.json(); |
| 62 }) | 89 }) |
| 63 .then(function (j) { | 90 .then(function (j) { |
| 64 assert_equals(j.username, 'id'); | 91 assert_equals(j.username, 'id'); |
| 65 assert_equals(j.password, 'pencil'); | 92 assert_equals(j.password, 'pencil'); |
| 66 }); | 93 }); |
| 67 }, "'additionalData': Empty FormData has no effect."); | 94 }, "'additionalData': Empty FormData has no effect."); |
| 68 | 95 |
| 69 promise_test(function() { | 96 promise_test(function() { |
| 70 var credential = new PasswordCredential({ | 97 var credential = new PasswordCredential({ |
| 71 id: 'id', | 98 id: 'id', |
| 72 password: 'pencil', | 99 password: 'pencil', |
| 73 name: 'name', | 100 name: 'name', |
| 74 iconURL: 'https://example.com/icon.png' | 101 iconURL: 'https://example.com/icon.png' |
| 75 }); | 102 }); |
| 76 | 103 |
| 77 var fd = new FormData(); | 104 var fd = new FormData(); |
| 78 fd.append("excitingData", "exciting value"); | 105 fd.append("excitingData", "exciting value"); |
| 79 fd.append("csrf", "[randomness]"); | 106 fd.append("csrf", "[randomness]"); |
| 80 credential.additionalData = fd; | 107 credential.additionalData = fd; |
| 81 | 108 |
| 82 return fetch("./resources/echo-post.php", { body: credential, method: "POST" }) | 109 return fetch("./resources/echo-post.php", { credentials: credential, method: "POST" }) |
| 83 .then(function (r) { | 110 .then(function (r) { |
| 84 return r.json(); | 111 return r.json(); |
| 85 }) | 112 }) |
| 86 .then(function (j) { | 113 .then(function (j) { |
| 87 assert_equals(j.username, 'id'); | 114 assert_equals(j.username, 'id'); |
| 88 assert_equals(j.password, 'pencil'); | 115 assert_equals(j.password, 'pencil'); |
| 89 assert_equals(j.excitingData, 'exciting value'); | 116 assert_equals(j.excitingData, 'exciting value'); |
| 90 assert_equals(j.csrf, '[randomness]'); | 117 assert_equals(j.csrf, '[randomness]'); |
| 91 }); | 118 }); |
| 92 }, "'additionalData': FormData properties are properly injected."); | 119 }, "'additionalData': FormData properties are properly injected."); |
| 93 | 120 |
| 94 promise_test(function() { | 121 promise_test(function() { |
| 95 var credential = new PasswordCredential({ | 122 var credential = new PasswordCredential({ |
| 96 id: 'id', | 123 id: 'id', |
| 97 password: 'pencil', | 124 password: 'pencil', |
| 98 name: 'name', | 125 name: 'name', |
| 99 iconURL: 'https://example.com/icon.png' | 126 iconURL: 'https://example.com/icon.png' |
| 100 }); | 127 }); |
| 101 | 128 |
| 102 var fd = new FormData(); | 129 var fd = new FormData(); |
| 103 fd.append("username", "foo"); | 130 fd.append("username", "foo"); |
| 104 fd.append("password", "bar"); | 131 fd.append("password", "bar"); |
| 105 credential.additionalData = fd; | 132 credential.additionalData = fd; |
| 106 | 133 |
| 107 // Use post-echo.cgi since PHP doesn't give us the raw data of a POST's | 134 // Use post-echo.cgi since PHP doesn't give us the raw data of a POST's |
| 108 // body if it's multipart/form-data. | 135 // body if it's multipart/form-data. |
| 109 return fetch("/xmlhttprequest/resources/post-echo.cgi", { body: credential, method: "POST" }) | 136 return fetch("/xmlhttprequest/resources/post-echo.cgi", { credentials: crede ntial, method: "POST" }) |
| 110 .then(function (r) { | 137 .then(function (r) { |
| 111 return r.text(); | 138 return r.text(); |
| 112 }) | 139 }) |
| 113 .then(function (t) { | 140 .then(function (t) { |
| 114 // Match "CRLF *OCTET CRLF". See RFC 2046 for the multipart | 141 // Match "CRLF *OCTET CRLF". See RFC 2046 for the multipart |
| 115 // grammar. | 142 // grammar. |
| 116 assert_false( | 143 assert_false( |
| 117 /\r\nfoo\r\n/.test(t), | 144 /\r\nfoo\r\n/.test(t), |
| 118 "POST data should not contain the overridden value foo."); | 145 "POST data should not contain the overridden value foo."); |
| 119 assert_false( | 146 assert_false( |
| 120 /\r\nbar\r\n/.test(t), | 147 /\r\nbar\r\n/.test(t), |
| 121 "POST data should not contain the overridden value bar."); | 148 "POST data should not contain the overridden value bar."); |
| 122 }); | 149 }); |
| 123 }, "'additionalData': FormData properties are properly overridden."); | 150 }, "'additionalData': FormData properties are properly overridden."); |
| 124 | 151 |
| 125 promise_test(function() { | 152 promise_test(function() { |
| 126 var credential = new PasswordCredential({ | 153 var credential = new PasswordCredential({ |
| 127 id: 'id', | 154 id: 'id', |
| 128 password: 'pencil', | 155 password: 'pencil', |
| 129 name: 'name', | 156 name: 'name', |
| 130 iconURL: 'https://example.com/icon.png' | 157 iconURL: 'https://example.com/icon.png' |
| 131 }); | 158 }); |
| 132 | 159 |
| 133 var params = new URLSearchParams(); | 160 var params = new URLSearchParams(); |
| 134 credential.additionalData = params; | 161 credential.additionalData = params; |
| 135 | 162 |
| 136 return fetch("./resources/echo-post.php", { body: credential, method: "POST" }) | 163 return fetch("./resources/echo-post.php", { credentials: credential, method: "POST" }) |
| 137 .then(function (r) { | 164 .then(function (r) { |
| 138 return r.json(); | 165 return r.json(); |
| 139 }) | 166 }) |
| 140 .then(function (j) { | 167 .then(function (j) { |
| 141 assert_equals(j.username, 'id'); | 168 assert_equals(j.username, 'id'); |
| 142 assert_equals(j.password, 'pencil'); | 169 assert_equals(j.password, 'pencil'); |
| 143 }); | 170 }); |
| 144 }, "'additionalData': Empty URLSearchParams has no effect."); | 171 }, "'additionalData': Empty URLSearchParams has no effect."); |
| 145 | 172 |
| 146 promise_test(function() { | 173 promise_test(function() { |
| 147 var credential = new PasswordCredential({ | 174 var credential = new PasswordCredential({ |
| 148 id: 'id', | 175 id: 'id', |
| 149 password: 'pencil', | 176 password: 'pencil', |
| 150 name: 'name', | 177 name: 'name', |
| 151 iconURL: 'https://example.com/icon.png' | 178 iconURL: 'https://example.com/icon.png' |
| 152 }); | 179 }); |
| 153 | 180 |
| 154 var params = new URLSearchParams(); | 181 var params = new URLSearchParams(); |
| 155 params.append("excitingData", "exciting value"); | 182 params.append("excitingData", "exciting value"); |
| 156 params.append("csrf", "[randomness]"); | 183 params.append("csrf", "[randomness]"); |
| 157 credential.additionalData = params; | 184 credential.additionalData = params; |
| 158 | 185 |
| 159 return fetch("./resources/echo-post.php", { body: credential, method: "POST" }) | 186 return fetch("./resources/echo-post.php", { credentials: credential, method: "POST" }) |
| 160 .then(function (r) { | 187 .then(function (r) { |
| 161 return r.json(); | 188 return r.json(); |
| 162 }) | 189 }) |
| 163 .then(function (j) { | 190 .then(function (j) { |
| 164 assert_equals(j.username, 'id'); | 191 assert_equals(j.username, 'id'); |
| 165 assert_equals(j.password, 'pencil'); | 192 assert_equals(j.password, 'pencil'); |
| 166 assert_equals(j.excitingData, 'exciting value'); | 193 assert_equals(j.excitingData, 'exciting value'); |
| 167 assert_equals(j.csrf, '[randomness]'); | 194 assert_equals(j.csrf, '[randomness]'); |
| 168 }); | 195 }); |
| 169 }, "'additionalData': URLSearchParams properties are properly injected."); | 196 }, "'additionalData': URLSearchParams properties are properly injected."); |
| 170 | 197 |
| 171 promise_test(function() { | 198 promise_test(function() { |
| 172 var credential = new PasswordCredential({ | 199 var credential = new PasswordCredential({ |
| 173 id: 'id', | 200 id: 'id', |
| 174 password: 'pencil', | 201 password: 'pencil', |
| 175 name: 'name', | 202 name: 'name', |
| 176 iconURL: 'https://example.com/icon.png' | 203 iconURL: 'https://example.com/icon.png' |
| 177 }); | 204 }); |
| 178 | 205 |
| 179 var params = new URLSearchParams(); | 206 var params = new URLSearchParams(); |
| 180 params.append("username", "foo"); | 207 params.append("username", "foo"); |
| 181 params.append("password", "bar"); | 208 params.append("password", "bar"); |
| 182 credential.additionalData = params; | 209 credential.additionalData = params; |
| 183 | 210 |
| 184 return fetch("./resources/echo-raw-post.php", { body: credential, method: "P OST" }) | 211 return fetch("./resources/echo-raw-post.php", { credentials: credential, met hod: "POST" }) |
| 185 .then(function (r) { | 212 .then(function (r) { |
| 186 return r.text(); | 213 return r.text(); |
| 187 }) | 214 }) |
| 188 .then(function (t) { | 215 .then(function (t) { |
| 189 assert_equals(t, 'username=id&password=pencil'); | 216 assert_equals(t, 'username=id&password=pencil'); |
| 190 }); | 217 }); |
| 191 }, "'additionalData': URLSearchParams properties are properly overridden."); | 218 }, "'additionalData': URLSearchParams properties are properly overridden."); |
| 192 | 219 |
| 193 promise_test(function() { | 220 promise_test(function() { |
| 194 var credential = new PasswordCredential({ | 221 var credential = new PasswordCredential({ |
| 195 id: 'id', | 222 id: 'id', |
| 196 password: 'pencil', | 223 password: 'pencil', |
| 197 name: 'name', | 224 name: 'name', |
| 198 iconURL: 'https://example.com/icon.png' | 225 iconURL: 'https://example.com/icon.png' |
| 199 }); | 226 }); |
| 200 | 227 |
| 201 var params = new URLSearchParams(); | 228 var params = new URLSearchParams(); |
| 202 params.append("a", "1"); | 229 params.append("a", "1"); |
| 203 params.append("a", "2"); | 230 params.append("a", "2"); |
| 204 params.append("a", "3"); | 231 params.append("a", "3"); |
| 205 credential.additionalData = params; | 232 credential.additionalData = params; |
| 206 | 233 |
| 207 return fetch("./resources/echo-raw-post.php", { body: credential, method: "P OST" }) | 234 return fetch("./resources/echo-raw-post.php", { credentials: credential, met hod: "POST" }) |
| 208 .then(function (r) { | 235 .then(function (r) { |
| 209 return r.text(); | 236 return r.text(); |
| 210 }) | 237 }) |
| 211 .then(function (t) { | 238 .then(function (t) { |
| 212 assert_equals(t, 'a=1&a=2&a=3&username=id&password=pencil'); | 239 assert_equals(t, 'a=1&a=2&a=3&username=id&password=pencil'); |
| 213 }); | 240 }); |
| 214 }, "'additionalData': URLSearchParams properties are properly injected (ordering matters)."); | 241 }, "'additionalData': URLSearchParams properties are properly injected (ordering matters)."); |
| 215 </script> | 242 </script> |
| OLD | NEW |