From 3aa2bf8a76bc84876b888e69ea1c595d5c4790c9 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 3 Jul 2019 16:42:33 -0600 Subject: [PATCH 1/2] Include the error object when raising Session.logged_out Note: The `call` argument previously defined in the SDK was never actually populated, and appears to be a documentation error when the definition was copied from `Call.incoming` directly above it. --- .../integ/matrix-client-event-emitter.spec.js | 25 +++++++++++++++++-- src/client.js | 2 +- src/http-api.js | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/spec/integ/matrix-client-event-emitter.spec.js b/spec/integ/matrix-client-event-emitter.spec.js index 93f4fbce4c6..b339cb0e55b 100644 --- a/spec/integ/matrix-client-event-emitter.spec.js +++ b/spec/integ/matrix-client-event-emitter.spec.js @@ -302,11 +302,32 @@ describe("MatrixClient events", function() { }); it("should emit Session.logged_out on M_UNKNOWN_TOKEN", function() { - httpBackend.when("GET", "/sync").respond(401, { errcode: 'M_UNKNOWN_TOKEN' }); + const error = { errcode: 'M_UNKNOWN_TOKEN' }; + httpBackend.when("GET", "/sync").respond(401, error); let sessionLoggedOutCount = 0; - client.on("Session.logged_out", function(event, member) { + client.on("Session.logged_out", function(errObj) { sessionLoggedOutCount++; + expect(errObj).toMatchObject(error); + }); + + client.startClient(); + + return httpBackend.flushAllExpected().then(function() { + expect(sessionLoggedOutCount).toEqual( + 1, "Session.logged_out fired wrong number of times", + ); + }); + }); + + it("should emit Session.logged_out on M_UNKNOWN_TOKEN (soft logout)", function() { + const error = { errcode: 'M_UNKNOWN_TOKEN', soft_logout: true }; + httpBackend.when("GET", "/sync").respond(401, error); + + let sessionLoggedOutCount = 0; + client.on("Session.logged_out", function(errObj) { + sessionLoggedOutCount++; + expect(errObj).toMatchObject(error); }); client.startClient(); diff --git a/src/client.js b/src/client.js index 9b3ade274ab..87db5c20a11 100644 --- a/src/client.js +++ b/src/client.js @@ -4555,7 +4555,7 @@ module.exports.CRYPTO_ENABLED = CRYPTO_ENABLED; * when then login session can be renewed by using a refresh token. * @event module:client~MatrixClient#"Session.logged_out" * @example - * matrixClient.on("Session.logged_out", function(call){ + * matrixClient.on("Session.logged_out", function(errorObj){ * // show the login screen * }); */ diff --git a/src/http-api.js b/src/http-api.js index 0c42f765ed6..16171151afc 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -470,7 +470,7 @@ module.exports.MatrixHttpApi.prototype = { const self = this; requestPromise.catch(function(err) { if (err.errcode == 'M_UNKNOWN_TOKEN') { - self.event_emitter.emit("Session.logged_out"); + self.event_emitter.emit("Session.logged_out", err); } else if (err.errcode == 'M_CONSENT_NOT_GIVEN') { self.event_emitter.emit( "no_consent", From ff9c84ff94eb22dd1725c8aa964ed05135874789 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 3 Jul 2019 16:50:24 -0600 Subject: [PATCH 2/2] Fix tests --- spec/integ/matrix-client-event-emitter.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integ/matrix-client-event-emitter.spec.js b/spec/integ/matrix-client-event-emitter.spec.js index b339cb0e55b..9f7b028eb0a 100644 --- a/spec/integ/matrix-client-event-emitter.spec.js +++ b/spec/integ/matrix-client-event-emitter.spec.js @@ -308,7 +308,7 @@ describe("MatrixClient events", function() { let sessionLoggedOutCount = 0; client.on("Session.logged_out", function(errObj) { sessionLoggedOutCount++; - expect(errObj).toMatchObject(error); + expect(errObj.data).toEqual(error); }); client.startClient(); @@ -327,7 +327,7 @@ describe("MatrixClient events", function() { let sessionLoggedOutCount = 0; client.on("Session.logged_out", function(errObj) { sessionLoggedOutCount++; - expect(errObj).toMatchObject(error); + expect(errObj.data).toEqual(error); }); client.startClient();