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