-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Option to disable 2FA for OAuth users (#32945)
- Loading branch information
1 parent
4146c39
commit 0f21fa0
Showing
12 changed files
with
217 additions
and
75 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,6 @@ | ||
--- | ||
'@rocket.chat/i18n': minor | ||
'@rocket.chat/meteor': minor | ||
--- | ||
|
||
Added a new setting which allows workspace admins to disable email two factor authentication for SSO (OAuth) users. If enabled, SSO users won't be asked for email two factor authentication. |
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,70 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import proxyquire from 'proxyquire'; | ||
import sinon from 'sinon'; | ||
|
||
const settingsMock = sinon.stub(); | ||
|
||
const { EmailCheck } = proxyquire.noCallThru().load('./EmailCheck', { | ||
'@rocket.chat/models': { | ||
Users: {}, | ||
}, | ||
'meteor/accounts-base': { | ||
Accounts: { | ||
_bcryptRounds: () => '123', | ||
}, | ||
}, | ||
'../../../../server/lib/i18n': { | ||
i18n: { | ||
t: (key: string) => key, | ||
}, | ||
}, | ||
'../../../mailer/server/api': { | ||
send: () => undefined, | ||
}, | ||
'../../../settings/server': { | ||
settings: { | ||
get: settingsMock, | ||
}, | ||
}, | ||
}); | ||
|
||
const normalUserMock = { services: { email2fa: { enabled: true } }, emails: [{ email: 'abc@gmail.com', verified: true }] }; | ||
const normalUserWithUnverifiedEmailMock = { | ||
services: { email2fa: { enabled: true } }, | ||
emails: [{ email: 'abc@gmail.com', verified: false }], | ||
}; | ||
const OAuthUserMock = { services: { google: {} }, emails: [{ email: 'abc@gmail.com', verified: true }] }; | ||
|
||
describe('EmailCheck', () => { | ||
let emailCheck: typeof EmailCheck; | ||
beforeEach(() => { | ||
settingsMock.reset(); | ||
|
||
emailCheck = new EmailCheck(); | ||
}); | ||
|
||
it('should return EmailCheck is enabled for a normal user', () => { | ||
settingsMock.returns(true); | ||
|
||
const isEmail2FAEnabled = emailCheck.isEnabled(normalUserMock); | ||
|
||
expect(isEmail2FAEnabled).to.be.equal(true); | ||
}); | ||
|
||
it('should return EmailCheck is not enabled for a normal user with unverified email', () => { | ||
settingsMock.returns(true); | ||
|
||
const isEmail2FAEnabled = emailCheck.isEnabled(normalUserWithUnverifiedEmailMock); | ||
|
||
expect(isEmail2FAEnabled).to.be.equal(false); | ||
}); | ||
|
||
it('should return EmailCheck is not enabled for a OAuth user with setting being false', () => { | ||
settingsMock.returns(true); | ||
|
||
const isEmail2FAEnabled = emailCheck.isEnabled(OAuthUserMock); | ||
|
||
expect(isEmail2FAEnabled).to.be.equal(false); | ||
}); | ||
}); |
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
34 changes: 34 additions & 0 deletions
34
apps/meteor/app/utils/server/functions/getBaseUserFields.ts
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,34 @@ | ||
type UserFields = { | ||
[k: string]: number; | ||
}; | ||
|
||
export const getBaseUserFields = (): UserFields => ({ | ||
'name': 1, | ||
'username': 1, | ||
'nickname': 1, | ||
'emails': 1, | ||
'status': 1, | ||
'statusDefault': 1, | ||
'statusText': 1, | ||
'statusConnection': 1, | ||
'bio': 1, | ||
'avatarOrigin': 1, | ||
'utcOffset': 1, | ||
'language': 1, | ||
'settings': 1, | ||
'enableAutoAway': 1, | ||
'idleTimeLimit': 1, | ||
'roles': 1, | ||
'active': 1, | ||
'defaultRoom': 1, | ||
'customFields': 1, | ||
'requirePasswordChange': 1, | ||
'requirePasswordChangeReason': 1, | ||
'statusLivechat': 1, | ||
'banners': 1, | ||
'oauth.authorizedClients': 1, | ||
'_updatedAt': 1, | ||
'avatarETag': 1, | ||
'extension': 1, | ||
'openBusinessHours': 1, | ||
}); |
35 changes: 5 additions & 30 deletions
35
apps/meteor/app/utils/server/functions/getDefaultUserFields.ts
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 |
---|---|---|
@@ -1,39 +1,14 @@ | ||
type DefaultUserFields = { | ||
import { getBaseUserFields } from './getBaseUserFields'; | ||
|
||
type UserFields = { | ||
[k: string]: number; | ||
}; | ||
|
||
export const getDefaultUserFields = (): DefaultUserFields => ({ | ||
'name': 1, | ||
'username': 1, | ||
'nickname': 1, | ||
'emails': 1, | ||
'status': 1, | ||
'statusDefault': 1, | ||
'statusText': 1, | ||
'statusConnection': 1, | ||
'bio': 1, | ||
'avatarOrigin': 1, | ||
'utcOffset': 1, | ||
'language': 1, | ||
'settings': 1, | ||
'enableAutoAway': 1, | ||
'idleTimeLimit': 1, | ||
'roles': 1, | ||
'active': 1, | ||
'defaultRoom': 1, | ||
'customFields': 1, | ||
'requirePasswordChange': 1, | ||
'requirePasswordChangeReason': 1, | ||
export const getDefaultUserFields = (): UserFields => ({ | ||
...getBaseUserFields(), | ||
'services.github': 1, | ||
'services.gitlab': 1, | ||
'services.password.bcrypt': 1, | ||
'services.totp.enabled': 1, | ||
'services.email2fa.enabled': 1, | ||
'statusLivechat': 1, | ||
'banners': 1, | ||
'oauth.authorizedClients': 1, | ||
'_updatedAt': 1, | ||
'avatarETag': 1, | ||
'extension': 1, | ||
'openBusinessHours': 1, | ||
}); |
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
Oops, something went wrong.