Skip to content

Commit

Permalink
[STCOR-869] Add small margin to ensure /logout is called before cooki…
Browse files Browse the repository at this point in the history
…e expires (#1513)

* Added a small time margin to wait so that cookie is not deleted before /logout request

* Fix test and lint issue

(cherry picked from commit da01a6a)
  • Loading branch information
ryandberger authored and zburke committed Sep 5, 2024
1 parent d4e9f1d commit 6288840
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/Root/FFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
RTR_AT_TTL_FRACTION,
RTR_ERROR_EVENT,
RTR_FLS_TIMEOUT_EVENT,
RTR_TIME_MARGIN_IN_MS,
RTR_FLS_WARNING_EVENT,
RTR_RT_EXPIRY_IF_UNKNOWN,
} from './constants';
Expand Down Expand Up @@ -142,7 +143,7 @@ export class FFetch {
this.store.dispatch(setRtrFlsTimeout(setTimeout(() => {
this.logger.log('rtr-fls', 'emitting RTR_FLS_TIMEOUT_EVENT');
window.dispatchEvent(new Event(RTR_FLS_TIMEOUT_EVENT));
}, rtTimeoutInterval)));
}, rtTimeoutInterval - RTR_TIME_MARGIN_IN_MS))); // Calling /logout a small margin before cookie is deleted to ensure it is included in the request
});
};

Expand Down
5 changes: 3 additions & 2 deletions src/components/Root/FFetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RTR_AT_EXPIRY_IF_UNKNOWN,
RTR_AT_TTL_FRACTION,
RTR_FLS_WARNING_TTL,
RTR_TIME_MARGIN_IN_MS,
} from './constants';

jest.mock('../../loginServices', () => ({
Expand Down Expand Up @@ -206,7 +207,7 @@ describe('FFetch class', () => {
expect(st).toHaveBeenCalledWith(expect.any(Function), (refreshTokenExpiration - whatTimeIsItMrFox) - ms(RTR_FLS_WARNING_TTL));

// FLS timeout
expect(st).toHaveBeenCalledWith(expect.any(Function), (refreshTokenExpiration - whatTimeIsItMrFox));
expect(st).toHaveBeenCalledWith(expect.any(Function), (refreshTokenExpiration - whatTimeIsItMrFox - RTR_TIME_MARGIN_IN_MS));
});

it('handles RTR data in the session', async () => {
Expand Down Expand Up @@ -379,7 +380,7 @@ describe('FFetch class', () => {
expect(st).toHaveBeenCalledWith(expect.any(Function), (refreshTokenExpiration - whatTimeIsItMrFox) - ms(RTR_FLS_WARNING_TTL));

// FLS timeout
expect(st).toHaveBeenCalledWith(expect.any(Function), (refreshTokenExpiration - whatTimeIsItMrFox));
expect(st).toHaveBeenCalledWith(expect.any(Function), (refreshTokenExpiration - whatTimeIsItMrFox - RTR_TIME_MARGIN_IN_MS));
});
});

Expand Down
6 changes: 6 additions & 0 deletions src/components/Root/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ export const RTR_IDLE_MODAL_TTL = '1m';
*/
export const RTR_AT_EXPIRY_IF_UNKNOWN = '10s';
export const RTR_RT_EXPIRY_IF_UNKNOWN = '10m';

/**
* To account for minor delays between events (such as cookie expiration and API calls),
* this is a small amount of time to wait so the proper order can be ensured if they happen simultaneously.
*/
export const RTR_TIME_MARGIN_IN_MS = 200;

0 comments on commit 6288840

Please sign in to comment.