|
|
@@ -68,7 +68,12 @@ describe('UserUpdater', function() {
|
|
|
'settings-sharelatex': (this.settings = {}),
|
|
|
request: (this.request = {}),
|
|
|
'../Newsletter/NewsletterManager': this.NewsletterManager,
|
|
|
- '../Subscription/RecurlyWrapper': this.RecurlyWrapper
|
|
|
+ '../Subscription/RecurlyWrapper': this.RecurlyWrapper,
|
|
|
+ './UserAuditLogHandler': (this.UserAuditLogHandler = {
|
|
|
+ promises: {
|
|
|
+ addEntry: sinon.stub().resolves()
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -125,6 +130,10 @@ describe('UserUpdater', function() {
|
|
|
|
|
|
describe('changeEmailAddress', function() {
|
|
|
beforeEach(function() {
|
|
|
+ this.auditLog = {
|
|
|
+ initiatorId: 'abc123',
|
|
|
+ ipAddress: '0:0:0:0'
|
|
|
+ }
|
|
|
this.UserGetter.getUserEmail.callsArgWith(1, null, this.stubbedUser.email)
|
|
|
this.UserUpdater.addEmailAddress = sinon.stub().callsArgWith(2)
|
|
|
this.UserUpdater.setDefaultEmailAddress = sinon.stub().yields()
|
|
|
@@ -135,6 +144,7 @@ describe('UserUpdater', function() {
|
|
|
this.UserUpdater.changeEmailAddress(
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
+ this.auditLog,
|
|
|
err => {
|
|
|
should.not.exist(err)
|
|
|
this.UserUpdater.addEmailAddress
|
|
|
@@ -152,10 +162,15 @@ describe('UserUpdater', function() {
|
|
|
})
|
|
|
|
|
|
it('validates email', function(done) {
|
|
|
- this.UserUpdater.changeEmailAddress(this.stubbedUser._id, 'foo', err => {
|
|
|
- should.exist(err)
|
|
|
- done()
|
|
|
- })
|
|
|
+ this.UserUpdater.changeEmailAddress(
|
|
|
+ this.stubbedUser._id,
|
|
|
+ 'foo',
|
|
|
+ this.auditLog,
|
|
|
+ err => {
|
|
|
+ should.exist(err)
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
})
|
|
|
|
|
|
it('handle error', function(done) {
|
|
|
@@ -163,6 +178,7 @@ describe('UserUpdater', function() {
|
|
|
this.UserUpdater.changeEmailAddress(
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
+ this.auditLog,
|
|
|
err => {
|
|
|
should.exist(err)
|
|
|
done()
|
|
|
@@ -350,6 +366,10 @@ describe('UserUpdater', function() {
|
|
|
|
|
|
describe('setDefaultEmailAddress', function() {
|
|
|
beforeEach(function() {
|
|
|
+ this.auditLog = {
|
|
|
+ initiatorId: this.stubbedUser,
|
|
|
+ ipAddress: '0:0:0:0'
|
|
|
+ }
|
|
|
this.stubbedUser.emails = [
|
|
|
{
|
|
|
email: this.newEmail,
|
|
|
@@ -368,6 +388,7 @@ describe('UserUpdater', function() {
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
false,
|
|
|
+ this.auditLog,
|
|
|
err => {
|
|
|
should.not.exist(err)
|
|
|
this.UserUpdater.promises.updateUser
|
|
|
@@ -388,6 +409,7 @@ describe('UserUpdater', function() {
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
false,
|
|
|
+ this.auditLog,
|
|
|
err => {
|
|
|
should.not.exist(err)
|
|
|
this.NewsletterManager.promises.changeEmail
|
|
|
@@ -408,6 +430,7 @@ describe('UserUpdater', function() {
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
false,
|
|
|
+ this.auditLog,
|
|
|
err => {
|
|
|
should.exist(err)
|
|
|
done()
|
|
|
@@ -422,6 +445,7 @@ describe('UserUpdater', function() {
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
false,
|
|
|
+ this.auditLog,
|
|
|
err => {
|
|
|
should.exist(err)
|
|
|
done()
|
|
|
@@ -434,6 +458,7 @@ describe('UserUpdater', function() {
|
|
|
this.stubbedUser._id,
|
|
|
'.edu',
|
|
|
false,
|
|
|
+ this.auditLog,
|
|
|
err => {
|
|
|
should.exist(err)
|
|
|
done()
|
|
|
@@ -441,6 +466,49 @@ describe('UserUpdater', function() {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
+ it('updates audit log', function(done) {
|
|
|
+ this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
|
|
+
|
|
|
+ this.UserUpdater.setDefaultEmailAddress(
|
|
|
+ this.stubbedUser._id,
|
|
|
+ this.newEmail,
|
|
|
+ false,
|
|
|
+ this.auditLog,
|
|
|
+ error => {
|
|
|
+ expect(error).to.not.exist
|
|
|
+ expect(
|
|
|
+ this.UserAuditLogHandler.promises.addEntry
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.stubbedUser._id,
|
|
|
+ 'change-primary-email',
|
|
|
+ this.auditLog.initiatorId,
|
|
|
+ this.auditLog.ipAddress,
|
|
|
+ {
|
|
|
+ newPrimaryEmail: this.newEmail,
|
|
|
+ oldPrimaryEmail: this.stubbedUser.email
|
|
|
+ }
|
|
|
+ )
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('blocks email update if audit log returns an error', function(done) {
|
|
|
+ this.UserUpdater.promises.updateUser = sinon.stub()
|
|
|
+ this.UserAuditLogHandler.promises.addEntry.rejects(new Error('oops'))
|
|
|
+ this.UserUpdater.setDefaultEmailAddress(
|
|
|
+ this.stubbedUser._id,
|
|
|
+ this.newEmail,
|
|
|
+ false,
|
|
|
+ this.auditLog,
|
|
|
+ error => {
|
|
|
+ expect(error).to.exist
|
|
|
+ expect(this.UserUpdater.promises.updateUser).to.not.have.been.called
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
describe('when email not confirmed', function() {
|
|
|
beforeEach(function() {
|
|
|
this.stubbedUser.emails = [
|
|
|
@@ -457,6 +525,7 @@ describe('UserUpdater', function() {
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
false,
|
|
|
+ this.auditLog,
|
|
|
error => {
|
|
|
expect(error).to.exist
|
|
|
expect(error.name).to.equal('UnconfirmedEmailError')
|
|
|
@@ -481,6 +550,7 @@ describe('UserUpdater', function() {
|
|
|
this.stubbedUser._id,
|
|
|
this.newEmail,
|
|
|
false,
|
|
|
+ this.auditLog,
|
|
|
error => {
|
|
|
expect(error).to.exist
|
|
|
expect(error.name).to.equal('Error')
|