|
|
@@ -123,6 +123,12 @@ describe('TokenAccessController', function () {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+ this.LimitationsManager = {
|
|
|
+ promises: {
|
|
|
+ canAcceptEditCollaboratorInvite: sinon.stub().resolves(),
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
this.TokenAccessController = SandboxedModule.require(MODULE_PATH, {
|
|
|
requires: {
|
|
|
'@overleaf/settings': this.Settings,
|
|
|
@@ -145,6 +151,7 @@ describe('TokenAccessController', function () {
|
|
|
}),
|
|
|
'../Analytics/AnalyticsManager': this.AnalyticsManager,
|
|
|
'../User/UserGetter': this.UserGetter,
|
|
|
+ '../Subscription/LimitationsManager': this.LimitationsManager,
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -195,9 +202,13 @@ describe('TokenAccessController', function () {
|
|
|
|
|
|
describe('when project owner in link-sharing-warning split test', function () {
|
|
|
beforeEach(function () {
|
|
|
- this.SplitTestHandler.promises.getAssignmentForUser.resolves({
|
|
|
- variant: 'active',
|
|
|
- })
|
|
|
+ this.SplitTestHandler.promises.getAssignmentForUser.callsFake(
|
|
|
+ async (userId, test) => {
|
|
|
+ if (test === 'link-sharing-warning') {
|
|
|
+ return { variant: 'active' }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
})
|
|
|
|
|
|
it('tells the ui to show the link-sharing-warning variant', async function () {
|
|
|
@@ -284,6 +295,168 @@ describe('TokenAccessController', function () {
|
|
|
)
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe('when the project owner is in the link-sharing-enforcement split test', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.SplitTestHandler.promises.getAssignmentForUser.callsFake(
|
|
|
+ async (userId, test) => {
|
|
|
+ if (test === 'link-sharing-warning') {
|
|
|
+ return { variant: 'active' }
|
|
|
+ } else if (test === 'link-sharing-enforcement') {
|
|
|
+ return { variant: 'active' }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('normal case (edit slot available)', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.LimitationsManager.promises.canAcceptEditCollaboratorInvite.resolves(
|
|
|
+ true
|
|
|
+ )
|
|
|
+ this.req.params = { token: this.token }
|
|
|
+ this.req.body = {
|
|
|
+ confirmedByUser: true,
|
|
|
+ tokenHashPrefix: '#prefix',
|
|
|
+ }
|
|
|
+ this.res.callback = done
|
|
|
+ this.TokenAccessController.grantTokenAccessReadAndWrite(
|
|
|
+ this.req,
|
|
|
+ this.res,
|
|
|
+ done
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('adds the user as a read and write invited member', function () {
|
|
|
+ expect(
|
|
|
+ this.CollaboratorsHandler.promises.addUserIdToProject
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ undefined,
|
|
|
+ this.user._id,
|
|
|
+ PrivilegeLevels.READ_AND_WRITE
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('writes a project audit log', function () {
|
|
|
+ expect(
|
|
|
+ this.ProjectAuditLogHandler.promises.addEntry
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ 'accept-via-link-sharing',
|
|
|
+ this.user._id,
|
|
|
+ this.req.ip,
|
|
|
+ { privileges: 'readAndWrite' }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('records a project-joined event for the user', function () {
|
|
|
+ expect(
|
|
|
+ this.AnalyticsManager.recordEventForUserInBackground
|
|
|
+ ).to.have.been.calledWith(this.user._id, 'project-joined', {
|
|
|
+ mode: 'read-write',
|
|
|
+ projectId: this.project._id.toString(),
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('emits a project membership changed event', function () {
|
|
|
+ expect(
|
|
|
+ this.EditorRealTimeController.emitToRoom
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ 'project:membership:changed',
|
|
|
+ { members: true }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('checks token hash', function () {
|
|
|
+ expect(
|
|
|
+ this.TokenAccessHandler.checkTokenHashPrefix
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.token,
|
|
|
+ '#prefix',
|
|
|
+ 'readAndWrite',
|
|
|
+ this.user._id,
|
|
|
+ { projectId: this.project._id, action: 'continue' }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('when there are no edit collaborator slots available', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.LimitationsManager.promises.canAcceptEditCollaboratorInvite.resolves(
|
|
|
+ false
|
|
|
+ )
|
|
|
+ this.req.params = { token: this.token }
|
|
|
+ this.req.body = {
|
|
|
+ confirmedByUser: true,
|
|
|
+ tokenHashPrefix: '#prefix',
|
|
|
+ }
|
|
|
+ this.res.callback = done
|
|
|
+ this.TokenAccessController.grantTokenAccessReadAndWrite(
|
|
|
+ this.req,
|
|
|
+ this.res,
|
|
|
+ done
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('adds the user as a read only invited member instead (pendingEditor)', function () {
|
|
|
+ expect(
|
|
|
+ this.CollaboratorsHandler.promises.addUserIdToProject
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ undefined,
|
|
|
+ this.user._id,
|
|
|
+ PrivilegeLevels.READ_ONLY,
|
|
|
+ { pendingEditor: true }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('writes a project audit log', function () {
|
|
|
+ expect(
|
|
|
+ this.ProjectAuditLogHandler.promises.addEntry
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ 'accept-via-link-sharing',
|
|
|
+ this.user._id,
|
|
|
+ this.req.ip,
|
|
|
+ { privileges: 'readOnly', pendingEditor: true }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('records a project-joined event for the user', function () {
|
|
|
+ expect(
|
|
|
+ this.AnalyticsManager.recordEventForUserInBackground
|
|
|
+ ).to.have.been.calledWith(this.user._id, 'project-joined', {
|
|
|
+ mode: 'read-only',
|
|
|
+ projectId: this.project._id.toString(),
|
|
|
+ pendingEditor: true,
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('emits a project membership changed event', function () {
|
|
|
+ expect(
|
|
|
+ this.EditorRealTimeController.emitToRoom
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ 'project:membership:changed',
|
|
|
+ { members: true }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('checks token hash', function () {
|
|
|
+ expect(
|
|
|
+ this.TokenAccessHandler.checkTokenHashPrefix
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.token,
|
|
|
+ '#prefix',
|
|
|
+ 'readAndWrite',
|
|
|
+ this.user._id,
|
|
|
+ { projectId: this.project._id, action: 'continue' }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('when the access was already granted', function () {
|
|
|
@@ -994,6 +1167,89 @@ describe('TokenAccessController', function () {
|
|
|
expect(this.res.sendStatus).to.have.been.calledWith(204)
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe('when link-sharing-enforcement test is active', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.SplitTestHandler.promises.getAssignmentForUser.resolves({
|
|
|
+ variant: 'active',
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('when there are collaborator slots available', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.LimitationsManager.promises.canAcceptEditCollaboratorInvite.resolves(
|
|
|
+ true
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('previously joined token access user moving to named collaborator', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.CollaboratorsGetter.promises.isUserInvitedMemberOfProject.resolves(
|
|
|
+ false
|
|
|
+ )
|
|
|
+ this.res.callback = done
|
|
|
+ this.TokenAccessController.moveReadWriteToCollaborators(
|
|
|
+ this.req,
|
|
|
+ this.res,
|
|
|
+ done
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('sets the privilege level to read and write for the invited viewer', function () {
|
|
|
+ expect(
|
|
|
+ this.TokenAccessHandler.promises.removeReadAndWriteUserFromProject
|
|
|
+ ).to.have.been.calledWith(this.user._id, this.project._id)
|
|
|
+ expect(
|
|
|
+ this.CollaboratorsHandler.promises.addUserIdToProject
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ undefined,
|
|
|
+ this.user._id,
|
|
|
+ PrivilegeLevels.READ_AND_WRITE
|
|
|
+ )
|
|
|
+ expect(this.res.sendStatus).to.have.been.calledWith(204)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('when there are no edit collaborator slots available', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.LimitationsManager.promises.canAcceptEditCollaboratorInvite.resolves(
|
|
|
+ false
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('previously joined token access user moving to named collaborator', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ this.CollaboratorsGetter.promises.isUserInvitedMemberOfProject.resolves(
|
|
|
+ false
|
|
|
+ )
|
|
|
+ this.res.callback = done
|
|
|
+ this.TokenAccessController.moveReadWriteToCollaborators(
|
|
|
+ this.req,
|
|
|
+ this.res,
|
|
|
+ done
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('sets the privilege level to read only for the invited viewer (pendingEditor)', function () {
|
|
|
+ expect(
|
|
|
+ this.TokenAccessHandler.promises.removeReadAndWriteUserFromProject
|
|
|
+ ).to.have.been.calledWith(this.user._id, this.project._id)
|
|
|
+ expect(
|
|
|
+ this.CollaboratorsHandler.promises.addUserIdToProject
|
|
|
+ ).to.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ undefined,
|
|
|
+ this.user._id,
|
|
|
+ PrivilegeLevels.READ_ONLY,
|
|
|
+ { pendingEditor: true }
|
|
|
+ )
|
|
|
+ expect(this.res.sendStatus).to.have.been.calledWith(204)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('moveReadWriteToReadOnly', function () {
|