-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/dangling-subscriptions-livechat-rooms
- Loading branch information
Showing
15 changed files
with
106 additions
and
10 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,8 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
"@rocket.chat/tools": patch | ||
"@rocket.chat/account-service": patch | ||
--- | ||
|
||
Fixed an inconsistent evaluation of the `Accounts_LoginExpiration` setting over the codebase. In some places, it was being used as milliseconds while in others as days. Invalid values produced different results. A helper function was created to centralize the setting validation and the proper value being returned to avoid edge cases. | ||
Negative values may be saved on the settings UI panel but the code will interpret any negative, NaN or 0 value to the default expiration which is 90 days. |
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,3 @@ | ||
export default { | ||
preset: 'ts-jest', | ||
}; |
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,15 @@ | ||
import { convertFromDaysToMilliseconds } from './converter'; | ||
|
||
describe('convertFromDaysToMilliseconds', () => { | ||
it('should throw an error when a non number is passed', () => { | ||
// @ts-expect-error - Testing | ||
expect(() => convertFromDaysToMilliseconds('90')).toThrow(); | ||
}); | ||
it('should return the value passed when its valid', () => { | ||
expect(convertFromDaysToMilliseconds(85)).toBe(85 * 24 * 60 * 60 * 1000); | ||
}); | ||
it('should fail if anything but an integer is passed', () => { | ||
expect(() => convertFromDaysToMilliseconds(85.5)).toThrow(); | ||
expect(() => convertFromDaysToMilliseconds(-2.3)).toThrow(); | ||
}); | ||
}); |
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,7 @@ | ||
export const convertFromDaysToMilliseconds = (days: number) => { | ||
if (typeof days !== 'number' || !Number.isInteger(days)) { | ||
throw new Error('days must be a number'); | ||
} | ||
|
||
return days * 24 * 60 * 60 * 1000; | ||
}; |
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,35 @@ | ||
import { getLoginExpirationInDays, getLoginExpirationInMs } from './getLoginExpiration'; | ||
|
||
describe('getLoginExpirationInDays', () => { | ||
it('should return 90 by default', () => { | ||
expect(getLoginExpirationInDays()).toBe(90); | ||
}); | ||
it('should return 90 when value is 0', () => { | ||
expect(getLoginExpirationInDays(0)).toBe(90); | ||
}); | ||
it('should return 90 when value is NaN', () => { | ||
expect(getLoginExpirationInDays(NaN)).toBe(90); | ||
}); | ||
it('should return 90 when value is negative', () => { | ||
expect(getLoginExpirationInDays(-1)).toBe(90); | ||
}); | ||
it('should return 90 when value is undefined', () => { | ||
expect(getLoginExpirationInDays(undefined)).toBe(90); | ||
}); | ||
it('should return 90 when value is not a number', () => { | ||
// @ts-expect-error - Testing | ||
expect(getLoginExpirationInDays('90')).toBe(90); | ||
}); | ||
it('should return the value passed when its valid', () => { | ||
expect(getLoginExpirationInDays(85)).toBe(85); | ||
}); | ||
}); | ||
|
||
describe('getLoginExpirationInMs', () => { | ||
it('should return 90 days in milliseconds when no value is passed', () => { | ||
expect(getLoginExpirationInMs()).toBe(90 * 24 * 60 * 60 * 1000); | ||
}); | ||
it('should return the value passed when its valid', () => { | ||
expect(getLoginExpirationInMs(85)).toBe(85 * 24 * 60 * 60 * 1000); | ||
}); | ||
}); |
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,16 @@ | ||
import { convertFromDaysToMilliseconds } from './converter'; | ||
|
||
const ACCOUNTS_DEFAULT_LOGIN_EXPIRATION_DAYS = 90; | ||
|
||
// Given a value, validates if it mets the conditions to be a valid login expiration. | ||
// Else, returns the default login expiration (which for Meteor is 90 days) | ||
export const getLoginExpirationInDays = (expiry?: number) => { | ||
if (expiry && typeof expiry === 'number' && !Number.isNaN(expiry) && expiry > 0) { | ||
return expiry; | ||
} | ||
return ACCOUNTS_DEFAULT_LOGIN_EXPIRATION_DAYS; | ||
}; | ||
|
||
export const getLoginExpirationInMs = (expiry?: number) => { | ||
return convertFromDaysToMilliseconds(getLoginExpirationInDays(expiry)); | ||
}; |
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