Skip to content

Commit

Permalink
fix: removed cookies when max-age equal to the lifespan (#2853)
Browse files Browse the repository at this point in the history
* fix: removed cookies when max-age  equal to the life span

* build: updated version
  • Loading branch information
Aleksey28 authored Feb 8, 2023
1 parent 2ebc842 commit 60c6bca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "testcafe-hammerhead",
"description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).",
"version": "28.4.1",
"version": "28.4.2",
"homepage": "https://github.com/DevExpress/testcafe-hammerhead",
"bugs": {
"url": "https://github.com/DevExpress/testcafe-hammerhead/issues"
Expand Down
4 changes: 3 additions & 1 deletion src/client/sandbox/cookie/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import MessageSandbox from '../event/message';
import UnloadSandbox from '../event/unload';
import SandboxBase from '../base';
Expand Down Expand Up @@ -118,6 +119,7 @@ class CookieSandboxProxyStrategy implements CookieSandboxStrategy {
}
}

/* eslint-disable */
syncCookie (gettingCookies = false): void {
const cookies = nativeMethods.documentCookieGetter.call(this.document);
const parsedCookies = parseClientSyncCookieStr(cookies);
Expand All @@ -140,7 +142,7 @@ class CookieSandboxProxyStrategy implements CookieSandboxStrategy {
const maxAge = !isNull(parsedCookie.maxAge) && Number(parsedCookie.maxAge);
const expires = Number(parsedCookie.expires);

if (!isNaN(maxAge) && isNumber(maxAge) && maxAge * 1000 < currentDate.getTime() - parsedCookie.lastAccessed.getTime() ||
if (!isNaN(maxAge) && isNumber(maxAge) && maxAge * 1000 <= currentDate.getTime() - parsedCookie.lastAccessed.getTime() ||
!isNaN(expires) && isNumber(expires) && expires < currentDate.getTime()) {
nativeMethods.documentCookieSetter.call(this.document, generateDeleteSyncCookieStr(parsedCookie));
CookieSandbox._updateClientCookieStr(parsedCookie.key, null);
Expand Down
4 changes: 3 additions & 1 deletion test/client/fixtures/sandbox/cookie-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
// NOTE: You should clear a browser's cookie if tests are fail,
// because document.cookie can contains cookie from another sites which was run through playground
var sharedCookieUtils = hammerhead.sharedUtils.cookie;
Expand Down Expand Up @@ -107,7 +108,8 @@ if (!isGreaterThanSafari15_1) { //eslint-disable-line camelcase
'TestExpired1=value; expires=' + new Date((Math.floor(Date.now() / 1000) + 1) * 1000).toUTCString(),
'TestExpired2=value; max-age=' + 1,
'TestNotExpired3=value',
], 'TestNotExpired3=value', 2000);
'TestExpired4=value; max-age=' + 2,
], 'TestNotExpired3=value', 2100);
})
.then(function () {
return destLocation.forceLocation(storedForcedLocation);
Expand Down

0 comments on commit 60c6bca

Please sign in to comment.