blob: 6120e5b98d73fb179dd685fab03d112ae92d8c50 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="/js-test-resources/js-test.js"></script>
<script src="/cookies/resources/cookie-utilities.js"></script>
<script src="resources/util.js"></script>
</head>
<body onload="runTest()">
<script>
description("Test for CNAME Cloaking: Cookie expiry capping if the top frame has no alternate CNAME and the sub resource has an alternate CNAME.");
jsTestIsAsync = true;
function finishTest() {
resetCookiesForCurrentOrigin();
setEnableFeature(false, function() {
finishJSTest();
});
}
const oneWeekInSeconds = 7 * 24 * 60 * 60;
const overOneWeekInSeconds = oneWeekInSeconds + 600;
const underOneWeekInSeconds = oneWeekInSeconds - 600;
function checkCookieExpiry(cookieData, seconds, shouldBeLessThan) {
let now = new Date();
let expiryDateInMilliseconds = now.getTime() + (seconds * 1000);
if ((cookieData["expires"] < expiryDateInMilliseconds) === shouldBeLessThan) {
let underOneWeekExpiryDateInMilliseconds = now.getTime() + (underOneWeekInSeconds * 1000);
if (cookieData["expires"] < underOneWeekExpiryDateInMilliseconds)
testFailed("Cookie named " + cookieData["name"] + " was capped too low.");
else
testPassed("Cookie named " + cookieData["name"] + " expires in " + (shouldBeLessThan ? "less" : "more") + " than " + seconds + " seconds.");
} else
testFailed("Cookie named " + cookieData["name"] + " expires in " + (shouldBeLessThan ? "more" : "less") + " than " + seconds + " seconds.");
}
const cookieName = "cnameTestCookie";
const subPathToSetFirstPartyCookie = "resources/set-cookie.py?name=" + cookieName + "&value=value&dummy=" + Math.random();
function setAndCheckCookie() {
fetch(subPathToSetFirstPartyCookie).then(function() {
if (internals) {
let cookies = internals.getCookies();
if (!cookies.length)
testFailed("No cookies found.");
for (let cookie of cookies) {
if (cookie.name === cookieName) {
checkCookieExpiry(cookie, overOneWeekInSeconds, true);
} else {
testFailed("Unknown cookie " + cookie.name + " found.");
}
}
finishTest();
}
});
}
const firstParty = "http://127.0.0.1:8000";
const thirdPartyCNAMEForTesting = "http://3rdpartytestwebkit.org";
function runTest() {
setEnableFeature(true, function() {
testRunner.statisticsSetThirdPartyCNAMEDomain(thirdPartyCNAMEForTesting, function() {
setAndCheckCookie();
});
});
}
</script>
</body>