mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-23 02:55:13 -04:00
d8b2537f48
Add security email template and switch institution SSO alerts to use it GitOrigin-RevId: c6f07655165e352527a9efbcfffc5bd2f635405c
73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
const sinon = require('sinon')
|
|
const chai = require('chai')
|
|
const { expect } = chai
|
|
const SandboxedModule = require('sandboxed-module')
|
|
const modulePath =
|
|
'../../../../app/src/Features/User/ThirdPartyIdentityManager.js'
|
|
|
|
describe('ThirdPartyIdentityManager', function() {
|
|
beforeEach(function() {
|
|
this.userId = 'a1b2c3'
|
|
this.user = {
|
|
_id: this.userId,
|
|
email: 'example@overleaf.com'
|
|
}
|
|
this.externalUserId = 'id789'
|
|
this.externalData = {}
|
|
this.ThirdPartyIdentityManager = SandboxedModule.require(modulePath, {
|
|
globals: {
|
|
console: console
|
|
},
|
|
requires: {
|
|
'../../../../app/src/Features/Email/EmailHandler': (this.EmailHandler = {
|
|
sendEmail: sinon.stub().yields()
|
|
}),
|
|
Errors: (this.Errors = {
|
|
ThirdPartyIdentityExistsError: sinon.stub(),
|
|
ThirdPartyUserNotFoundError: sinon.stub()
|
|
}),
|
|
'../../../../app/src/models/User': {
|
|
User: (this.User = {
|
|
findOneAndUpdate: sinon.stub().yields(undefined, this.user),
|
|
findOne: sinon.stub()
|
|
})
|
|
},
|
|
'settings-sharelatex': {
|
|
oauthProviders: {
|
|
google: {
|
|
name: 'Google'
|
|
},
|
|
orcid: {
|
|
name: 'Orcid'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
describe('link', function() {
|
|
it('should send email alert', async function() {
|
|
await this.ThirdPartyIdentityManager.promises.link(
|
|
this.userId,
|
|
'google',
|
|
this.externalUserId,
|
|
this.externalData
|
|
)
|
|
const emailCall = this.EmailHandler.sendEmail.getCall(0)
|
|
expect(emailCall.args[0]).to.equal('securityAlert')
|
|
expect(emailCall.args[1].actionDescribed).to.contain(
|
|
'a Google account was linked'
|
|
)
|
|
})
|
|
})
|
|
describe('unlink', function() {
|
|
it('should send email alert', async function() {
|
|
await this.ThirdPartyIdentityManager.promises.unlink(this.userId, 'orcid')
|
|
const emailCall = this.EmailHandler.sendEmail.getCall(0)
|
|
expect(emailCall.args[0]).to.equal('securityAlert')
|
|
expect(emailCall.args[1].actionDescribed).to.contain(
|
|
'an Orcid account is no longer linked'
|
|
)
|
|
})
|
|
})
|
|
})
|