Bug 1764567 [wpt PR 33622] - Throw exception based on exclusions when creating sanitized cookies, a=testonly

Automatic update from web-platform-tests
Throw exception based on exclusions when creating sanitized cookies

When we get a nullptr cookie from ToCanonicalCookie we assume that
there is an exception to explain the failure. We have a DCHECK to
verify such scenario. However, we only generate assertions if there is
any problem with the cookie url.

The CreateSanitizedCookie function, called to generate the return value
with the canonical cookie, performs some additional checks before
parsing the cookie string. Any error is described in as exclusion in
the CookieInclusionStatus instance. If the status has any exclusion, a
nullptr cookie is returned, but no exception is generated.

The bug 1315053 describes a scenario where we get a nullotr cookie
without an exception, violating the previously mentioned DCHECK. This
change fixes the bug by generating exceptions based on the exclusions
comment if the CreateSanitizedCookie adds any on the status instance.

This change makes our implementation spec complaint, according to what
is stated in the CookieStore-set method [1] algorithm:

"2- If r is failure, then reject p with a TypeError and abort these steps."

[1] https://wicg.github.io/cookie-store/#CookieStore-set

Bug: 1315053
Change-Id: I0ebbf727f7404391b12446a457247c4468754015
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3582579
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Cr-Commit-Position: refs/heads/main@{#992339}

--

wpt-commits: 4e9035fad8bcac85717069a50ab8be5e69a5cadd
wpt-pr: 33622
This commit is contained in:
Javier Fernández García-Boente 2022-04-14 16:19:33 +00:00 коммит произвёл moz-wptsync-bot
Родитель 00bbfb189c
Коммит bab41bfbc0
1 изменённых файлов: 11 добавлений и 0 удалений

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

@ -51,3 +51,14 @@ promise_test(async testCase => {
cookieStore.set( { name: '__Host-cookie-name', value: 'cookie-value',
path: "/path" }));
}, 'cookieStore.set with __Host- prefix a path option');
promise_test(async testCase => {
let exceptionThrown = false;
try {
await cookieStore.set(unescape('cookie-name%0D1'), 'cookie-value');
} catch (e) {
assert_equals (e.name, "TypeError", "cookieStore thrown an incorrect exception -");
exceptionThrown = true;
}
assert_true(exceptionThrown, "No exception thrown.");
}, 'cookieStore.set with malformed name.');