From f4c08477d0f69d0259874f40af9b1bef3734b561 Mon Sep 17 00:00:00 2001 From: Michael Kohler Date: Sun, 19 Apr 2020 14:04:10 +0200 Subject: [PATCH] Reject attemptAuth promise if no auth flow found --- spec/unit/interactive-auth.spec.js | 29 +++++++++++++++++++++++++++++ src/interactive-auth.js | 8 +++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/spec/unit/interactive-auth.spec.js b/spec/unit/interactive-auth.spec.js index 46008b906..bf4e53138 100644 --- a/spec/unit/interactive-auth.spec.js +++ b/spec/unit/interactive-auth.spec.js @@ -143,4 +143,33 @@ describe("InteractiveAuth", function() { expect(stateUpdated).toBeCalledTimes(1); }); }); + + it("should start an auth stage and reject if no auth flow", function() { + const doRequest = jest.fn(); + const stateUpdated = jest.fn(); + + const ia = new InteractiveAuth({ + matrixClient: new FakeClient(), + doRequest: doRequest, + stateUpdated: stateUpdated, + }); + + doRequest.mockImplementation(function(authData) { + logger.log("request1", authData); + expect(authData).toEqual({}); + const err = new MatrixError({ + session: "sessionId", + flows: [], + params: { + "logintype": { param: "aa" }, + }, + }); + err.httpStatus = 401; + throw err; + }); + + return ia.attemptAuth().catch(function(error) { + expect(error.message).toBe('No appropriate authentication flow found'); + }); + }); }); diff --git a/src/interactive-auth.js b/src/interactive-auth.js index eb0e25a51..18cad14b7 100644 --- a/src/interactive-auth.js +++ b/src/interactive-auth.js @@ -351,7 +351,13 @@ InteractiveAuth.prototype = { error.data.session = this._data.session; } this._data = error.data; - this._startNextAuthStage(); + try { + this._startNextAuthStage(); + } catch (e) { + this._rejectFunc(e); + this._resolveFunc = null; + this._rejectFunc = null; + } if ( !this._emailSid &&