From 684cb3903c45127f8ca687b687b46b0aded03357 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 12 May 2020 12:45:46 +0200 Subject: [PATCH] [WebsocketController] handle redis subscribe error on joinProject joinProject should not complete when the redis pub/sub subscribe request failed. --- .../app/coffee/WebsocketController.coffee | 1 + .../coffee/WebsocketControllerTests.coffee | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/services/real-time/app/coffee/WebsocketController.coffee b/services/real-time/app/coffee/WebsocketController.coffee index 786a77d114..e9017b05b9 100644 --- a/services/real-time/app/coffee/WebsocketController.coffee +++ b/services/real-time/app/coffee/WebsocketController.coffee @@ -40,6 +40,7 @@ module.exports = WebsocketController = client.set("is_restricted_user", !!(isRestrictedUser)) RoomManager.joinProject client, project_id, (err) -> + return callback(err) if err logger.log {user_id, project_id, client_id: client.id}, "user joined project" callback null, project, privilegeLevel, WebsocketController.PROTOCOL_VERSION diff --git a/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee b/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee index 62243f797c..c6d29d5715 100644 --- a/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee +++ b/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee @@ -125,6 +125,28 @@ describe 'WebsocketController', -> it "should not log an error", -> @logger.error.called.should.equal false + describe "when the subscribe failed", -> + beforeEach -> + @client.id = "mock-client-id" + @project = { + name: "Test Project" + owner: { + _id: @owner_id = "mock-owner-id-123" + } + } + @privilegeLevel = "owner" + @ConnectedUsersManager.updateUserPosition = sinon.stub().callsArg(4) + @isRestrictedUser = true + @WebApiManager.joinProject = sinon.stub().callsArgWith(2, null, @project, @privilegeLevel, @isRestrictedUser) + @RoomManager.joinProject = sinon.stub().callsArgWith(2, new Error("subscribe failed")) + @WebsocketController.joinProject @client, @user, @project_id, @callback + + it "should return an error", -> + @callback + .calledWith(new Error("subscribe failed")) + .should.equal true + @callback.args[0][0].message.should.equal "subscribe failed" + describe "leaveProject", -> beforeEach -> @DocumentUpdaterManager.flushProjectToMongoAndDelete = sinon.stub().callsArg(1)