mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
Tests: Add test for credentials flag in fetch
This commit is contained in:
parent
36bfee7f1b
commit
193163be2f
|
|
@ -0,0 +1 @@
|
|||
PASS
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
const COOKIE_NAME = "testcookie";
|
||||
|
||||
async function hasCookie(resp) {
|
||||
const body = await resp.json();
|
||||
return body["Cookie"]?.find(
|
||||
(cookie) => cookie.trim().startsWith(COOKIE_NAME + '=')
|
||||
);
|
||||
}
|
||||
|
||||
promiseTest(async () => {
|
||||
try {
|
||||
const httpServer = httpTestServer();
|
||||
const url = await httpServer.createEcho("GET", `/fetch-cors-credentials-flag-cookie`, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": location.origin,
|
||||
"Access-Control-Allow-Credentials": "true",
|
||||
"Set-Cookie": `${COOKIE_NAME}=COOKIE`
|
||||
},
|
||||
reflect_headers_in_body: true,
|
||||
});
|
||||
|
||||
let resp = await fetch(url, { credentials: 'omit' });
|
||||
if (await hasCookie(resp)) {
|
||||
println("FAIL - cookie was set");
|
||||
return;
|
||||
}
|
||||
|
||||
resp = await fetch(url, { credentials: 'include' });
|
||||
if (await hasCookie(resp)) {
|
||||
println("FAIL - cookie was set");
|
||||
return;
|
||||
}
|
||||
|
||||
resp = await fetch(url, { credentials: 'include' });
|
||||
if (!await hasCookie(resp)) {
|
||||
println("FAIL - cookie was not set");
|
||||
return;
|
||||
}
|
||||
|
||||
println("PASS");
|
||||
} catch (err) {
|
||||
println("FAIL - " + err);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user