зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1684082 [wpt PR 27002] - Re-write wpt/cookies/http-state/ path tests, a=testonly
Automatic update from web-platform-tests Re-write wpt/cookies/http-state/ path tests This also adds support for sending multiple Set-Cookie strings to the test infrastructure. Notes for history books (and reviewers) legacy test => ported test cookie name map (ignoring Path) path0001 => (path.html) testA=11; testB=11 path0002 => (path.html) testB=12; testA=12 path0003 => (path.html) testA=13; testB=13 path0004 => (path.html) testB=14; testA=14 path0005 => (path.html) test=15 path0006 => (path.html) test=16 path0007 => (path-redirect.html) test=1 path0008 => (path-redirect.html) test=9 path0009 => (path-redirect.html) test=10 (can be improved) path0010 => (path-redirect.html) test=2 path0011 => (path-redirect.html) test=11 path0012 => (path-redirect.html) test=12 path0013 => (path-redirect.html) test=13 path0014 => (path-redirect.html) test=17 path0015 => not ported, see note below. path0016 => (path-redirect.html) test=3 path0017 => (path-redirect.html) test=4 path0018 => (path-redirect.html) test=14 (can be improved) path0019, dupe of (path.html) test1, not ported path0020, dupe of (path.html) test2, not ported path0021, dupe of (path.html) test3, not ported path0022 => (path.html) test=17 path0023 => (path.html) test=18 path0024 => (path-redirect.html) test=15 path0025 => (path-redirect.html) test=16 path0026 => (path-redirect.html) test=5 path0027 => (path-redirect.html) test=6 path0028 => (path-redirect.html) test=7a disabled-path0029 (path-redirect.html) test=7b path0029 => (path.html) test=19 path0030 => (path.html) test=21 path0031 => path.html test=20 path0032 => (path-redirect.html) test=8a; test=8b Notes: For path0027 and path0028, I'm swapping the assertions (to expected a cookie) because Firefox, Safari and Chrome do this. path0015 isn't possible to port with current WPT infra (as there are no dynamic handlers, and '/' is treated as a directory "mount"). https://bugs.chromium.org/p/chromium/issues/detail?id=1161544 is filed to track that work, and a few improvements to better capture the intents of path0009 and path0018. Bug: 1159925 Change-Id: I37da066e60d79e3f99e01a7d6ccbc408f447e01b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598139 Commit-Queue: Mike Taylor <miketaylr@chromium.org> Reviewed-by: Lily Chen <chlily@chromium.org> Cr-Commit-Position: refs/heads/master@{#839497} -- wpt-commits: 821a1ef63f08a7329175513b6c2eb00bb8b0152e wpt-pr: 27002
This commit is contained in:
Родитель
ff08454f06
Коммит
c500f4b4ac
|
@ -0,0 +1,126 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Test cookie path attribute parsing</title>
|
||||
<meta name=help href="https://tools.ietf.org/html/rfc6265#section-5.2.4">
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/cookies/resources/cookie-test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
const pathRedirectTests = [
|
||||
{
|
||||
cookie: "test=1; path=/cookies/attributes/resources/path.html",
|
||||
expected: "test=1",
|
||||
name: "Cookie sent for exact redirected path match",
|
||||
location: "/cookies/attributes/resources/path.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=2; path=/cookies/attributes/resources/path/one.html",
|
||||
expected: "test=2",
|
||||
name: "Cookie sent for exact redirected path match, one level deeper",
|
||||
location: "/cookies/attributes/resources/path/one.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=3; path=/cookies/attributes/resources/path/",
|
||||
expected: "test=3",
|
||||
name: "Cookie sent for redirected path with trailing '/' and the redirected URL is one level deeper",
|
||||
location: "/cookies/attributes/resources/path/one.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=4; path=/cookies/attributes/resources/path/",
|
||||
expected: "test=4",
|
||||
name: "Cookie sent for redirected path with trailing '/' and a double '/' in the redirected URL",
|
||||
location: "/cookies/attributes/resources/path//one.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=5; path=/cookies/attributes/resources/path/one.html;",
|
||||
expected: "test=5",
|
||||
name: "Cookie sent for redirected path match with a trailing ';' after an unquoted Path",
|
||||
location: "/cookies/attributes/resources/path/one.html",
|
||||
},
|
||||
{
|
||||
cookie: 'test=6; path="/cookies/attributes/resources/path/one.html;"',
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path match with a trailing ';' inside a quoted Path",
|
||||
location: "/cookies/attributes/resources/path/one.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=7a; path=/cookies/attributes/resources/p%61th/three.html",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path match with partially URL encoded path",
|
||||
location: "/cookies/attributes/resources/path/three.html",
|
||||
},
|
||||
{
|
||||
cookie: ["test=8a; path=/cookies/attributes/resources",
|
||||
"test=8b; path=/cookies/attributes/resources/"],
|
||||
expected: "test=8b; test=8a",
|
||||
name: "Multiple cookies sent for multiple redirected path matches, sorted by length",
|
||||
location: "/cookies/attributes/resources/path.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=9; path=/cookies/attributes/resources/path.html",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch where path and redirected URL begin with same string",
|
||||
location: "/cookies/attributes/resources/pathfakeout.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=10; path=/cookies/attributes/resources/path/one.html",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch where final path directory component and redirected URL resource begin with same string",
|
||||
location: "/cookies/attributes/resources/path.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=11; path=/cookies/attributes/resources/path/one.html",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch where final path directory component begins with same string as redirected URL final directory component",
|
||||
location: "/cookies/attributes/resources/pathfakeout/one.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=12; path=/cookies/attributes/resources/path/one.html",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch for different resources inside the same final directory component",
|
||||
location: "/cookies/attributes/resources/path/two.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=13; path=/cookies/attributes/resources/path/one.html/",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch where final path directory component ends in '/' and does not match redirected URL",
|
||||
location: "/cookies/attributes/resources/path/two.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=14; path=/cookies/attributes/resources/path/",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch with a similar start to the redirected URL",
|
||||
location: "/cookies/attributes/resources/pathfakeout.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=15; path=/cookies/attributes/resources/path/one.html?",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch with trailing '?' after unquoted Path",
|
||||
location: "/cookies/attributes/resources/path/one.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=16; path=/cookies/attributes/resources/path/one.html#",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch with trailing '#' after unquoted Path",
|
||||
location: "/cookies/attributes/resources/path/one.html",
|
||||
},
|
||||
{
|
||||
cookie: "test=17; path=/cookies/attributes/resources/path/one.html/",
|
||||
expected: "",
|
||||
name: "No cookie sent for redirected path mismatch with trailing '/' after unquoted Path",
|
||||
location: "/cookies/attributes/resources/path/one.html",
|
||||
},
|
||||
];
|
||||
|
||||
for (const test of pathRedirectTests) {
|
||||
httpRedirectCookieTest(test.cookie, test.expected, test.name,
|
||||
test.location);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -26,48 +26,111 @@
|
|||
cookie: "test=3; Path=/",
|
||||
expected: "test=3",
|
||||
name: "Set cookie for Path=/",
|
||||
defaultPath: false
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: "test=4; Path=/qux",
|
||||
expected: "",
|
||||
name: "No cookie returned for mismatched path",
|
||||
defaultPath: false
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: "test=5; Path =/qux",
|
||||
expected: "",
|
||||
name: "No cookie returned for path space equals mismatched path",
|
||||
defaultPath: false
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: "test=6; Path= /qux",
|
||||
expected: "",
|
||||
name: "No cookie returned for path equals space mismatched path",
|
||||
defaultPath: false
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: "test=7; Path=/qux ; taz",
|
||||
expected: "",
|
||||
name: "No cookie returned for mismatched path and attribute",
|
||||
defaultPath: false
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: "test=8; Path=/qux; Path=/",
|
||||
expected: "test=8",
|
||||
name: "Set cookie for mismatched and root path"
|
||||
name: "Set cookie for mismatched and root path",
|
||||
},
|
||||
{
|
||||
cookie: "test=9; Path=/; Path=/qux",
|
||||
expected: "",
|
||||
name: "No cookie returned for root and mismatched path",
|
||||
defaultPath: false
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: "test=10; Path=/lol; Path=/qux",
|
||||
expected: "",
|
||||
name: "No cookie returned for multiple mismatched paths",
|
||||
defaultPath: false
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["testA=11; path=/", "testB=11; path=/cookies/attributes"],
|
||||
expected: "testB=11; testA=11",
|
||||
name: "Return 2 cookies sorted by matching path length (earlier name with shorter path set first)",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["testB=12; path=/", "testA=12; path=/cookies/attributes"],
|
||||
expected: "testA=12; testB=12",
|
||||
name: "Return 2 cookies sorted by matching path length (later name with shorter path set first)",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["testA=13; path=/cookies/attributes", "testB=13; path=/"],
|
||||
expected: "testA=13; testB=13",
|
||||
name: "Return 2 cookies sorted by matching path length (earlier name with longer path set first)",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["testB=14; path=/cookies/attributes", "testA=14; path=/"],
|
||||
expected: "testB=14; testA=14",
|
||||
name: "Return 2 cookies sorted by matching path length (later name with longer path set first)",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["test=15; path=/cookies/attributes/foo"],
|
||||
expected: "",
|
||||
name: "No cookie returned for partial path match",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["test=16", "test=0; path=/cookies/attributes/foo"],
|
||||
expected: "test=16",
|
||||
name: "No cookie returned for partial path match, return cookie for default path",
|
||||
},
|
||||
{
|
||||
cookie: ["test=17; path= /"],
|
||||
expected: "test=17",
|
||||
name: "Return cookie for path= / (whitespace after equals)",
|
||||
},
|
||||
{
|
||||
cookie: ["test=18; path=/cookies/ATTRIBUTES"],
|
||||
expected: "",
|
||||
name: "No cookie returned for case mismatched path",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["testA=19; path = /cookies/attributes", "testB=19; path = /book"],
|
||||
expected: "testA=19",
|
||||
name: "Return cookie A on path match, no cookie returned for path mismatch (plus whitespace)",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["test=20; path=; path=/dog"],
|
||||
expected: "",
|
||||
name: "No cookie returned for mismatched path (after bare path=)",
|
||||
defaultPath: false,
|
||||
},
|
||||
{
|
||||
cookie: ["test=21; path=/dog; path="],
|
||||
expected: "test=21",
|
||||
name: "Return cookie for bare path= (after mismatched path)",
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
window.expireCookie = (cookie) => {
|
||||
const cookies = Array.isArray(cookie) ? cookie : [cookie];
|
||||
for (let c of cookies) {
|
||||
document.cookie = c += "; max-age=0";
|
||||
}
|
||||
}
|
||||
window.getCookies = () => document.cookie;
|
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>helper iframe for matching cookie path redirect tests</title>
|
||||
<meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>helper iframe for matching cookie path redirect tests</title>
|
||||
<meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>helper iframe for matching cookie path redirect tests</title>
|
||||
<meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>helper iframe for matching cookie path redirect tests</title>
|
||||
<meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>helper iframe for matching cookie path redirect tests</title>
|
||||
<meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,11 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>helper iframe for matching cookie path redirect tests</title>
|
||||
<meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,63 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Tests basic cookie setting functionality</title>
|
||||
<meta name=help href="https://tools.ietf.org/html/rfc6265#page-8">
|
||||
<meta name="timeout" content="long">
|
||||
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/cookie-http-state-template.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<div id="iframes"></div>
|
||||
<script>
|
||||
setup({ explicit_timeout: true });
|
||||
|
||||
const TEST_CASES = [
|
||||
{file: "path0001", name: "path0001"},
|
||||
{file: "path0002", name: "path0002"},
|
||||
{file: "path0003", name: "path0003"},
|
||||
{file: "path0004", name: "path0004"},
|
||||
{file: "path0005", name: "path0005"},
|
||||
{file: "path0006", name: "path0006"},
|
||||
{file: "path0007", name: "path0007"},
|
||||
{file: "path0008", name: "path0008"},
|
||||
{file: "path0009", name: "path0009"},
|
||||
{file: "path0010", name: "path0010"},
|
||||
{file: "path0011", name: "path0011"},
|
||||
{file: "path0012", name: "path0012"},
|
||||
{file: "path0013", name: "path0013"},
|
||||
{file: "path0014", name: "path0014"},
|
||||
{file: "path0015", name: "path0015"},
|
||||
{file: "path0016", name: "path0016"},
|
||||
{file: "path0017", name: "path0017"},
|
||||
{file: "path0018", name: "path0018"},
|
||||
{file: "path0019", name: "path0019"},
|
||||
{file: "path0020", name: "path0020"},
|
||||
{file: "path0021", name: "path0021"},
|
||||
{file: "path0022", name: "path0022"},
|
||||
{file: "path0023", name: "path0023"},
|
||||
{file: "path0024", name: "path0024"},
|
||||
{file: "path0025", name: "path0025"},
|
||||
{file: "path0026", name: "path0026"},
|
||||
{file: "path0027", name: "path0027"},
|
||||
{file: "path0028", name: "path0028"},
|
||||
{file: "disabled-path0029", name: "disabled-path0029"},
|
||||
{file: "path0029", name: "path0029"},
|
||||
{file: "path0030", name: "path0030"},
|
||||
{file: "path0031", name: "path0031"},
|
||||
{file: "path0032", name: "path0032"},
|
||||
];
|
||||
|
||||
for (const i in TEST_CASES) {
|
||||
const t = TEST_CASES[i];
|
||||
promise_test(createCookieTest(t.file),
|
||||
t.file + " - " + t.name);
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/bar
|
||||
Location: /cookie-parser-result/f%6Fo/bar?disabled-path0029
|
|
@ -1 +0,0 @@
|
|||
Cookie: x=y; a=b
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: a=b; path=/
|
||||
Set-Cookie: x=y; path=/cookie-parser-result
|
|
@ -1 +0,0 @@
|
|||
Cookie: a=b; x=y
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: a=b; path=/cookie-parser-result
|
||||
Set-Cookie: x=y; path=/
|
|
@ -1 +0,0 @@
|
|||
Cookie: a=b; x=y
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: x=y; path=/
|
||||
Set-Cookie: a=b; path=/cookie-parser-result
|
|
@ -1 +0,0 @@
|
|||
Cookie: x=y; a=b
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: x=y; path=/cookie-parser-result
|
||||
Set-Cookie: a=b; path=/
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar
|
||||
Set-Cookie: foo=qux; path=/cookie-parser-result/foo
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo
|
||||
Location: /cookie-parser-result/foo?path0007
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo
|
||||
Location: /cookie-parser-result/bar?path0008
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux
|
||||
Location: /cookie-parser-result/foo?path0009
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux
|
||||
Location: /cookie-parser-result/foo/qux?path0010
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux
|
||||
Location: /cookie-parser-result/bar/qux?path0011
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux
|
||||
Location: /cookie-parser-result/foo/baz?path0012
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux/
|
||||
Location: /cookie-parser-result/foo/baz?path0013
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux/
|
||||
Location: /cookie-parser-result/foo/qux?path0014
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux/
|
||||
Location: /cookie-parser-result/foo/qux/?path0015
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/
|
||||
Location: /cookie-parser-result/foo/qux?path0016
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/
|
||||
Location: /cookie-parser-result/foo//qux?path0017
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/
|
||||
Location: /cookie-parser-result/fooqux?path0018
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; path
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; path= /
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; Path=/cookie-PARSER-result
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux?
|
||||
Location: /cookie-parser-result/foo/qux?path0024
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux#
|
||||
Location: /cookie-parser-result/foo/qux?path0025
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/foo/qux;
|
||||
Location: /cookie-parser-result/foo/qux?path0026
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path="/cookie-parser-result/foo/qux;"
|
||||
Location: /cookie-parser-result/foo/qux?path0027
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result/f%6Fo/bar
|
||||
Location: /cookie-parser-result/foo/bar?path0028
|
|
@ -1 +0,0 @@
|
|||
Cookie: a=b
|
|
@ -1,2 +0,0 @@
|
|||
Set-Cookie: a=b; path = /cookie-parser-result
|
||||
Set-Cookie: x=y; path = /book
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=bar
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/dog; path=
|
|
@ -1 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=; path=/dog
|
|
@ -1 +0,0 @@
|
|||
Cookie: foo=qux; foo=bar
|
|
@ -1,3 +0,0 @@
|
|||
Set-Cookie: foo=bar; path=/cookie-parser-result
|
||||
Set-Cookie: foo=qux; path=/cookie-parser-result/
|
||||
Location: /cookie-parser-result/dog?path0032
|
|
@ -22,11 +22,38 @@ async function getDefaultPathCookies(path = '/cookies/resources') {
|
|||
});
|
||||
}
|
||||
|
||||
// getRedirectedCookies is a helper method to get and delete cookies that
|
||||
// were set from a Location header redirect.
|
||||
async function getRedirectedCookies(location, cookie) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.style = 'display: none';
|
||||
iframe.src = `${location}`;
|
||||
|
||||
iframe.addEventListener('load', (e) => {
|
||||
const win = e.target.contentWindow;
|
||||
const iframeCookies = win.getCookies();
|
||||
win.expireCookie(cookie);
|
||||
resolve(iframeCookies);
|
||||
}, {once: true});
|
||||
|
||||
document.documentElement.appendChild(iframe);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// httpCookieTest sets a |cookie| (via HTTP), then asserts it was or was not set
|
||||
// via |expectedValue| (via the DOM). Then cleans it up (via HTTP). Most tests
|
||||
// do not set a Path attribute, so |defaultPath| defaults to true.
|
||||
//
|
||||
// |cookie| may be a single cookie string, or an array of cookie strings, where
|
||||
// the order of the array items represents the order of the Set-Cookie headers
|
||||
// sent by the server.
|
||||
function httpCookieTest(cookie, expectedValue, name, defaultPath = true) {
|
||||
let encodedCookie = encodeURIComponent(cookie);
|
||||
let encodedCookie = encodeURIComponent(JSON.stringify(cookie));
|
||||
return promise_test(
|
||||
async t => {
|
||||
return fetch(`/cookies/resources/cookie.py?set=${encodedCookie}`)
|
||||
|
@ -53,3 +80,30 @@ function httpCookieTest(cookie, expectedValue, name, defaultPath = true) {
|
|||
})},
|
||||
name);
|
||||
}
|
||||
|
||||
// This is a variation on httpCookieTest, where a redirect happens via
|
||||
// the Location header and we check to see if cookies are sent via
|
||||
// getRedirectedCookies
|
||||
function httpRedirectCookieTest(cookie, expectedValue, name, location) {
|
||||
const encodedCookie = encodeURIComponent(JSON.stringify(cookie));
|
||||
const encodedLocation = encodeURIComponent(location);
|
||||
const setParams = `?set=${encodedCookie}&location=${encodedLocation}`;
|
||||
return promise_test(
|
||||
async t => {
|
||||
return fetch(`/cookies/resources/cookie.py${setParams}`)
|
||||
.then(async () => {
|
||||
// for the tests where a redirect happens, we need to head
|
||||
// to that URI to get the cookies (and then delete them there)
|
||||
const cookies = await getRedirectedCookies(location, cookie);
|
||||
if (Boolean(expectedValue)) {
|
||||
assert_equals(cookies, expectedValue,
|
||||
'The cookie was set as expected.');
|
||||
} else {
|
||||
assert_equals(cookies, expectedValue, 'The cookie was rejected.');
|
||||
}
|
||||
}).then(() => {
|
||||
return fetch(`/cookies/resources/cookie.py?drop=${encodedCookie}`);
|
||||
})
|
||||
},
|
||||
name);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
import json
|
||||
|
||||
from cookies.resources.helpers import setNoCacheAndCORSHeaders
|
||||
from wptserve.utils import isomorphic_decode
|
||||
from wptserve.utils import isomorphic_encode
|
||||
|
||||
def set_cookie(headers, cookie_string, drop=False):
|
||||
"""Helper method to add a Set-Cookie header"""
|
||||
if drop:
|
||||
cookie_string = cookie_string.encode('utf-8') + b'; max-age=0'
|
||||
headers.append((b'Set-Cookie', isomorphic_encode(cookie_string)))
|
||||
|
||||
def main(request, response):
|
||||
"""Set or drop a cookie via GET params.
|
||||
|
||||
Usage: `/cookie.py?set={cookie}` or `/cookie.py?drop={cookie}`
|
||||
|
||||
The passed-in cookie string should be encoded via encodeURIComponent,
|
||||
otherwise `parse_qsl` will split on any semicolons (used by the Request.GET
|
||||
property getter).
|
||||
The passed-in cookie string should be stringified via JSON.stringify() (in
|
||||
the case of multiple cookie headers sent in an array) and encoded via
|
||||
encodeURIComponent, otherwise `parse_qsl` will split on any semicolons
|
||||
(used by the Request.GET property getter). Note that values returned by
|
||||
Request.GET will decode any percent-encoded sequences sent in a GET param
|
||||
(which may or may not be surprising depending on what you're doing).
|
||||
|
||||
Note: here we don't use Response.delete_cookie() or similar other methods
|
||||
in this resources directory because there are edge cases that are impossible
|
||||
|
@ -21,13 +33,22 @@ def main(request, response):
|
|||
try:
|
||||
if b'drop' in request.GET:
|
||||
cookie = request.GET[b'drop']
|
||||
cookie += b'; max-age=0'
|
||||
cookie = json.loads(cookie)
|
||||
cookies = cookie if isinstance(cookie, list) else [cookie]
|
||||
for c in cookies:
|
||||
set_cookie(headers, c, drop=True)
|
||||
|
||||
if b'set' in request.GET:
|
||||
cookie = request.GET[b'set']
|
||||
cookie = isomorphic_decode(request.GET[b'set'])
|
||||
cookie = json.loads(cookie)
|
||||
cookies = cookie if isinstance(cookie, list) else [cookie]
|
||||
for c in cookies:
|
||||
set_cookie(headers, c)
|
||||
|
||||
if b'location' in request.GET:
|
||||
headers.append((b'Location', request.GET[b'location']))
|
||||
return 302, headers, b'{"redirect": true}'
|
||||
|
||||
headers.append((b'Set-Cookie', isomorphic_encode(cookie)))
|
||||
return headers, b'{"success": true}'
|
||||
except Exception as e:
|
||||
return 500, headers, bytes({'error': '{}'.format(e)})
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче