domain-child.sub.html (18924B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset=utf-8> 5 <title>Test cookie domain attribute parsing</title> 6 <meta name=help href="https://tools.ietf.org/html/rfc6265#section-5.2.3"> 7 <meta name="timeout" content="long"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 <script src="/cookies/resources/cookie-test.js"></script> 12 </head> 13 <body> 14 <script> 15 const path = "path=/cookies/attributes" 16 const port = "{{ports[http][0]}}"; 17 const host = "{{host}}"; // example.org 18 const wwwHost = "{{domains[www]}}"; // home.example.org 19 const www1Host = "{{domains[www1]}}"; // sibling.example.org 20 const www2wwwHost = "{{domains[www2.www]}}"; // subdomain.home.example.org 21 22 // naive helper method to return the TLD for a given domain 23 const getTLD = domain => { 24 let match = /\.[a-z]+$/.exec(domain); 25 if (match) { 26 return match[0]; 27 } else { 28 throw 'Domain is malformed!'; 29 } 30 } 31 32 // helper to take a domain like "www.example.org" 33 // and return a string like "www.eXaMpLe.org" 34 const makeBizarre = domain => { 35 let bizarre = ""; 36 let domainArray = domain.split("."); 37 let secondLevel = domainArray[domainArray.length - 2]; 38 for (let i in secondLevel) { 39 if (i % 2 == 1) { 40 bizarre += secondLevel[i].toUpperCase(); 41 } else { 42 bizarre += secondLevel[i]; 43 } 44 } 45 domainArray[domainArray.length - 2] = bizarre; 46 return domainArray.join("."); 47 } 48 49 // helper to change the current TLD to a TLD that doesn't exist, and is 50 // unlikely to exist in the future. (the main point is that the TLD 51 // *changes*, so there is no domain match, but we cant' predict how WPT 52 // servers may be set up in the wild so picking any valid TLD has the risk 53 // of future (unintentional) domain matching. 54 const changeTLD = domain => { 55 let domainArray = domain.split("."); 56 domainArray[domainArray.length - 1] += "zzz"; 57 return domainArray.join("."); 58 } 59 60 const domainTests = [ 61 { 62 cookie: `test=1; domain=${wwwHost}`, 63 expected: "test=1", 64 name: "Return cookie for a domain match", 65 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 66 }, 67 { 68 cookie: `test=2; domain=${wwwHost}`, 69 expected: "", 70 name: "No cookie returned for domain mismatch (subdomains differ post-redirect)", 71 location: `http://${www1Host}:${port}/cookies/attributes/resources/path.html`, 72 }, 73 { 74 cookie: `test=3; domain=.${wwwHost}`, 75 expected: "test=3", 76 name: "Return cookie for a domain match with leading '.'", 77 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 78 }, 79 { 80 cookie: `test=4; domain=${wwwHost}`, 81 expected: "test=4", 82 name: "Return cookie for domain match (domain attribute is suffix of the host name and first level subdomain)", 83 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 84 }, 85 { 86 cookie: `test=5; domain=.${wwwHost}`, 87 expected: "test=5", 88 name: "Return cookie for domain match (domain attribute is suffix of the host name and first level subdomain, with leading '.')", 89 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 90 }, 91 { 92 cookie: `test=6; domain=.${wwwHost}`, 93 expected: "", 94 name: "No cookie returned for domain mismatch (subdomains differ, with leading '.')", 95 location: `http://${www1Host}:${port}/cookies/attributes/resources/path.html`, 96 }, 97 { 98 cookie: `test=7; domain=${www1Host}`, 99 expected: "", 100 name: "No cookie returned for domain mismatch when cookie was created (which would match after the redirect, with one subdomain level)", 101 location: `http://${www1Host}:${port}/cookies/attributes/resources/path.html`, 102 }, 103 { 104 cookie: `test=8; domain=.${host}`, 105 expected: "test=8", 106 name: "Return cookie for domain match (domain attribute is suffix of the host name, with leading '.')", 107 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 108 }, 109 { 110 cookie: `test=9; domain=${host}`, 111 expected: "test=9", 112 name: "Return cookie for domain match (domain attribute is suffix of the host name)", 113 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 114 }, 115 { 116 cookie: `test=10; domain=..${wwwHost}`, 117 expected: "", 118 name: "No cookie returned for domain attribute with double leading '.'", 119 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 120 }, 121 { 122 cookie: `test=11; domain=www..${host}`, 123 expected: "", 124 name: "No cookie returned for domain attribute with subdomain followed by ..", 125 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 126 }, 127 { 128 cookie: `test=12; domain= .${wwwHost}`, 129 expected: "test=12", 130 name: "Return cookie for a domain match with leading whitespace and '.'", 131 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 132 }, 133 { 134 cookie: `test=13; domain= . ${wwwHost}`, 135 expected: "", 136 name: "No cookie returned for domain attribute with whitespace that surrounds a leading '.'", 137 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 138 }, 139 { 140 cookie: `test=14; domain=${wwwHost}.`, 141 expected: "", 142 name: "No cookie returned for domain attribute with trailing '.'", 143 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 144 }, 145 { 146 cookie: `test=15; domain=${wwwHost}..`, 147 expected: "", 148 name: "No cookie returned for domain attribute with trailing '..'", 149 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 150 }, 151 { 152 cookie: `test=16; domain=${wwwHost} .`, 153 expected: "", 154 name: "No cookie returned for domain attribute with trailing whitespace and '.'", 155 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 156 }, 157 { 158 cookie: `test=17; domain=${getTLD(host)}`, 159 expected: "", 160 name: "No cookie returned for domain attribute with TLD as value", 161 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 162 }, 163 { 164 cookie: `test=18; domain=.${getTLD(host)}`, 165 expected: "", 166 name: "No cookie returned for domain attribute with TLD as value, with leading '.'", 167 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 168 }, 169 { 170 cookie: `test=18b; domain=.${getTLD(host)}.`, 171 expected: "", 172 name: "No cookie returned for domain attribute with TLD as value, with leading and trailing '.'", 173 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 174 }, 175 { 176 cookie: [`testA=19; domain=${wwwHost}`, `testB=19; domain=.${wwwHost}`], 177 expected: "testA=19; testB=19", 178 name: "Return multiple cookies that match on domain (without and with leading '.')", 179 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 180 }, 181 { 182 cookie: [`testB=20; domain=.${wwwHost}`, `testA=20; domain=${wwwHost}`], 183 expected: "testB=20; testA=20", 184 name: "Return multiple cookies that match on domain (with and without leading '.')", 185 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 186 }, 187 { 188 cookie: `test=21; domain="${wwwHost}"`, 189 expected: "", 190 name: "No cookie returned for domain attribute value between quotes", 191 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 192 }, 193 { 194 cookie: [`testA=22; domain=${wwwHost}`, `testB=22; domain=.${host}`], 195 expected: "testA=22; testB=22", 196 name: "Return multiple cookies that match on subdomain and domain (without and with leading '.')", 197 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 198 }, 199 { 200 cookie: [`testB=23; domain=.${host}`, `testA=23; domain=${wwwHost}`], 201 expected: "testB=23; testA=23", 202 name: "Return multiple cookies that match on domain and subdomain (with and without leading '.')", 203 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 204 }, 205 { 206 cookie: `test=24; domain=.${host}; domain=${wwwHost}`, 207 expected: "", 208 name: "No cookie returned when domain attribute does not domain-match (and first does)", 209 location: `http://${www1Host}:${port}/cookies/attributes/resources/path.html`, 210 }, 211 { 212 cookie: `test=25; domain=${wwwHost}; domain=.${host}`, 213 expected: "test=25", 214 name: "Return cookie for domain attribute match (first does not, but second does)", 215 location: `http://${www1Host}:${port}/cookies/attributes/resources/path.html`, 216 }, 217 { 218 cookie: `test=26; domain=${makeBizarre(wwwHost)}`, 219 expected: "test=26", 220 name: "Return cookie for domain match (with bizarre capitalization for domain attribute value)", 221 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 222 }, 223 { 224 cookie: `test=27; domain="${wwwHost}:${port}"`, 225 expected: "", 226 name: "No cookie returned for domain attribute value with port", 227 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 228 }, 229 { 230 cookie: `test=28; domain=${www2wwwHost}`, 231 expected: "", 232 name: "No cookie returned for domain mismatch when cookie was created (which would match after the redirect, with two subdomain levels)", 233 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 234 }, 235 { 236 cookie: `test=29`, 237 expected: "", 238 name: "No cookie returned for cookie set on different domain (with no domain attribute)", 239 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 240 }, 241 { 242 cookie: "test=30; domain=", 243 expected: "test=30", 244 name: "Return cookie set with bare domain= attribute", 245 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 246 }, 247 { 248 cookie: `test=31; domain=${wwwHost}`, 249 expected: "test=31", 250 name: "Return cookie that domain-matches with bizarre-cased URL", 251 location: `http://${makeBizarre(wwwHost)}:${port}/cookies/attributes/resources/path.html`, 252 }, 253 { 254 cookie: `test=32; domain=${wwwHost}; domain=${changeTLD(wwwHost)}`, 255 expected: "", 256 name: "No cookie returned for domain attribute mismatch (first attribute matches, but second does not)", 257 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 258 }, 259 { 260 cookie: `test=33; domain=${changeTLD(wwwHost)}; domain=${wwwHost}`, 261 expected: "test=33", 262 name: "Return cookie for domain match (first attribute doesn't, but second does)", 263 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 264 }, 265 { 266 cookie: `test=34; domain=${wwwHost}; domain=${changeTLD(wwwHost)}; domain=${wwwHost}`, 267 expected: "test=34", 268 name: "Return cookie for domain match (first attribute matches, second doesn't, third does)", 269 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 270 }, 271 { 272 cookie: `test=35; domain=${changeTLD(wwwHost)}; domain=${wwwHost}; domain=${changeTLD(wwwHost)}`, 273 expected: "", 274 name: "No cookie returned for domain attribute mismatch (first attribute doesn't, second does, third doesn't)", 275 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 276 }, 277 { 278 cookie: `test=36; domain=${wwwHost}; domain=${wwwHost}`, 279 expected: "test=36", 280 name: "Return cookie for domain match (with two identical domain attributes)", 281 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 282 }, 283 { 284 cookie: `test=37; domain=${wwwHost}; domain=${host}`, 285 expected: "test=37", 286 name: "Return cookie for domain match (with first domain attribute a match for host name and second as suffix of host name)", 287 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 288 }, 289 { 290 cookie: `test=38; domain=${host}; domain=${wwwHost}`, 291 expected: "test=38", 292 name: "Return cookie for domain match (with first domain attribute as suffix of host name and second a match for host name)", 293 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 294 }, 295 { 296 cookie: `test=39; domain=.${www1Host}`, 297 expected: "", 298 name: "No cookie set on domain mismatch before a (domain matching) redirect", 299 location: `http://${www1Host}:${port}/cookies/attributes/resources/path.html`, 300 }, 301 { 302 cookie: `test=40; domain=.${www2wwwHost}`, 303 expected: "", 304 name: "No cookie set on domain mismatch before a (domain matching) redirect (for second level subdomain)", 305 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 306 }, 307 { 308 cookie: `test=41; domain=${host}; domain=`, 309 expected: "test=41", 310 name: "Return cookie for domain match (with first domain attribute as suffix of host name and second a bare attribute)", 311 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 312 }, 313 { 314 cookie: `test=42; domain=${www1Host}; domain=`, 315 expected: "test=42", 316 name: "Cookie returned for bare domain attribute following mismatched domain attribute (after redirect to same-origin page).", 317 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 318 }, 319 { 320 cookie: `test=43; domain=${www1Host}; domain=`, 321 expected: "", 322 name: "No cookie returned for domain mismatch (first attribute is a different subdomain and second is bare)", 323 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 324 }, 325 { 326 cookie: [`test=not44; domain=${wwwHost}`, `test=44; domain=.${wwwHost}`], 327 expected: "test=44", 328 name: "Cookies with same name, path, and domain (differing only in leading '.') overwrite each other ('.' second)", 329 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 330 }, 331 { 332 cookie: [`test=not45; domain=.${wwwHost}`, `test=45; domain=${wwwHost}`], 333 expected: "test=45", 334 name: "Cookies with same name, path, and domain (differing only in leading '.') overwrite each other ('.' first)", 335 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 336 }, 337 { 338 cookie: `test=46; domain=.`, 339 expected: "", 340 name: "No cookie returned for domain with single dot ('.') value.", 341 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 342 }, 343 { 344 cookie: `test=46b; domain=.; domain=${host}`, 345 expected: "test=46b", 346 name: "Return cookie with valid domain after domain with single dot ('.') value.", 347 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 348 }, 349 { 350 cookie: ["test=47", `test=47b; domain=${host}`,`test=47b; domain=${www1Host}; domain=`], 351 expected: "test=47b; test=47b", 352 name: "Empty domain treated as host cookie 1", 353 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 354 }, 355 { 356 cookie: ["test=48", `test=48b; domain=${host}`,`test=48b; domain=${host}; domain=`], 357 expected: "test=48b; test=48b", 358 name: "Empty domain treated as host cookie 2", 359 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 360 }, 361 { 362 cookie: ["test=49", `test=49b; domain=${host}`,`test=49b; domain=`], 363 expected: "test=49b; test=49b", 364 name: "Empty domain treated as host cookie 3", 365 location: `http://${wwwHost}:${port}/cookies/attributes/resources/path.html`, 366 }, 367 { 368 cookie: ["test=50", `test=50b; domain=${host}`,`test=50b; domain=${www1Host}; domain=`], 369 expected: "test=50b", 370 name: "No host cookies returned for host cookies after non-host redirect 1", 371 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 372 }, 373 { 374 cookie: ["test=51", `test=51b; domain=${host}`,`test=51b; domain=${host}; domain=`], 375 expected: "test=51b", 376 name: "No host cookies returned for host cookies after non-host redirect 2", 377 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 378 }, 379 { 380 cookie: ["test=52", `test=52b; domain=${host}`,`test=52b; domain=`], 381 expected: "test=52b", 382 name: "No host cookies returned for host cookies after non-host redirect 3", 383 location: `http://${www2wwwHost}:${port}/cookies/attributes/resources/path.html`, 384 }, 385 ]; 386 387 for (const test of domainTests) { 388 if (Array.isArray(test.cookie)) { 389 for (let i in test.cookie) { 390 test.cookie[i] += `; ${path}`; 391 } 392 } else { 393 test.cookie += `; ${path}`; 394 } 395 396 httpRedirectCookieTest(test.cookie, test.expected, test.name, 397 test.location); 398 } 399 </script> 400 </body> 401 </html>