Merge pull request #2219 from overleaf/jel-institution-email-already-exists
Check for email before adding institution identifier GitOrigin-RevId: 71f498116c8c8df2c3c1a33eafce3e56c87e7ee0
This commit is contained in:
committed by
sharelatex
parent
ed7b5a9450
commit
526d4982a1
@@ -7,6 +7,7 @@ const modulePath = '../../../../app/src/Features/User/SAMLIdentityManager.js'
|
||||
describe('SAMLIdentityManager', function() {
|
||||
beforeEach(function() {
|
||||
this.Errors = {
|
||||
EmailExistsError: sinon.stub(),
|
||||
NotFoundError: sinon.stub(),
|
||||
SAMLIdentityExistsError: sinon.stub(),
|
||||
SAMLUserNotFoundError: sinon.stub()
|
||||
@@ -35,6 +36,7 @@ describe('SAMLIdentityManager', function() {
|
||||
'../Errors/Errors': this.Errors,
|
||||
'../../models/User': {
|
||||
User: (this.User = {
|
||||
findOneAndUpdate: sinon.stub(),
|
||||
findOne: sinon.stub(this.user),
|
||||
update: sinon.stub().returns({
|
||||
exec: sinon.stub().resolves()
|
||||
@@ -44,7 +46,8 @@ describe('SAMLIdentityManager', function() {
|
||||
'../User/UserGetter': (this.UserGetter = {
|
||||
getUser: sinon.stub(),
|
||||
promises: {
|
||||
getUser: sinon.stub().resolves(this.user)
|
||||
getUser: sinon.stub().resolves(this.user),
|
||||
getUserByAnyEmail: sinon.stub().resolves()
|
||||
}
|
||||
}),
|
||||
'../User/UserUpdater': (this.UserUpdater = {
|
||||
@@ -76,6 +79,30 @@ describe('SAMLIdentityManager', function() {
|
||||
expect(error).to.exist
|
||||
}
|
||||
})
|
||||
describe('when email is already associated with another Overleaf account', function() {
|
||||
beforeEach(function() {
|
||||
this.UserGetter.promises.getUserByAnyEmail.resolves({
|
||||
user_id: 'user-id-2'
|
||||
})
|
||||
})
|
||||
it('should throw an error if email is associated with another account', async function() {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.linkAccounts(
|
||||
'user-id-1',
|
||||
'2',
|
||||
'overleaf',
|
||||
true,
|
||||
'test@overleaf.com'
|
||||
)
|
||||
} catch (e) {
|
||||
error = e
|
||||
} finally {
|
||||
expect(error).to.exist
|
||||
expect(this.User.findOneAndUpdate).to.not.have.been.called
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('unlinkAccounts', function() {
|
||||
it('should send an email notification email', function() {
|
||||
|
||||
Reference in New Issue
Block a user