function checkSessionCookieConstraints(cookieName, expectedValue, domain, path) {
// Get the session cookie if it exists
const cookie = document.cookie.split('; ').find(row => row.startsWith(`${cookieName}=`));
if (!cookie) {
// Cookie doesn't exist
console.log(`Cookie ${cookieName} not found.`);
return false;
}
// Extract the cookie value
const cookieValue = cookie.split('=')[1];
// Check if the cookie value matches the expected value
if (cookieValue !== expectedValue) {
console.log(`Cookie ${cookieName} has unexpected value: ${cookieValue}. Expected: ${expectedValue}`);
return false;
}
// Check the domain
const [domainPart, portPart] = domain.split(':');
if (document.domain !== domainPart) {
console.log(`Domain mismatch: Document domain is ${document.domain}, expected ${domain}`);
return false;
}
//Check the path
if (window.location.pathname !== path) {
console.log(`Path mismatch: Document path is ${window.location.pathname}, expected ${path}`);
return false;
}
// All constraints are met
console.log(`Cookie ${cookieName} constraints met.`);
return true;
}
Add your comment