Skip to content

Commit

Permalink
STCOR-880 (STCOR-869 backport) add margin to prevent cookie expiration (
Browse files Browse the repository at this point in the history
#1529)

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

(cherry picked from commit da01a6a)

See PR #1513

Refs STCOR-880, STCOR-869

---------

Co-authored-by: Ryan Berger <[email protected]>
  • Loading branch information
zburke and ryandberger authored Sep 6, 2024
1 parent 9038661 commit 3aef1a0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Change history for stripes-core

## [10.1.1](https://github.com/folio-org/stripes-core/tree/v10.1.1) (2024-03-25)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.1.0...v10.1.1)
## IN PROGRESS

* Use keycloak URLs in place of users-bl for tenant-switch. Refs US1153537.
* Idle-session timeout and "Keep working?" modal. Refs STCOR-776.
Expand All @@ -10,6 +9,13 @@
* `/users-keycloak/_self` is an authentication request. Refs STCOR-866.
* Terminate the session when the fixed-length session expires. Refs STCOR-862.
* Provide `key` to elements in `<SessionEventContainer>`. Refs STCOR-874.
* Do not store /logout as a "return-to" URL. Refs STCOR-869.
* Add small margin to ensure /authn/logout is called before cookie expires. Refs STCOR-869.

## [10.1.1](https://github.com/folio-org/stripes-core/tree/v10.1.1) (2024-03-25)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.1.0...v10.1.1)

* Utilize the `tenant` procured through the SSO login process. Refs STCOR-769.

## [10.1.0](https://github.com/folio-org/stripes-core/tree/v10.1.0) (2024-03-12)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.0.0...v10.1.0)
Expand Down
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 3aef1a0

Please sign in to comment.