From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../web-platform/tests/clear-site-data/META.yml | 4 + .../clear-site-data/executionContexts.sub.html | 48 ++++ .../tests/clear-site-data/navigation-insecure.html | 52 ++++ .../tests/clear-site-data/navigation.https.html | 59 +++++ .../tests/clear-site-data/resource.html | 74 ++++++ .../set-cookie-after-clear-all.https.html | 23 ++ .../set-cookie-after-clear-cookies.https.html | 23 ++ .../set-cookie-before-clear-all.https.html | 23 ++ .../set-cookie-before-clear-cookies.https.html | 23 ++ .../tests/clear-site-data/storage.https.html | 110 +++++++++ .../support/clear-site-data-cookie.py | 16 ++ .../clear-site-data/support/controlled-endpoint.py | 3 + .../support/echo-clear-site-data.py | 40 ++++ .../support/iframe_executionContexts.html | 8 + .../support/page_using_service_worker.html | 6 + .../support/page_with_resource.sub.html | 27 +++ .../tests/clear-site-data/support/send_report.html | 24 ++ .../clear-site-data/support/service_worker.js | 6 + .../clear-site-data/support/test_utils.sub.js | 261 +++++++++++++++++++++ 19 files changed, 830 insertions(+) create mode 100644 testing/web-platform/tests/clear-site-data/META.yml create mode 100644 testing/web-platform/tests/clear-site-data/executionContexts.sub.html create mode 100644 testing/web-platform/tests/clear-site-data/navigation-insecure.html create mode 100644 testing/web-platform/tests/clear-site-data/navigation.https.html create mode 100644 testing/web-platform/tests/clear-site-data/resource.html create mode 100644 testing/web-platform/tests/clear-site-data/set-cookie-after-clear-all.https.html create mode 100644 testing/web-platform/tests/clear-site-data/set-cookie-after-clear-cookies.https.html create mode 100644 testing/web-platform/tests/clear-site-data/set-cookie-before-clear-all.https.html create mode 100644 testing/web-platform/tests/clear-site-data/set-cookie-before-clear-cookies.https.html create mode 100644 testing/web-platform/tests/clear-site-data/storage.https.html create mode 100644 testing/web-platform/tests/clear-site-data/support/clear-site-data-cookie.py create mode 100644 testing/web-platform/tests/clear-site-data/support/controlled-endpoint.py create mode 100644 testing/web-platform/tests/clear-site-data/support/echo-clear-site-data.py create mode 100644 testing/web-platform/tests/clear-site-data/support/iframe_executionContexts.html create mode 100644 testing/web-platform/tests/clear-site-data/support/page_using_service_worker.html create mode 100644 testing/web-platform/tests/clear-site-data/support/page_with_resource.sub.html create mode 100644 testing/web-platform/tests/clear-site-data/support/send_report.html create mode 100644 testing/web-platform/tests/clear-site-data/support/service_worker.js create mode 100644 testing/web-platform/tests/clear-site-data/support/test_utils.sub.js (limited to 'testing/web-platform/tests/clear-site-data') diff --git a/testing/web-platform/tests/clear-site-data/META.yml b/testing/web-platform/tests/clear-site-data/META.yml new file mode 100644 index 0000000000..65ca96dbb9 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/META.yml @@ -0,0 +1,4 @@ +spec: https://w3c.github.io/webappsec-clear-site-data/ +suggested_reviewers: + - mikewest + - msramek diff --git a/testing/web-platform/tests/clear-site-data/executionContexts.sub.html b/testing/web-platform/tests/clear-site-data/executionContexts.sub.html new file mode 100644 index 0000000000..b3ae17576a --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/executionContexts.sub.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/navigation-insecure.html b/testing/web-platform/tests/clear-site-data/navigation-insecure.html new file mode 100644 index 0000000000..9ccd712a22 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/navigation-insecure.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/navigation.https.html b/testing/web-platform/tests/clear-site-data/navigation.https.html new file mode 100644 index 0000000000..dbddce3c13 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/navigation.https.html @@ -0,0 +1,59 @@ + + + + + + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/resource.html b/testing/web-platform/tests/clear-site-data/resource.html new file mode 100644 index 0000000000..a966cb95aa --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/resource.html @@ -0,0 +1,74 @@ + + + + + + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/set-cookie-after-clear-all.https.html b/testing/web-platform/tests/clear-site-data/set-cookie-after-clear-all.https.html new file mode 100644 index 0000000000..73f6bafc25 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/set-cookie-after-clear-all.https.html @@ -0,0 +1,23 @@ + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/set-cookie-after-clear-cookies.https.html b/testing/web-platform/tests/clear-site-data/set-cookie-after-clear-cookies.https.html new file mode 100644 index 0000000000..69a99e7f58 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/set-cookie-after-clear-cookies.https.html @@ -0,0 +1,23 @@ + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/set-cookie-before-clear-all.https.html b/testing/web-platform/tests/clear-site-data/set-cookie-before-clear-all.https.html new file mode 100644 index 0000000000..73bd3476fb --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/set-cookie-before-clear-all.https.html @@ -0,0 +1,23 @@ + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/set-cookie-before-clear-cookies.https.html b/testing/web-platform/tests/clear-site-data/set-cookie-before-clear-cookies.https.html new file mode 100644 index 0000000000..28ba79e9f8 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/set-cookie-before-clear-cookies.https.html @@ -0,0 +1,23 @@ + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/storage.https.html b/testing/web-platform/tests/clear-site-data/storage.https.html new file mode 100644 index 0000000000..854c8f259e --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/storage.https.html @@ -0,0 +1,110 @@ + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/support/clear-site-data-cookie.py b/testing/web-platform/tests/clear-site-data/support/clear-site-data-cookie.py new file mode 100644 index 0000000000..eb50cb54ef --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/clear-site-data-cookie.py @@ -0,0 +1,16 @@ +""" +Step 2/3 (/clear-site-data/set-cookie-{}-clear-{}.https.html) +""" +def main(request, response): + headers = [(b"Content-Type", b"text/html")] + clear_site_data_header = (b"Clear-Site-Data", b"\"" + request.GET.first(b"target", b"*") + b"\"") + set_cookie_header = (b"Set-Cookie", b"testSetWithClear=true") + if request.GET.first(b"location") == b"after": + headers = headers + [clear_site_data_header, set_cookie_header] + else: + headers = headers + [set_cookie_header, clear_site_data_header] + content = u''' + ''' + return 200, headers, content diff --git a/testing/web-platform/tests/clear-site-data/support/controlled-endpoint.py b/testing/web-platform/tests/clear-site-data/support/controlled-endpoint.py new file mode 100644 index 0000000000..bb4f464088 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/controlled-endpoint.py @@ -0,0 +1,3 @@ +def main(request, response): + return ([(b"Content-Type", b"text/html")], + u"FROM_NETWORK") diff --git a/testing/web-platform/tests/clear-site-data/support/echo-clear-site-data.py b/testing/web-platform/tests/clear-site-data/support/echo-clear-site-data.py new file mode 100644 index 0000000000..6419d5bfad --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/echo-clear-site-data.py @@ -0,0 +1,40 @@ +import json + +RESPONSE = u""" + + + + Clear-Site-Data + + + + + + +""" + +# A support server that receives a list of datatypes in the GET query +# and returns a Clear-Site-Data header with those datatypes. The content +# of the response is a html site using postMessage to report the status +# of the datatypes, so that if used in an iframe, it can inform the +# embedder whether the data deletion succeeded. +def main(request, response): + types = [key for key in request.GET.keys()] + header = b",".join(b"\"" + type + b"\"" for type in types) + return ([(b"Clear-Site-Data", header), + (b"Content-Type", b"text/html")], + RESPONSE) diff --git a/testing/web-platform/tests/clear-site-data/support/iframe_executionContexts.html b/testing/web-platform/tests/clear-site-data/support/iframe_executionContexts.html new file mode 100644 index 0000000000..9c20c9e0db --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/iframe_executionContexts.html @@ -0,0 +1,8 @@ + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/support/page_using_service_worker.html b/testing/web-platform/tests/clear-site-data/support/page_using_service_worker.html new file mode 100644 index 0000000000..968a39a132 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/page_using_service_worker.html @@ -0,0 +1,6 @@ + + + + Clear-Site-Data + Service Workers Test Page + + \ No newline at end of file diff --git a/testing/web-platform/tests/clear-site-data/support/page_with_resource.sub.html b/testing/web-platform/tests/clear-site-data/support/page_with_resource.sub.html new file mode 100644 index 0000000000..703519a2f6 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/page_with_resource.sub.html @@ -0,0 +1,27 @@ + + + + Clear-Site-Data + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/support/send_report.html b/testing/web-platform/tests/clear-site-data/support/send_report.html new file mode 100644 index 0000000000..6e90c626ea --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/send_report.html @@ -0,0 +1,24 @@ + + + + Clear-Site-Data + + + + + + diff --git a/testing/web-platform/tests/clear-site-data/support/service_worker.js b/testing/web-platform/tests/clear-site-data/support/service_worker.js new file mode 100644 index 0000000000..a4e5709ee1 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/service_worker.js @@ -0,0 +1,6 @@ +self.addEventListener('fetch', (e) => { + const url = new URL(e.request.url); + if (url.pathname.match('controlled-endpoint.py')) { + e.respondWith(new Response('FROM_SERVICE_WORKER')); + } +}); \ No newline at end of file diff --git a/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js b/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js new file mode 100644 index 0000000000..71fc79c420 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js @@ -0,0 +1,261 @@ +var TestUtils = (function() { + function randomString() { + var result = ""; + for (var i = 0; i < 5; i++) + result += String.fromCharCode(97 + Math.floor(Math.random() * 26)); + return result; + }; + + /** + * Representation of one datatype. + * @typedef Datatype + * @type{object} + * @property{string} name Name of the datatype. + * @property{function():boolean} supported + * Whether this datatype is supported by this user agent. + * @method{function():Void} add A function to add an instance of the datatype. + * @method{function():boolean} isEmpty A function that tests whether + * the datatype's storage backend is empty. + */ + var Datatype; + + var TestUtils = {}; + + /** + * Various storage backends that are part of the 'storage' datatype. + * @param{Array.} + */ + TestUtils.STORAGE = [ + { + "name": "local storage", + "supported": function() { return !!window.localStorage; }, + "add": function() { + return new Promise(function(resolve, reject) { + localStorage.setItem(randomString(), randomString()); + resolve(); + }); + }, + "isEmpty": function() { + return new Promise(function(resolve, reject) { + resolve(!localStorage.length); + }); + } + }, + { + "name": "Indexed DB", + "supported": function() { return !!window.indexedDB; }, + "add": function() { + return new Promise(function(resolve, reject) { + var request = window.indexedDB.open("database"); + request.onupgradeneeded = function() { + request.result.createObjectStore("store"); + }; + request.onsuccess = function() { + request.result.close(); + resolve(); + } + }); + }, + "isEmpty": function() { + return new Promise(function(resolve, reject) { + var request = window.indexedDB.open("database"); + request.onsuccess = function() { + var database = request.result; + try { + var transaction = database.transaction(["store"]); + resolve(false); + } catch(error) { + // The database is empty. However, by testing that, we have also + // created it, which means that |onupgradeneeded| in the "add" + // method will not run the next time. Delete the database before + // reporting that it was empty. + var deletion = window.indexedDB.deleteDatabase("database"); + deletion.onsuccess = resolve.bind(this, true); + } finally { + database.close(); + } + }; + }); + } + }, + { + // TODO(@msramek): We should also test the PERSISTENT filesystem, however, + // that might require storage permissions. + "name": "filesystems", + "supported": function() { + return window.requestFileSystem || window.webkitRequestFileSystem; + }, + "add": function() { + return new Promise(function(resolve, reject) { + var onSuccess = function(fileSystem) { + fileSystem.root.getFile('file', {"create": true}, resolve, resolve); + } + var onFailure = resolve; + + var requestFileSystem = + window.requestFileSystem || window.webkitRequestFileSystem; + requestFileSystem(window.TEMPORARY, 1 /* 1B */, + onSuccess, onFailure); + }); + }, + "isEmpty": function() { + return new Promise(function(resolve, reject) { + var onSuccess = function(fileSystem) { + fileSystem.root.getFile( + 'file', {}, + resolve.bind(this, false) /* opened successfully */, + resolve.bind(this, true) /* failed to open */); + } + var onFailure = resolve.bind(this, true); + + var requestFileSystem = + window.requestFileSystem || window.webkitRequestFileSystem; + requestFileSystem(window.TEMPORARY, 1 /* 1B */, + onSuccess, onFailure); + }); + } + }, + { + "name": "service workers", + "supported": function() { return !!navigator.serviceWorker; }, + "add": function() { + return navigator.serviceWorker.register( + "support/service_worker.js", + { scope: "support/page_using_service_worker.html"}); + }, + "isEmpty": function() { + return new Promise(function(resolve, reject) { + navigator.serviceWorker.getRegistrations() + .then(function(registrations) { + resolve(!registrations.length); + }); + }); + } + }, + { + "name": "Storage Buckets", + "supported": function() { return !!navigator.storageBuckets; }, + "add": function() { + return navigator.storageBuckets.open('inbox_bucket'); + }, + "isEmpty": function() { + return new Promise(async function(resolve, reject) { + var keys = await navigator.storageBuckets.keys(); + resolve(!keys.includes('inbox_bucket')); + }); + } + }, + ].filter(function(backend) { return backend.supported(); }); + + /** + * All datatypes supported by Clear-Site-Data. + * @param{Array.} + */ + TestUtils.DATATYPES = [ + { + "name": "cookies", + "supported": function() { return typeof document.cookie == "string"; }, + "add": function() { + return new Promise(function(resolve, reject) { + document.cookie = randomString() + "=" + randomString(); + resolve(); + }); + }, + "isEmpty": function() { + return new Promise(function(resolve, reject) { + resolve(!document.cookie); + }); + } + }, + { + "name": "storage", + "supported": TestUtils.STORAGE[0].supported, + "add": TestUtils.STORAGE[0].add, + "isEmpty": TestUtils.STORAGE[0].isEmpty, + } + ].filter(function(datatype) { return datatype.supported(); }); + + /** + * All possible combinations of datatypes. + * @property {Array.>} + */ + TestUtils.COMBINATIONS = (function() { + var combinations = []; + for (var mask = 0; mask < (1 << TestUtils.DATATYPES.length); mask++) { + var combination = []; + + for (var datatype = 0; + datatype < TestUtils.DATATYPES.length; datatype++) { + if (mask & (1 << datatype)) + combination.push(TestUtils.DATATYPES[datatype]); + } + + combinations.push(combination); + } + return combinations; + })(); + + /** + * Populates |datatypes| by calling the "add" method on each of them, + * and verifies that they are nonempty. + * @param {Array.} datatypes to be populated. + * @private + */ + function populate(datatypes) { + return Promise.all(datatypes.map(function(datatype) { + return new Promise(function(resolve, reject) { + datatype.add().then(function() { + datatype.isEmpty().then(function(isEmpty) { + assert_false( + isEmpty, + datatype.name + + " has to be nonempty before the test starts."); + resolve(); + }); + }); + }); + })); + }; + + /** + * Ensures that all datatypes are nonempty. Should be called in the test + * setup phase. + */ + TestUtils.populateDatatypes = populate.bind(this, TestUtils.DATATYPES); + + /** + * Ensures that all backends of the "storage" datatype are nonempty. Should + * be called in the test setup phase. + */ + TestUtils.populateStorage = populate.bind(this, TestUtils.STORAGE); + + /** + * Get the support server URL that returns a Clear-Site-Data header + * to clear |datatypes|. + * @param{Array.} datatypes The list of datatypes to be deleted. + * @return string The URL to be queried. + */ + TestUtils.getClearSiteDataUrl = function(datatypes) { + names = datatypes.map(function(e) { return e.name }); + return "support/echo-clear-site-data.py?" + names.join("&"); + } + + /** + * @param{string} page_scheme Scheme of the page. "http" or "https". + * @param{string} resource_scheme Scheme of the resource. "http" or "https". + * @return The URL of a page that contains a resource requesting the deletion + * of storage. + */ + TestUtils.getPageWithResourceUrl = function(page_scheme, resource_scheme) { + if (page_scheme != "https" && page_scheme != "http") + throw "Unsupported scheme: " + page_scheme; + if (resource_scheme != "https" && resource_scheme != "http") + throw "Unsupported scheme: " + resource_scheme; + return page_scheme + "://{{domains[]}}:" + + (page_scheme == "https" ? {{ports[https][0]}} : {{ports[http][0]}}) + + "/clear-site-data/support/page_with_resource.sub.html?scheme=" + + resource_scheme; + } + + return TestUtils; +})(); -- cgit v1.2.3