|
|
@@ -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() {
|