|
@@ -14,11 +14,15 @@ describe('ThirdPartyIdentityManager', function() {
|
|
|
}
|
|
}
|
|
|
this.externalUserId = 'id789'
|
|
this.externalUserId = 'id789'
|
|
|
this.externalData = {}
|
|
this.externalData = {}
|
|
|
|
|
+ this.auditLog = { initiatorId: this.userId, ipAddress: '0:0:0:0' }
|
|
|
this.ThirdPartyIdentityManager = SandboxedModule.require(modulePath, {
|
|
this.ThirdPartyIdentityManager = SandboxedModule.require(modulePath, {
|
|
|
globals: {
|
|
globals: {
|
|
|
console: console
|
|
console: console
|
|
|
},
|
|
},
|
|
|
requires: {
|
|
requires: {
|
|
|
|
|
+ '../../../../app/src/Features/User/UserAuditLogHandler': (this.UserAuditLogHandler = {
|
|
|
|
|
+ addEntry: sinon.stub().yields()
|
|
|
|
|
+ }),
|
|
|
'../../../../app/src/Features/Email/EmailHandler': (this.EmailHandler = {
|
|
'../../../../app/src/Features/Email/EmailHandler': (this.EmailHandler = {
|
|
|
sendEmail: sinon.stub().yields()
|
|
sendEmail: sinon.stub().yields()
|
|
|
}),
|
|
}),
|
|
@@ -54,7 +58,8 @@ describe('ThirdPartyIdentityManager', function() {
|
|
|
this.userId,
|
|
this.userId,
|
|
|
'google',
|
|
'google',
|
|
|
this.externalUserId,
|
|
this.externalUserId,
|
|
|
- this.externalData
|
|
|
|
|
|
|
+ this.externalData,
|
|
|
|
|
+ this.auditLog
|
|
|
)
|
|
)
|
|
|
const emailCall = this.EmailHandler.sendEmail.getCall(0)
|
|
const emailCall = this.EmailHandler.sendEmail.getCall(0)
|
|
|
expect(emailCall.args[0]).to.equal('securityAlert')
|
|
expect(emailCall.args[0]).to.equal('securityAlert')
|
|
@@ -62,8 +67,43 @@ describe('ThirdPartyIdentityManager', function() {
|
|
|
'a Google account was linked'
|
|
'a Google account was linked'
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ it('should update user audit log', async function() {
|
|
|
|
|
+ await this.ThirdPartyIdentityManager.promises.link(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ 'google',
|
|
|
|
|
+ this.externalUserId,
|
|
|
|
|
+ this.externalData,
|
|
|
|
|
+ this.auditLog
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(this.UserAuditLogHandler.addEntry).to.have.been.calledOnceWith(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ 'link-sso',
|
|
|
|
|
+ this.auditLog.initiatorId,
|
|
|
|
|
+ this.auditLog.ipAddress,
|
|
|
|
|
+ {
|
|
|
|
|
+ providerId: 'google'
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
describe('errors', function() {
|
|
describe('errors', function() {
|
|
|
const anError = new Error('oops')
|
|
const anError = new Error('oops')
|
|
|
|
|
+ it('should not unlink if the UserAuditLogHandler throws an error', function(done) {
|
|
|
|
|
+ this.UserAuditLogHandler.addEntry.yields(anError)
|
|
|
|
|
+ this.ThirdPartyIdentityManager.link(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ 'google',
|
|
|
|
|
+ this.externalUserId,
|
|
|
|
|
+ this.externalData,
|
|
|
|
|
+ this.auditLog,
|
|
|
|
|
+ error => {
|
|
|
|
|
+ expect(error).to.exist
|
|
|
|
|
+ expect(error).to.equal(anError)
|
|
|
|
|
+ expect(this.User.findOneAndUpdate).to.not.have.been.called
|
|
|
|
|
+ done()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
describe('EmailHandler', function() {
|
|
describe('EmailHandler', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
this.EmailHandler.sendEmail.yields(anError)
|
|
this.EmailHandler.sendEmail.yields(anError)
|
|
@@ -74,6 +114,7 @@ describe('ThirdPartyIdentityManager', function() {
|
|
|
'google',
|
|
'google',
|
|
|
this.externalUserId,
|
|
this.externalUserId,
|
|
|
this.externalData,
|
|
this.externalData,
|
|
|
|
|
+ this.auditLog,
|
|
|
error => {
|
|
error => {
|
|
|
expect(error).to.not.exist
|
|
expect(error).to.not.exist
|
|
|
const loggerCall = this.logger.error.getCall(0)
|
|
const loggerCall = this.logger.error.getCall(0)
|
|
@@ -93,15 +134,50 @@ describe('ThirdPartyIdentityManager', function() {
|
|
|
})
|
|
})
|
|
|
describe('unlink', function() {
|
|
describe('unlink', function() {
|
|
|
it('should send email alert', async function() {
|
|
it('should send email alert', async function() {
|
|
|
- await this.ThirdPartyIdentityManager.promises.unlink(this.userId, 'orcid')
|
|
|
|
|
|
|
+ await this.ThirdPartyIdentityManager.promises.unlink(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ 'orcid',
|
|
|
|
|
+ this.auditLog
|
|
|
|
|
+ )
|
|
|
const emailCall = this.EmailHandler.sendEmail.getCall(0)
|
|
const emailCall = this.EmailHandler.sendEmail.getCall(0)
|
|
|
expect(emailCall.args[0]).to.equal('securityAlert')
|
|
expect(emailCall.args[0]).to.equal('securityAlert')
|
|
|
expect(emailCall.args[1].actionDescribed).to.contain(
|
|
expect(emailCall.args[1].actionDescribed).to.contain(
|
|
|
'an Orcid account is no longer linked'
|
|
'an Orcid account is no longer linked'
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
+ it('should update user audit log', async function() {
|
|
|
|
|
+ await this.ThirdPartyIdentityManager.promises.unlink(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ 'orcid',
|
|
|
|
|
+ this.auditLog
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(this.UserAuditLogHandler.addEntry).to.have.been.calledOnceWith(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ 'unlink-sso',
|
|
|
|
|
+ this.auditLog.initiatorId,
|
|
|
|
|
+ this.auditLog.ipAddress,
|
|
|
|
|
+ {
|
|
|
|
|
+ providerId: 'orcid'
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
describe('errors', function() {
|
|
describe('errors', function() {
|
|
|
const anError = new Error('oops')
|
|
const anError = new Error('oops')
|
|
|
|
|
+ it('should not unlink if the UserAuditLogHandler throws an error', function(done) {
|
|
|
|
|
+ this.UserAuditLogHandler.addEntry.yields(anError)
|
|
|
|
|
+ this.ThirdPartyIdentityManager.unlink(
|
|
|
|
|
+ this.userId,
|
|
|
|
|
+ 'orcid',
|
|
|
|
|
+ this.auditLog,
|
|
|
|
|
+ error => {
|
|
|
|
|
+ expect(error).to.exist
|
|
|
|
|
+ expect(error).to.equal(anError)
|
|
|
|
|
+ expect(this.User.findOneAndUpdate).to.not.have.been.called
|
|
|
|
|
+ done()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(this.User.findOneAndUpdate).to.not.have.been.called
|
|
|
|
|
+ })
|
|
|
describe('EmailHandler', function() {
|
|
describe('EmailHandler', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
this.EmailHandler.sendEmail.yields(anError)
|
|
this.EmailHandler.sendEmail.yields(anError)
|
|
@@ -110,6 +186,7 @@ describe('ThirdPartyIdentityManager', function() {
|
|
|
this.ThirdPartyIdentityManager.unlink(
|
|
this.ThirdPartyIdentityManager.unlink(
|
|
|
this.userId,
|
|
this.userId,
|
|
|
'google',
|
|
'google',
|
|
|
|
|
+ this.auditLog,
|
|
|
error => {
|
|
error => {
|
|
|
expect(error).to.not.exist
|
|
expect(error).to.not.exist
|
|
|
const loggerCall = this.logger.error.getCall(0)
|
|
const loggerCall = this.logger.error.getCall(0)
|