-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic redirect on session timeout (#1839)
* feat(session-redirect): add js module for redirect on session timeout * feat(sign-out): redirect to sign-in page on logout and display message * feat(session-timeout): explicit end users session when they redirect for session timeout * tests(sign-out): add tests for session timeout: 1. Redirect does not occur when not logged in 2. Redirect does occur (on app and public pages) when logged in 3. Explicit logout shows banner message * chore: formatting * test(sign out): app should redirect to /sign-in * chore: fix tests that checked that signing out brought you to `/home` * fix(sign-in): add note about session length to sign in page * style(signin): move session timeout message, update content * test(session-timeout): test for message on sign-in page; add `getByTestId` shortcut to cypress commands * chore: fix typo in test * chore: fix typo in test * Update app/translations/csv/fr.csv
- Loading branch information
1 parent
25b8340
commit 5fde768
Showing
12 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Redirects the user after a specified period of time. | ||
*/ | ||
(function () { | ||
const REDIRECT_LOCATION = "/sign-in?timeout=true"; | ||
const SESSION_TIMEOUT_MS = 7 * 60 * 60 * 1000 + 55 * 60 * 1000; // 7 hours 55 minutes | ||
|
||
redirectCountdown(REDIRECT_LOCATION, SESSION_TIMEOUT_MS); // 7 hours 55 minutes | ||
|
||
/** | ||
* Redirects to the specified location after a given period of time. | ||
* @param {string} redirectLocation - The URL to redirect to. | ||
* @param {number} period - The period of time (in milliseconds) before redirecting. | ||
*/ | ||
function redirectCountdown(redirectLocation, period) { | ||
setTimeout(function () { | ||
window.location.href = redirectLocation; | ||
}, period); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
setTimeout((function(){window.location.href="/sign-in?timeout=true"}),285e5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { LoginPage } from "../../../Notify/Admin/Pages/AllPages"; | ||
|
||
const REDIRECT_LOCATION = '/sign-in?timeout=true'; | ||
const SESSION_TIMEOUT_MS = 7 * 60 * 60 * 1000 + 55 * 60 * 1000; // 7 hours 55 minutes | ||
const vistPageAndFastForwardTime = (page = '/') => { | ||
cy.clock(); | ||
cy.visit(page); | ||
cy.tick(SESSION_TIMEOUT_MS); | ||
}; | ||
|
||
describe('Sign out', () => { | ||
|
||
it('Does not redirect to session timeout page when logged out', () => { | ||
cy.clearCookie('notify_admin_session'); | ||
vistPageAndFastForwardTime(); | ||
|
||
// asserts | ||
cy.url().should('not.include', REDIRECT_LOCATION); | ||
}); | ||
|
||
it('Redirects to session timeout page when logged in (multiple pages)', () => { | ||
['/home', '/features'].forEach((page) => { | ||
LoginPage.Login(Cypress.env('NOTIFY_USER'), Cypress.env('NOTIFY_PASSWORD')); | ||
vistPageAndFastForwardTime(page); | ||
|
||
// asserts | ||
cy.url().should('include', REDIRECT_LOCATION); | ||
cy.get('h1').should('contain', 'You need to sign in again'); | ||
}); | ||
}); | ||
|
||
it('Displays banner on explicit logout', () => { | ||
cy.visit('/sign-out'); | ||
|
||
// asserts | ||
cy.url().should('include', '/sign-in'); | ||
cy.get('.banner-default-with-tick').should('be.visible'); | ||
}); | ||
|
||
it('Displays session timeout info on login page', () => { | ||
cy.visit('/sign-in'); | ||
|
||
// asserts | ||
cy.getByTestId('session_timeout_info').should('be.visible'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters