diff --git a/frontend/src/components/AutoLogout.vue b/frontend/src/components/AutoLogout.vue index 7572dd86a0ae9aaee70eb9498252a52b488d5acf..ae037ddffd92a773e33fb16907061ca0865c2fbf 100644 --- a/frontend/src/components/AutoLogout.vue +++ b/frontend/src/components/AutoLogout.vue @@ -4,7 +4,7 @@ max-width="30%" v-model="logoutDialog" > - <v-card> + <v-card id="logout-dialog"> <v-card-title class="headline"> You'll be logged out! </v-card-title> @@ -82,7 +82,7 @@ export default { this.logoutDialog = true } } - }, 5 * 1e3) + }, 1 * 1e3) }, beforeDestroy () { clearInterval(this.timer) diff --git a/frontend/src/components/mixins/mixins.ts b/frontend/src/components/mixins/mixins.ts index 4b93f298605e53630e007eda72b1fba7206d89a1..974e18dff45cde5472666aa3fe0a7b39f5c5cf80 100644 --- a/frontend/src/components/mixins/mixins.ts +++ b/frontend/src/components/mixins/mixins.ts @@ -11,7 +11,6 @@ export enum ExportType { @Component export class parseCSVMapMixin extends Vue { parseCSVMap (csvMap: string) { - console.log('parsing') let lines = csvMap.split('\n') lines.shift() // drop the first line since it contains only headings // TODO remove any type diff --git a/functional_tests/test_auto_logout.py b/functional_tests/test_auto_logout.py new file mode 100644 index 0000000000000000000000000000000000000000..ecdfa41f42d3c4c28eb544c226fdcfbbfb952ce2 --- /dev/null +++ b/functional_tests/test_auto_logout.py @@ -0,0 +1,67 @@ +import datetime +import time +import logging +from django.test import LiveServerTestCase +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as ec + +from core.models import UserAccount +from functional_tests.util import (login, create_browser) +from util import factory_boys as fact + +log = logging.getLogger(__name__) + + +class TestAutoLogout(LiveServerTestCase): + browser: webdriver.Firefox = None + username = None + password = None + role = None + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.browser = create_browser() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + cls.browser.quit() + + def setUp(self): + self.username = 'reviewer' + self.password = 'p' + self.role = UserAccount.TUTOR + fact.UserAccountFactory( + username=self.username, + password=self.password, + role=self.role + ) + + def _login(self): + login(self.browser, self.live_server_url, self.username, self.password) + + def test_auto_logout_can_continue(self): + with self.settings(JWT_AUTH={ + 'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=5), + 'JWT_ALLOW_REFRESH': True, + } + ): + self._login() + initial_token = self.browser.execute_script( + 'return sessionStorage["token"]' + ) + logout_dialog = self.browser.find_element_by_id('logout-dialog') + WebDriverWait(self.browser, 5).until( + ec.visibility_of_element_located((By.ID, 'logout-dialog'))) + logout_dialog.find_element_by_id('continue-btn').click() + # explicit sleep is unfortunately necessary here, since we need to wait + # for the initial token to expire and the site to be the same + time.sleep(2) + self.assertNotIn('login', self.browser.current_url) + new_token = self.browser.execute_script( + 'return sessionStorage["token"]' + ) + self.assertNotEqual(initial_token, new_token)