Update web-platform-tests to revision 83b0a62af874eaf20e9d97d2fb9e15e91f3d109f

This commit is contained in:
WPT Sync Bot 2018-03-09 20:11:29 -05:00
parent 95f9e14e67
commit 3f33c72bb4
193 changed files with 1605 additions and 458 deletions

View file

@ -0,0 +1,59 @@
<!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">
<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>
<script>
setup({ explicit_timeout: true });
const TEST_CASES = [
{file: "0001", name: "Set cookie."},
{file: "0002", name: "Set cookie with future expiration."},
{file: "0003", name: "Set expired cookie along with valid cookie."},
{file: "0004", name: "Ignore cookie without key."},
{file: "0005", name: "Set cookie with age."},
{file: "0006", name: "Set no cookie with max-age=0."},
{file: "0007", name: "Set cookie with version=1."},
{file: "0008", name: "Set cookie with version=1000."},
{file: "0009", name: "Set cookie with custom value."},
// TODO(fhorschig): Could 0010 break when run on a HTTPS try server?
{file: "0010", name: "Dont accept 'secure' cookies over http."},
{file: "0011", name: "Ignore separators in cookie values."},
{file: "0012", name: "Ignore values with separators and without ';'."},
{file: "0013", name: "Use last value for cookies with identical keys."},
{file: "0014", name: "Keep alphabetic key order."},
{file: "0015", name: "Keep alphabetic single-char key order."},
{file: "0016", name: "Keep non-alphabetic key order."},
{file: "0017", name: "Keep order if comma-separated."},
{file: "0018", name: "Ignore keys after semicolon."},
{file: "0019", name: "Ignore attributes after semicolon."},
{file: "0020", name: "Ignore cookies without key and value."},
{file: "0021", name: "Ignore cookie without key in all 'Set-Cookie'."},
{file: "0022", name: "Set cookie without value in all 'Set-Cookie'."},
{file: "0023", name: "Ignore cookies without '=' in all 'Set-Cookie'."},
{file: "0024", name: "Ignore malformed cookies in all 'Set-Cookie'."},
{file: "0025", name: "Ignore cookies with ';' in all 'Set-Cookie'."},
{file: "0026", name: "Ignore malformed cookies in all 'Set-Cookie' v2."},
{file: "0027", name: "Ignore malformed cookies in all 'Set-Cookie' v3."},
// TODO(fhorschig): Ask about 0028's expectations ... should be empty?
{file: "0028", name: "[INVALID EXPECTATION] Ignore malformed cookies in all 'Set-Cookie' v4."},
];
for (const i in TEST_CASES) {
const t = TEST_CASES[i];
promise_test(createCookieTest(t.file),
t.file + " - " + t.name,
{ timeout: 3000 });
}
</script>
</body>
</html>

View file

