Skip to content

Commit

Permalink
Prevent flashing lifespan warning
Browse files Browse the repository at this point in the history
Previously, the lifespan warning would flash on a user's screen
every time they clicked a link, because that would result in an
API call to get updated session info. Added a check to prevent
that from happening.
  • Loading branch information
jportner committed Nov 21, 2019
1 parent 3175a6f commit c128fd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
25 changes: 19 additions & 6 deletions x-pack/plugins/security/public/session/session_timeout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('Session Timeout', () => {
test(`shows lifespan warning toast`, async () => {
const sessionInfo = {
now,
idleTimeoutExpiration: now + 2 * 60 * 1000,
idleTimeoutExpiration: null,
lifespanExpiration: now + 2 * 60 * 1000,
};
http.fetch.mockResolvedValue(sessionInfo);
Expand All @@ -183,15 +183,28 @@ describe('Session Timeout', () => {
jest.advanceTimersByTime(10 * 1000);
expectIdleTimeoutWarningToast(notifications);

http.fetch.mockResolvedValue({
now: now + 55 * 1000,
idleTimeoutExpiration: now + 55 * 1000 + 2 * 60 * 1000,
lifespanExpiration: null,
});
await sessionTimeout.extend('/foo');
expect(http.fetch).toHaveBeenCalledTimes(3);
});

test(`extend does not result in an HTTP call if a lifespan warning is shown`, async () => {
const sessionInfo = {
now,
idleTimeoutExpiration: null,
lifespanExpiration: now + 2 * 60 * 1000,
};
http.fetch.mockResolvedValue(sessionInfo);
await sessionTimeout.init();

// we display the warning a minute before we expire the the session, which is 5 seconds before it actually expires
jest.advanceTimersByTime(55 * 1000);
expectLifespanWarningToast(notifications);

expect(http.fetch).toHaveBeenCalledTimes(1);
await sessionTimeout.extend('/foo');
expect(http.fetch).toHaveBeenCalledTimes(1);
});

test(`extend hides displayed warning toast`, async () => {
await sessionTimeout.init();
expect(http.fetch).toHaveBeenCalledTimes(1);
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/security/public/session/session_timeout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ export class SessionTimeout {
return;
}

if (this.warningToast) {
// the warning is currently showing and the user has clicked elsewhere on the page;
const { isMaximum } = this.getTimeout();
if (this.warningToast && !isMaximum) {
// the idle timeout warning is currently showing and the user has clicked elsewhere on the page;
// make a new call to get the latest session info
return this.fetchSessionInfoAndResetTimers();
}
Expand Down

0 comments on commit c128fd5

Please sign in to comment.