From ed10d7d1a00b8cc8ae65d6efa1323921e800e649 Mon Sep 17 00:00:00 2001 From: mahula Date: Wed, 13 Jul 2022 14:54:17 +0200 Subject: [PATCH 1/5] set session timer to 0, if expiration is greater then 0 seconds --- frontend/src/components/SessionLogoutTimeout.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/SessionLogoutTimeout.vue b/frontend/src/components/SessionLogoutTimeout.vue index 1e5a27998..113362abf 100644 --- a/frontend/src/components/SessionLogoutTimeout.vue +++ b/frontend/src/components/SessionLogoutTimeout.vue @@ -65,7 +65,7 @@ export default { this.$timer.restart('tokenExpires') this.$bvModal.show('modalSessionTimeOut') } - if (this.tokenExpiresInSeconds <= 0) { + if (this.tokenExpiresInSeconds === 0) { this.$timer.stop('tokenExpires') this.$emit('logout') } @@ -90,7 +90,11 @@ export default { }, computed: { tokenExpiresInSeconds() { - return Math.floor((new Date(this.$store.state.tokenTime * 1000).getTime() - this.now) / 1000) + const remainingSecs = Math.floor( + (new Date(this.$store.state.tokenTime * 1000).getTime() - this.now) / 1000, + ) + if (remainingSecs <= 0) return 0 + return remainingSecs }, }, beforeDestroy() { From b2164e6d1dc90fed257fcbb95601b5b5cc218e46 Mon Sep 17 00:00:00 2001 From: mahula Date: Wed, 13 Jul 2022 14:54:47 +0200 Subject: [PATCH 2/5] add unit test for this fix --- frontend/src/components/SessionLogoutTimeout.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/SessionLogoutTimeout.spec.js b/frontend/src/components/SessionLogoutTimeout.spec.js index 0f5d21d36..94751f9cb 100644 --- a/frontend/src/components/SessionLogoutTimeout.spec.js +++ b/frontend/src/components/SessionLogoutTimeout.spec.js @@ -62,12 +62,16 @@ describe('SessionLogoutTimeout', () => { }) }) - describe('token is expired', () => { + describe('token is expired for several seconds', () => { beforeEach(() => { mocks.$store.state.tokenTime = setTokenTime(-60) wrapper = Wrapper() }) + it('value for remaining seconds is 0', () => { + expect(wrapper.tokenExpiresInSeconds === 0) + }) + it('emits logout', () => { expect(wrapper.emitted('logout')).toBeTruthy() }) From 1d1cc7e960aa845de7a659f6e5f4f25442c52e1b Mon Sep 17 00:00:00 2001 From: mahula Date: Wed, 13 Jul 2022 15:36:15 +0200 Subject: [PATCH 3/5] Update frontend/src/components/SessionLogoutTimeout.spec.js Co-authored-by: Moriz Wahl --- frontend/src/components/SessionLogoutTimeout.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/SessionLogoutTimeout.spec.js b/frontend/src/components/SessionLogoutTimeout.spec.js index 94751f9cb..bd6911d13 100644 --- a/frontend/src/components/SessionLogoutTimeout.spec.js +++ b/frontend/src/components/SessionLogoutTimeout.spec.js @@ -68,7 +68,7 @@ describe('SessionLogoutTimeout', () => { wrapper = Wrapper() }) - it('value for remaining seconds is 0', () => { + it('has value for remaining seconds equal 0', () => { expect(wrapper.tokenExpiresInSeconds === 0) }) From 2302da9054785b8b4a7ca330fd1ddbdd42826ce0 Mon Sep 17 00:00:00 2001 From: mahula Date: Wed, 13 Jul 2022 15:36:40 +0200 Subject: [PATCH 4/5] Update frontend/src/components/SessionLogoutTimeout.vue Co-authored-by: Moriz Wahl --- frontend/src/components/SessionLogoutTimeout.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/components/SessionLogoutTimeout.vue b/frontend/src/components/SessionLogoutTimeout.vue index 113362abf..f10b8114a 100644 --- a/frontend/src/components/SessionLogoutTimeout.vue +++ b/frontend/src/components/SessionLogoutTimeout.vue @@ -93,8 +93,7 @@ export default { const remainingSecs = Math.floor( (new Date(this.$store.state.tokenTime * 1000).getTime() - this.now) / 1000, ) - if (remainingSecs <= 0) return 0 - return remainingSecs + return remainingSecs <= 0 ? 0 : remainingSecs }, }, beforeDestroy() { From 90d90ca9bd9960457aa6a3267e73628d21675519 Mon Sep 17 00:00:00 2001 From: mahula Date: Wed, 13 Jul 2022 19:04:38 +0200 Subject: [PATCH 5/5] fix linting --- frontend/src/components/SessionLogoutTimeout.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/SessionLogoutTimeout.vue b/frontend/src/components/SessionLogoutTimeout.vue index f10b8114a..1ebff752a 100644 --- a/frontend/src/components/SessionLogoutTimeout.vue +++ b/frontend/src/components/SessionLogoutTimeout.vue @@ -93,7 +93,7 @@ export default { const remainingSecs = Math.floor( (new Date(this.$store.state.tokenTime * 1000).getTime() - this.now) / 1000, ) - return remainingSecs <= 0 ? 0 : remainingSecs + return remainingSecs <= 0 ? 0 : remainingSecs }, }, beforeDestroy() {