-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Do not return
inviteAcceptUrl
in response if email was s…
…ent (#7465)
- Loading branch information
Showing
11 changed files
with
74 additions
and
102 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
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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import { compare } from 'bcryptjs'; | ||
import { Container } from 'typedi'; | ||
import { License } from '@/License'; | ||
|
||
import * as Db from '@/Db'; | ||
import config from '@/config'; | ||
import type { Role } from '@db/entities/Role'; | ||
import type { User } from '@db/entities/User'; | ||
import { setCurrentAuthenticationMethod } from '@/sso/ssoHelpers'; | ||
import { ExternalHooks } from '@/ExternalHooks'; | ||
import { JwtService } from '@/services/jwt.service'; | ||
import { UserManagementMailer } from '@/UserManagement/email'; | ||
|
||
import * as utils from './shared/utils/'; | ||
import { | ||
randomEmail, | ||
|
@@ -15,12 +21,7 @@ import { | |
randomValidPassword, | ||
} from './shared/random'; | ||
import * as testDb from './shared/testDb'; | ||
import { setCurrentAuthenticationMethod } from '@/sso/ssoHelpers'; | ||
import { ExternalHooks } from '@/ExternalHooks'; | ||
import { JwtService } from '@/services/jwt.service'; | ||
import { Container } from 'typedi'; | ||
|
||
jest.mock('@/UserManagement/email/NodeMailer'); | ||
config.set('userManagement.jwtSecret', randomString(5, 10)); | ||
|
||
let globalOwnerRole: Role; | ||
|
@@ -29,6 +30,7 @@ let owner: User; | |
let member: User; | ||
|
||
const externalHooks = utils.mockInstance(ExternalHooks); | ||
const mailer = utils.mockInstance(UserManagementMailer, { isEmailSetUp: true }); | ||
const testServer = utils.setupTestServer({ endpointGroups: ['passwordReset'] }); | ||
const jwtService = Container.get(JwtService); | ||
|
||
|
@@ -43,6 +45,7 @@ beforeEach(async () => { | |
owner = await testDb.createUser({ globalRole: globalOwnerRole }); | ||
member = await testDb.createUser({ globalRole: globalMemberRole }); | ||
externalHooks.run.mockReset(); | ||
jest.replaceProperty(mailer, 'isEmailSetUp', true); | ||
}); | ||
|
||
describe('POST /forgot-password', () => { | ||
|
@@ -52,8 +55,6 @@ describe('POST /forgot-password', () => { | |
globalRole: globalMemberRole, | ||
}); | ||
|
||
config.set('userManagement.emails.mode', 'smtp'); | ||
|
||
await Promise.all( | ||
[{ email: owner.email }, { email: member.email.toUpperCase() }].map(async (payload) => { | ||
const response = await testServer.authlessAgent.post('/forgot-password').send(payload); | ||
|
@@ -65,7 +66,7 @@ describe('POST /forgot-password', () => { | |
}); | ||
|
||
test('should fail if emailing is not set up', async () => { | ||
config.set('userManagement.emails.mode', ''); | ||
jest.replaceProperty(mailer, 'isEmailSetUp', false); | ||
|
||
await testServer.authlessAgent | ||
.post('/forgot-password') | ||
|
@@ -75,7 +76,6 @@ describe('POST /forgot-password', () => { | |
|
||
test('should fail if SAML is authentication method', async () => { | ||
await setCurrentAuthenticationMethod('saml'); | ||
config.set('userManagement.emails.mode', 'smtp'); | ||
const member = await testDb.createUser({ | ||
email: '[email protected]', | ||
globalRole: globalMemberRole, | ||
|
@@ -91,7 +91,6 @@ describe('POST /forgot-password', () => { | |
|
||
test('should succeed if SAML is authentication method and requestor is owner', async () => { | ||
await setCurrentAuthenticationMethod('saml'); | ||
config.set('userManagement.emails.mode', 'smtp'); | ||
|
||
const response = await testServer.authlessAgent | ||
.post('/forgot-password') | ||
|
@@ -104,8 +103,6 @@ describe('POST /forgot-password', () => { | |
}); | ||
|
||
test('should fail with invalid inputs', async () => { | ||
config.set('userManagement.emails.mode', 'smtp'); | ||
|
||
const invalidPayloads = [ | ||
randomEmail(), | ||
[randomEmail()], | ||
|
@@ -121,8 +118,6 @@ describe('POST /forgot-password', () => { | |
}); | ||
|
||
test('should fail if user is not found', async () => { | ||
config.set('userManagement.emails.mode', 'smtp'); | ||
|
||
const response = await testServer.authlessAgent | ||
.post('/forgot-password') | ||
.send({ email: randomEmail() }); | ||
|
@@ -132,10 +127,6 @@ describe('POST /forgot-password', () => { | |
}); | ||
|
||
describe('GET /resolve-password-token', () => { | ||
beforeEach(() => { | ||
config.set('userManagement.emails.mode', 'smtp'); | ||
}); | ||
|
||
test('should succeed with valid inputs', async () => { | ||
const resetPasswordToken = jwtService.signData({ sub: owner.id }); | ||
|
||
|
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.