From 6d1d04782a94b9be8e1b1c470d1449f2a2a5d6ec Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 19 Dec 2023 17:27:08 +0000 Subject: [PATCH] Send authenticated /versions request (#3968) * Send authenticated /versions request Implements [MSC4026](https://github.com/matrix-org/matrix-spec-proposals/pull/4026). I believe this probably is as simple as this: it will mean that the versions response can obviously change after logging in, but since the client is constructed again with an access token, this should just work (?) A remaining question is whether this needs to be optional. Opening the PR to prompt the discussion. Apps might not expect it, but it's just the same auth that we're sending to other endpoints on the same server. * Fix tests * Clear /versions cache on access token set --- spec/unit/matrix-client.spec.ts | 6 ++---- src/client.ts | 15 ++++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index 75af3b6dda1..920bec55804 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -2211,8 +2211,7 @@ describe("MatrixClient", function () { "org.matrix.msc3391": true, }, }; - jest.spyOn(client.http, "request").mockResolvedValue(versionsResponse); - const requestSpy = jest.spyOn(client.http, "authedRequest").mockImplementation(() => Promise.resolve()); + const requestSpy = jest.spyOn(client.http, "authedRequest").mockResolvedValue(versionsResponse); const unstablePrefix = "/_matrix/client/unstable/org.matrix.msc3391"; const path = `/user/${encodeURIComponent(userId)}/account_data/${eventType}`; @@ -2250,8 +2249,7 @@ describe("MatrixClient", function () { "org.matrix.msc3391": false, }, }; - jest.spyOn(client.http, "request").mockResolvedValue(versionsResponse); - const requestSpy = jest.spyOn(client.http, "authedRequest").mockImplementation(() => Promise.resolve()); + const requestSpy = jest.spyOn(client.http, "authedRequest").mockResolvedValue(versionsResponse); const path = `/user/${encodeURIComponent(userId)}/account_data/${eventType}`; // populate version support diff --git a/src/client.ts b/src/client.ts index b10949e2242..73ed7bbba44 100644 --- a/src/client.ts +++ b/src/client.ts @@ -7450,16 +7450,11 @@ export class MatrixClient extends TypedEventEmitter( - Method.Get, - "/_matrix/client/versions", - undefined, // queryParams - undefined, // data - { - prefix: "", - }, - ) + .authedRequest(Method.Get, "/_matrix/client/versions", undefined, undefined, { + prefix: "", + }) .catch((e) => { // Need to unset this if it fails, otherwise we'll never retry this.serverVersionsPromise = undefined; @@ -7732,6 +7727,8 @@ export class MatrixClient extends TypedEventEmitter