changeset 163:30c212a6f580

fix: Bugfix for session evaluation Refactoring the session introduced bug. Expires is stored as string and not time millis.
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 05 Jul 2018 18:15:04 +0200
parents 9908260d1e6a
children 7c40e9f28f94
files client/src/lib/session.js client/tests/unit/session.spec.js
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/lib/session.js	Thu Jul 05 18:01:39 2018 +0200
+++ b/client/src/lib/session.js	Thu Jul 05 18:15:04 2018 +0200
@@ -1,7 +1,10 @@
 function sessionStillActive(expiresFromPastSession) {
   if (!expiresFromPastSession) return false;
   const now = Date.now();
-  const sessionEnd = expiresFromPastSession;
+  const sessionEnd =
+    typeof expiresFromPastSession === "string"
+      ? expiresFromPastSession * 1000
+      : expiresFromPastSession;
   const stillActive = now < sessionEnd;
   return stillActive;
 }
--- a/client/tests/unit/session.spec.js	Thu Jul 05 18:01:39 2018 +0200
+++ b/client/tests/unit/session.spec.js	Thu Jul 05 18:15:04 2018 +0200
@@ -13,3 +13,13 @@
   const active = Date.now() + 60000;
   expect(sessionStillActive(active)).toBe(true);
 });
+
+test("Session alive with string", () => {
+  const active = "" + Date.now() + 60000;
+  expect(sessionStillActive(active)).toBe(true);
+});
+
+test("Session expired with string", () => {
+  const expired = "" + Date.now() - 60000;
+  expect(sessionStillActive(expired)).toBe(false);
+});