@ -0,0 +1,80 @@
const SERVER_LOCATION = "resources";
const SERVER_SCRIPT = SERVER_LOCATION + "/cookie-setter.py";
function stripPrefixAndWhitespace(cookie_text) {
return cookie_text.replace(/^Cookie: /, '').replace(/^\s+|\s+$/g, '');
}
function getLocalResourcesPath() {
return location.pathname.replace(/[^\/]*$/, "") + SERVER_LOCATION;
}
function getAbsoluteServerLocation() {
return getLocalResourcesPath().replace(/resources.*$/,'')+ SERVER_SCRIPT;
}
function expireCookie(name, expiry_date, path) {
name = name || "";
expiry_date = expiry_date || "Thu, 01 Jan 1970 00:00:00 UTC";
path = path || getLocalResourcesPath();
document.cookie = name + "=; expires=" + expiry_date + "; path=" + path + ";";
}
function CookieManager() {
this.initial_cookies = [];
}
CookieManager.prototype.parse = document_cookies => {
this.initial_cookies = [];
document_cookies = document_cookies.replace(/^Cookie: /, '');
if (document_cookies != "") {
this.initial_cookies = document_cookies.split(/\s*;\s*/);
}
}
CookieManager.prototype.diffWith = document_cookies => {
this.actual_cookies = document_cookies;
for (let i in initial_cookies) {
let no_spaces_cookie_regex =
new RegExp(/\s*[\;]*\s/.source + initial_cookies[i]);
this.actual_cookies = actual_cookies.replace(no_spaces_cookie_regex, '');
}
return this.actual_cookies;
}
CookieManager.prototype.resetCookies = () => {
expireCookie(/*name=*/""); // If a cookie without keys was accepted, drop it.
if (this.actual_cookies == "") {
return; // There is nothing to reset here.
}
let cookies_to_delete = this.actual_cookies.split(/\s*;\s*/)
for (let i in cookies_to_delete){
expireCookie(cookies_to_delete[i].replace(/=.*$/, ""));
// Drop cookies with same name that were set to the root path which happens
// for example due to "0010" still failing.
expireCookie(cookies_to_delete[i].replace(/=.*$/, ""),
/*expiry_date=*/null,
/*path=*/'/');
}
}
function createCookieTest(file) {
return t => {
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
let diff_tool = new CookieManager();
t.add_cleanup(diff_tool.resetCookies);
return new Promise((resolve, reject) => {
diff_tool.parse(document.cookie);
window.addEventListener("message", t.step_func(e => {
assert_true(!!e.data, "Message contains data")
resolve(e.data);
}));
iframe.src = getAbsoluteServerLocation() + "?file=" + file;
}).then((response) => {
let actual_cookies = diff_tool.diffWith(response.cookies);
let expected_cookies = stripPrefixAndWhitespace(response.expectation);
assert_equals(actual_cookies, expected_cookies);
});
}
};

View file

@ -0,0 +1,54 @@
from os import path;
SETUP_FILE_TEMPLATE = "{}-test"
EXPECTATION_FILE_TEMPLATE = "{}-expected"
EXPECTATION_HTML_SCAFFOLD = "iframe-expectation-doc.html.py-str"
DEBUGGING_HTML_SCAFFOLD = "debugging-single-test.html.py-str"
DEFAULT_RESOURCE_DIR = path.join("cookies", "http-state", "resources")
DEFAULT_TEST_DIR = "test-files"
def dump_file(directory, filename):
return open(path.join(directory, filename), "r").read()
class CookieTestResponse(object):
def __init__(self, file, root):
super(CookieTestResponse, self).__init__()
self.__test_file = SETUP_FILE_TEMPLATE.format(file)
self.__expectation_file = EXPECTATION_FILE_TEMPLATE.format(file)
self.__resources_dir = path.join(root, DEFAULT_RESOURCE_DIR)
self.__test_files_dir = path.join(self.__resources_dir, DEFAULT_TEST_DIR)
def cookie_setting_header(self):
return dump_file(self.__test_files_dir, self.__test_file)
def body_with_expectation(self):
html_frame = dump_file(self.__resources_dir, EXPECTATION_HTML_SCAFFOLD)
expected_data = dump_file(self.__test_files_dir, self.__expectation_file);
return html_frame.format(**{'data' : expected_data})
def main(request, response):
if "debug" in request.GET:
response.writer.write_status(200)
response.writer.end_headers()
html_frame = dump_file(path.join(request.doc_root, DEFAULT_RESOURCE_DIR),
DEBUGGING_HTML_SCAFFOLD)
test_file = html_frame % (request.GET['debug'])
response.writer.write_content(test_file)
return;
if not "file" in request.GET:
response.writer.write_status(404)
response.writer.end_headers()
response.writer.write_content("The 'file' parameter is missing!")
return;
cookie_response = CookieTestResponse(request.GET['file'], request.doc_root)
response.writer.write_status(200)
response.writer.write(cookie_response.cookie_setting_header())
response.writer.end_headers()
response.writer.write_content(cookie_response.body_with_expectation())

View file

