Bug 1692478 [wpt PR 27607] - Clear reports in WPT collector when queried., a=testonly

Automatic update from web-platform-tests
Clear reports in WPT collector when queried.

This fixes a bug in the WPT report collector where reports are not
removed from the stash when queried, as they were intended to be.

There was one test in the Network Error Logging suite which relied on
this bug, and tested reports in two passes, which could now fail if all
reports are received before the first query is performed, so this CL
also fixes that test by adding an optional 'retain' query parameter to
the report collector.

Bug: 1177757
Change-Id: I945325f15a2ce633cfa32bcebeedb5be5afaa860
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2689369
Reviewed-by: Stephen McGruer <smcgruer@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#853528}

--

wpt-commits: be055c46bb610b18e2c3f5612aff388f9003750f
wpt-pr: 27607
This commit is contained in:
Ian Clelland 2021-02-16 03:21:49 +00:00 коммит произвёл moz-wptsync-bot
Родитель 87648868b2
Коммит 0469c9ee08
4 изменённых файлов: 23 добавлений и 13 удалений

Просмотреть файл

@ -32,7 +32,7 @@
metadata: {
content_type: "application/reports+json",
},
}), "receive report about redirected resource");
}, true /* retain */), "receive report about redirected resource");
assert_true(await reportExists({
// This happens to be where we're redirected to.
url: getURLForResourceWithNoPolicy(),

Просмотреть файл

@ -247,12 +247,14 @@ function _isSubsetOf(obj1, obj2) {
* expected.
*/
async function reportExists(expected) {
async function reportExists(expected, retain_reports) {
var timeout =
document.querySelector("meta[name=timeout][content=long]") ? 50 : 1;
var reportLocation =
"/reporting/resources/report.py?op=retrieve_report&timeout=" +
timeout + "&reportID=" + reportID;
if (retain_reports)
reportLocation += "&retain=1";
const response = await fetch(reportLocation);
const json = await response.json();
for (const report of json) {
@ -268,11 +270,13 @@ async function reportExists(expected) {
* expected.
*/
async function reportsExist(expected_reports) {
async function reportsExist(expected_reports, retain_reports) {
const timeout = 10;
let reportLocation =
"/reporting/resources/report.py?op=retrieve_report&timeout=" +
timeout + "&reportID=" + reportID;
if (retain_reports)
reportLocation += "&retain";
// There must be the report of pass.png, so adding 1.
const min_count = expected_reports.length + 1;
reportLocation += "&min_count=" + min_count;

Просмотреть файл

@ -31,6 +31,8 @@ Supported GET parameters:
`min_count`: The minimum number of reports to return with the `retrieve_report`
operation. If there have been fewer than this many reports received, then an
empty report list will be returned instead.
`retain`: If present, reports will remain in the stash after being retrieved.
By default, reports are cleared once retrieved.
Operations:
`retrieve_report`: Returns all reports received so far for this reportID, as a

Просмотреть файл

@ -5,7 +5,7 @@ import uuid
from wptserve.utils import isomorphic_decode
def retrieve_from_stash(request, key, timeout, default_value, min_count=None):
def retrieve_from_stash(request, key, timeout, default_value, min_count=None, retain=False):
"""Retrieve the set of reports for a given report ID.
This will extract either the set of reports, credentials, or request count
@ -22,8 +22,11 @@ def retrieve_from_stash(request, key, timeout, default_value, min_count=None):
time.sleep(0.5)
with request.server.stash.lock:
value = request.server.stash.take(key=key)
if value is not None and (min_count is None or len(value) >= min_count):
if value is not None:
have_sufficient_reports = (min_count is None or len(value) >= min_count)
if retain or not have_sufficient_reports:
request.server.stash.put(key=key, value=value)
if have_sufficient_reports:
# If the last report received looks like a CSP report-uri report, then
# extract it from the list and return it alone. (This is until the CSP
# tests are modified to expect a list of reports returned in all cases.)
@ -67,10 +70,11 @@ def main(request, response):
min_count = int(request.GET.first(b"min_count"))
except:
min_count = 1
retain = (b"retain" in request.GET)
op = request.GET.first(b"op", b"")
if op in (b"retrieve_report", b""):
return [(b"Content-Type", b"application/json")], retrieve_from_stash(request, key, timeout, u'[]', min_count)
return [(b"Content-Type", b"application/json")], retrieve_from_stash(request, key, timeout, u'[]', min_count, retain)
if op == b"retrieve_cookies":
return [(b"Content-Type", b"application/json")], u"{ \"reportCookies\" : " + str(retrieve_from_stash(request, cookie_key, timeout, u"\"None\"")) + u"}"