Skip to content

Commit 8c16d69

Browse files
turt2liveGermaint3chguy
authored
Set minimum supported Matrix 1.1 version (drop legacy r0 versions) (#3007)
Co-authored-by: Germain <[email protected]> Co-authored-by: Michael Telatynski <[email protected]>
1 parent 55b9116 commit 8c16d69

27 files changed

+229
-287
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
This is the [Matrix](https://matrix.org) Client-Server SDK for JavaScript and TypeScript. This SDK can be run in a
1212
browser or in Node.js.
1313

14+
#### Minimum Matrix server version: v1.1
15+
1416
The Matrix specification is constantly evolving - while this SDK aims for maximum backwards compatibility, it only
1517
guarantees that a feature will be supported for at least 4 spec releases. For example, if a feature the js-sdk supports
1618
is removed in v1.4 then the feature is _eligible_ for removal from the SDK when v1.8 is released. This SDK has no

spec/TestClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class TestClient implements IE2EKeyReceiver, ISyncResponder {
9090
logger.log(this + ": starting");
9191
this.httpBackend.when("GET", "/versions").respond(200, {
9292
// we have tests that rely on support for lazy-loading members
93-
versions: ["r0.5.0"],
93+
versions: ["v1.1"],
9494
});
9595
this.httpBackend.when("GET", "/pushrules").respond(200, {});
9696
this.httpBackend.when("POST", "/filter").respond(200, { filter_id: "fid" });

spec/integ/crypto/crypto.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
19451945
};
19461946
};
19471947

1948-
for (const path of ["/_matrix/client/r0/keys/upload", "/_matrix/client/v3/keys/upload"]) {
1948+
for (const path of ["/_matrix/client/v3/keys/upload", "/_matrix/client/v3/keys/upload"]) {
19491949
fetchMock.post(new URL(path, aliceClient.getHomeserverUrl()).toString(), listener, {
19501950
// These routes are already defined in the E2EKeyReceiver
19511951
// We want to overwrite the behaviour of the E2EKeyReceiver
@@ -2082,9 +2082,10 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
20822082
return queryResponseBody;
20832083
};
20842084

2085-
for (const path of ["/_matrix/client/r0/keys/query", "/_matrix/client/v3/keys/query"]) {
2086-
fetchMock.post(new URL(path, aliceClient.getHomeserverUrl()).toString(), listener);
2087-
}
2085+
fetchMock.post(
2086+
new URL("/_matrix/client/v3/keys/query", aliceClient.getHomeserverUrl()).toString(),
2087+
listener,
2088+
);
20882089
});
20892090
}
20902091

@@ -2175,7 +2176,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
21752176
});
21762177