@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Debug single test</title>
<meta name=help href="https://tools.ietf.org/html/rfc6265#page-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="cookie-http-state-template.js"></script>
</head>
<body>
<div id="log"></div>
<script>
setup({ explicit_timeout: true });
promise_test(createCookieTest("%s"), "DEBUG", { timeout: 3000 });
</script>
</body>
</html>

View file

@ -0,0 +1,4 @@
window.top.postMessage({
"cookies": document.cookie,
"expectation": document.querySelector('#data').innerText
}, "*");

View file

@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Cookie Test Expectation Document</title>
</head>
<body>
<div id="data">{data}</div>
<script src="iframe-content-pushing.js"></script>
</body>
</html>

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; Expires=Fri, 07 Aug 2019 08:04:19 GMT

View file

@ -0,0 +1 @@
Cookie: foo2=bar2

View file

@ -0,0 +1,2 @@
Set-Cookie: foo=bar; Expires=Fri, 07 Aug 2007 08:04:19 GMT
Set-Cookie: foo2=bar2; Expires=Fri, 07 Aug 2027 08:04:19 GMT

View file

@ -0,0 +1 @@
Set-Cookie: foo

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; max-age=10000;

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; max-age=0;

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; version=1;

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; version=1000;

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; customvalue=1000;

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; secure;

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; customvalue="1000 or more";

View file

@ -0,0 +1 @@
Cookie: foo=bar

View file

@ -0,0 +1 @@
Set-Cookie: foo=bar; customvalue="no trailing semicolon"

View file

@ -0,0 +1 @@
Cookie: foo=qux

View file

@ -0,0 +1,2 @@
Set-Cookie: foo=bar
Set-Cookie: foo=qux

View file

@ -0,0 +1 @@
Cookie: foo1=bar; foo2=qux

View file

@ -0,0 +1,2 @@
Set-Cookie: foo1=bar
Set-Cookie: foo2=qux

View file

@ -0,0 +1 @@
Cookie: a=b; z=y

View file

@ -0,0 +1,2 @@
Set-Cookie: a=b
Set-Cookie: z=y

View file

@ -0,0 +1 @@
Cookie: z=y; a=b

View file

@ -0,0 +1,2 @@
Set-Cookie: z=y
Set-Cookie: a=b

View file

@ -0,0 +1,2 @@
Cookie: z=y, a=b

View file

@ -0,0 +1 @@
Set-Cookie: z=y, a=b

View file

@ -0,0 +1 @@
Set-Cookie: z=y; foo=bar, a=b

View file

@ -0,0 +1 @@
Set-Cookie: foo=b;max-age=3600, c=d;path=/

View file

@ -0,0 +1 @@
Cookie: a=b; c=d

View file

@ -0,0 +1,3 @@
Set-Cookie: a=b
Set-Cookie: =
Set-Cookie: c=d

View file

@ -0,0 +1 @@
Cookie: a=b; c=d

View file

@ -0,0 +1,3 @@
Set-Cookie: a=b
Set-Cookie: =x
Set-Cookie: c=d

View file

@ -0,0 +1 @@
Cookie: a=b; x=; c=d

View file

@ -0,0 +1,3 @@
Set-Cookie: a=b
Set-Cookie: x=
Set-Cookie: c=d

View file

@ -0,0 +1,2 @@
Set-Cookie: foo
Set-Cookie:

View file

@ -0,0 +1,2 @@
Set-Cookie: foo
Set-Cookie: =

View file

@ -0,0 +1,2 @@
Set-Cookie: foo
Set-Cookie: ; bar

View file

@ -0,0 +1,2 @@
Set-Cookie: foo
Set-Cookie:

View file

@ -0,0 +1,2 @@
Set-Cookie: foo
Set-Cookie: bar

View file

@ -0,0 +1,2 @@
Set-Cookie: foo
Set-Cookie:

View file

@ -0,0 +1,2 @@
Set-Cookie: foo
Set-Cookie: