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