21772178
/**
2178-
* Create a mock to respond to the PUT request `/_matrix/client/r0/user/:userId/account_data/:type(m.secret_storage.*)`
2179+
* Create a mock to respond to the PUT request `/_matrix/client/v3/user/:userId/account_data/:type(m.secret_storage.*)`
21792180
* Resolved when a key is uploaded (ie in `body.content.key`)
21802181
* https://spec.matrix.org/v1.6/client-server-api/#put_matrixclientv3useruseridaccount_datatype
21812182
*/
@@ -2184,7 +2185,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
21842185
// This url is called multiple times during the secret storage bootstrap process
21852186
// When we received the newly generated key, we return it
21862187
fetchMock.put(
2187-
"express:/_matrix/client/r0/user/:userId/account_data/:type(m.secret_storage.*)",
2188+
"express:/_matrix/client/v3/user/:userId/account_data/:type(m.secret_storage.*)",
21882189
(url: string, options: RequestInit) => {
21892190
const content = JSON.parse(options.body as string);
21902191

@@ -2200,15 +2201,15 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
22002201
}
22012202

22022203
/**
2203-
* Create a mock to respond to the PUT request `/_matrix/client/r0/user/:userId/account_data/m.cross_signing.${key}`
2204+
* Create a mock to respond to the PUT request `/_matrix/client/v3/user/:userId/account_data/m.cross_signing.${key}`
22042205
* Resolved when the cross signing key is uploaded
22052206
* https://spec.matrix.org/v1.6/client-server-api/#put_matrixclientv3useruseridaccount_datatype
22062207
*/
22072208
function awaitCrossSigningKeyUpload(key: string): Promise<Record<string, {}>> {
22082209
return new Promise((resolve) => {
22092210
// Called when the cross signing key is uploaded
22102211
fetchMock.put(
2211-
`express:/_matrix/client/r0/user/:userId/account_data/m.cross_signing.${key}`,
2212+
`express:/_matrix/client/v3/user/:userId/account_data/m.cross_signing.${key}`,
22122213
(url: string, options: RequestInit) => {
22132214
const content = JSON.parse(options.body as string);
22142215
resolve(content.encrypted);

spec/integ/matrix-client-event-timeline.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ describe("MatrixClient event timelines", function () {
13421342
function respondToContext(event: Partial<IEvent> = THREAD_ROOT): ExpectedHttpRequest {
13431343
const request = httpBackend.when(
13441344
"GET",
1345-
encodeUri("/_matrix/client/r0/rooms/$roomId/context/$eventId", {
1345+
encodeUri("/_matrix/client/v3/rooms/$roomId/context/$eventId", {
13461346
$roomId: roomId,
13471347
$eventId: event.event_id!,
13481348
}),
@@ -1360,7 +1360,7 @@ describe("MatrixClient event timelines", function () {
13601360
function respondToEvent(event: Partial<IEvent> = THREAD_ROOT): ExpectedHttpRequest {
13611361
const request = httpBackend.when(
13621362
"GET",
1363-
encodeUri("/_matrix/client/r0/rooms/$roomId/event/$eventId", {
1363+
encodeUri("/_matrix/client/v3/rooms/$roomId/event/$eventId", {
13641364
$roomId: roomId,
13651365
$eventId: event.event_id!,
13661366
}),
@@ -1371,7 +1371,7 @@ describe("MatrixClient event timelines", function () {
13711371
function respondToMessagesRequest(): ExpectedHttpRequest {
13721372
const request = httpBackend.when(
13731373
"GET",
1374-
encodeUri("/_matrix/client/r0/rooms/$roomId/messages", {
1374+
encodeUri("/_matrix/client/v3/rooms/$roomId/messages", {
13751375
$roomId: roomId,
13761376
}),
13771377
);

spec/integ/matrix-client-methods.spec.ts

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe("MatrixClient", function () {
7373

7474
it("should upload the file", function () {
7575
httpBackend
76-
.when("POST", "/_matrix/media/r0/upload")
76+
.when("POST", "/_matrix/media/v3/upload")
7777
.check(function (req) {
7878
expect(req.rawData).toEqual(buf);
7979
expect(req.queryParams?.filename).toEqual("hi.txt");
@@ -108,7 +108,7 @@ describe("MatrixClient", function () {
108108

109109
it("should parse errors into a MatrixError", function () {
110110
httpBackend
111-
.when("POST", "/_matrix/media/r0/upload")
111+
.when("POST", "/_matrix/media/v3/upload")
112112
.check(function (req) {
113113
expect(req.rawData).toEqual(buf);
114114
// @ts-ignore private property
@@ -708,7 +708,7 @@ describe("MatrixClient", function () {
708708
const auth = { identifier: 1 };
709709
it("should pass through an auth dict", function () {
710710
httpBackend
711-
.when("DELETE", "/_matrix/client/r0/devices/my_device")
711+
.when("DELETE", "/_matrix/client/v3/devices/my_device")
712712
.check(function (req) {
713713
expect(req.data).toEqual({ auth: auth });
714714
})
@@ -1102,10 +1102,6 @@ describe("MatrixClient", function () {
11021102
submit_url: "https://foobar.matrix/_matrix/matrix",
11031103
};
11041104

1105-
httpBackend.when("GET", "/_matrix/client/versions").respond(200, {
1106-
versions: ["r0.6.0"],
1107-
});
1108-
11091105
const prom = client.requestRegisterEmailToken("bob@email", "secret", 1);
11101106
httpBackend
11111107
.when("POST", "/register/email/requestToken")
@@ -1126,10 +1122,6 @@ describe("MatrixClient", function () {
11261122
it("should supply an id_access_token", async () => {
11271123
const targetEmail = "[email protected]";
11281124

1129-
httpBackend.when("GET", "/_matrix/client/versions").respond(200, {
1130-
versions: ["r0.6.0"],
1131-
});
1132-
11331125
httpBackend
11341126
.when("POST", "/invite")
11351127
.check((req) => {
@@ -1165,10 +1157,6 @@ describe("MatrixClient", function () {
11651157
],
11661158
};
11671159

1168-
httpBackend.when("GET", "/_matrix/client/versions").respond(200, {
1169-
versions: ["r0.6.0"],
1170-
});
1171-
11721160
httpBackend
11731161
.when("POST", "/createRoom")
11741162
.check((req) => {
@@ -1652,6 +1640,82 @@ describe("MatrixClient", function () {
16521640
]);
16531641
});
16541642
});
1643+
1644+
describe("getFallbackAuthUrl", () => {
1645+
it("should return fallback url", () => {
1646+
expect(client.getFallbackAuthUrl("loginType", "authSessionId")).toMatchInlineSnapshot(
1647+
`"http://alice.localhost.test.server/_matrix/client/v3/auth/loginType/fallback/web?session=authSessionId"`,
1648+
);
1649+
});
1650+
});
1651+
1652+
describe("addThreePidOnly", () => {
1653+
it("should make expected POST request", async () => {
1654+
httpBackend
1655+
.when("POST", "/_matrix/client/v3/account/3pid/add")
1656+
.check(function (req) {
1657+
expect(req.data).toEqual({
1658+
client_secret: "secret",
1659+
sid: "sid",
1660+
});
1661+
expect(req.headers["Authorization"]).toBe("Bearer " + accessToken);
1662+
})
1663+
.respond(200, {});
1664+
1665+
await Promise.all([
1666+
client.addThreePidOnly({
1667+
client_secret: "secret",
1668+
sid: "sid",
1669+
}),
1670+
httpBackend.flushAllExpected(),
1671+
]);
1672+
});
1673+
});
1674+
1675+
describe("bindThreePid", () => {
1676+
it("should make expected POST request", async () => {
1677+
httpBackend
1678+
.when("POST", "/_matrix/client/v3/account/3pid/bind")
1679+
.check(function (req) {
1680+
expect(req.data).toEqual({
1681+
client_secret: "secret",
1682+
id_server: "server",
1683+
id_access_token: "token",
1684+
sid: "sid",
1685+
});
1686+
expect(req.headers["Authorization"]).toBe("Bearer " + accessToken);
1687+
})
1688+
.respond(200, {});
1689+
1690+
await Promise.all([
1691+
client.bindThreePid({
1692+
client_secret: "secret",
1693+
id_server: "server",
1694+
id_access_token: "token",
1695+
sid: "sid",
1696+
}),
1697+
httpBackend.flushAllExpected(),
1698+
]);
1699+
});
1700+
});
1701+
1702+
describe("unbindThreePid", () => {
1703+
it("should make expected POST request", async () => {
1704+
httpBackend
1705+
.when("POST", "/_matrix/client/v3/account/3pid/unbind")
1706+
.check(function (req) {
1707+
expect(req.data).toEqual({
1708+
medium: "email",
1709+
address: "[email protected]",
1710+
id_server: "identity.localhost",
1711+
});
1712+
expect(req.headers["Authorization"]).toBe("Bearer " + accessToken);
1713+
})
1714+
.respond(200, {});
1715+
1716+
await Promise.all([client.unbindThreePid("email", "[email protected]"), httpBackend.flushAllExpected()]);
1717+
});
1718+
});
16551719
});
16561720

16571721
function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent {

spec/integ/matrix-client-syncing.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ describe("MatrixClient syncing", () => {
224224
});
225225

226226
it("should honour lazyLoadMembers if user is not a guest", () => {
227-
client!.doesServerSupportLazyLoading = jest.fn().mockResolvedValue(true);
228-
229227
httpBackend!
230228
.when("GET", "/sync")
231229
.check((req) => {
@@ -242,8 +240,6 @@ describe("MatrixClient syncing", () => {
242240
it("should not honour lazyLoadMembers if user is a guest", () => {
243241
httpBackend!.expectedRequests = [];
244242
httpBackend!.when("GET", "/versions").respond(200, {});
245-
client!.doesServerSupportLazyLoading = jest.fn().mockResolvedValue(true);
246-
247243
httpBackend!
248244
.when("GET", "/sync")
249245
.check((req) => {

spec/integ/sliding-sync-sdk.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe("SlidingSyncSdk", () => {
121121
await client!.initCrypto();
122122
syncOpts.cryptoCallbacks = syncOpts.crypto = client!.crypto;
123123
}
124-
httpBackend!.when("GET", "/_matrix/client/r0/pushrules").respond(200, {});
124+
httpBackend!.when("GET", "/_matrix/client/v3/pushrules").respond(200, {});
125125
sdk = new SlidingSyncSdk(mockSlidingSync, client, testOpts, syncOpts);
126126
};
127127

spec/test-utils/E2EKeyReceiver.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ export class E2EKeyReceiver implements IE2EKeyReceiver {
7575
const listener = (url: string, options: RequestInit) =>
7676
this.onKeyUploadRequest(resolveOneTimeKeys, options);
7777

78-
// catch both r0 and v3 variants
79-
fetchMock.post(new URL("/_matrix/client/r0/keys/upload", homeserverUrl).toString(), listener);
8078
fetchMock.post(new URL("/_matrix/client/v3/keys/upload", homeserverUrl).toString(), listener);
8179
});
8280
}

spec/test-utils/E2EKeyResponder.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export class E2EKeyResponder {
4343
public constructor(homeserverUrl: string) {
4444
// set up a listener for /keys/query.
4545
const listener = (url: string, options: RequestInit) => this.onKeyQueryRequest(options);
46-
// catch both r0 and v3 variants
47-
fetchMock.post(new URL("/_matrix/client/r0/keys/query", homeserverUrl).toString(), listener);
4846
fetchMock.post(new URL("/_matrix/client/v3/keys/query", homeserverUrl).toString(), listener);
4947
}
5048

spec/test-utils/SyncResponder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class SyncResponder implements ISyncResponder {
7575
*/
7676
public constructor(homeserverUrl: string) {
7777
this.debug = debugFunc(`sync-responder:[${homeserverUrl}]`);
78-
fetchMock.get("begin:" + new URL("/_matrix/client/r0/sync?", homeserverUrl).toString(), (_url, _options) =>
78+
fetchMock.get("begin:" + new URL("/_matrix/client/v3/sync?", homeserverUrl).toString(), (_url, _options) =>
7979
this.onSyncRequest(),
8080
);
8181
}

spec/test-utils/client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export const mockClientMethodsEvents = () => ({
8686
* Returns basic mocked client methods related to server support
8787
*/
8888
export const mockClientMethodsServer = (): Partial<Record<MethodLikeKeys<MatrixClient>, unknown>> => ({
89-
doesServerSupportSeparateAddAndBind: jest.fn(),
9089
getIdentityServerUrl: jest.fn(),
9190
getHomeserverUrl: jest.fn(),
9291
getCapabilities: jest.fn().mockReturnValue({}),

spec/test-utils/mockEndpoints.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ import fetchMock from "fetch-mock-jest";
2222
* @param homeserverUrl - the homeserver url for the client under test
2323
*/
2424
export function mockInitialApiRequests(homeserverUrl: string) {
25-
fetchMock.getOnce(new URL("/_matrix/client/versions", homeserverUrl).toString(), { versions: ["r0.5.0"] });
26-
fetchMock.getOnce(new URL("/_matrix/client/r0/pushrules/", homeserverUrl).toString(), {});
27-
fetchMock.postOnce(new URL("/_matrix/client/r0/user/%40alice%3Alocalhost/filter", homeserverUrl).toString(), {
25+
fetchMock.getOnce(new URL("/_matrix/client/versions", homeserverUrl).toString(), { versions: ["v1.1"] });
26+
fetchMock.getOnce(new URL("/_matrix/client/v3/pushrules/", homeserverUrl).toString(), {});
27+
fetchMock.postOnce(new URL("/_matrix/client/v3/user/%40alice%3Alocalhost/filter", homeserverUrl).toString(), {
2828
filter_id: "fid",
2929
});
3030
}
3131

3232
/**
3333
* Mock the requests needed to set up cross signing
3434
*
35-
* Return 404 error for `GET _matrix/client/r0/user/:userId/account_data/:type` request
35+
* Return 404 error for `GET _matrix/client/v3/user/:userId/account_data/:type` request
3636
* Return `{}` for `POST _matrix/client/v3/keys/signatures/upload` request (named `upload-sigs` for fetchMock check)
3737
* Return `{}` for `POST /_matrix/client/(unstable|v3)/keys/device_signing/upload` request (named `upload-keys` for fetchMock check)
3838
*/
3939
export function mockSetupCrossSigningRequests(): void {
4040
// have account_data requests return an empty object
41-
fetchMock.get("express:/_matrix/client/r0/user/:userId/account_data/:type", {
41+
fetchMock.get("express:/_matrix/client/v3/user/:userId/account_data/:type", {
4242
status: 404,
4343
body: { errcode: "M_NOT_FOUND", error: "Account data not found." },
4444
});

0 commit comments

Comments
 (0)