You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-05 00:42:10 +03:00
Fix issue in sync when crypto is not supported by client (#2715)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
f349663329
commit
9bb5afe5c0
@@ -132,7 +132,7 @@ async function aliDownloadsKeys(): Promise<void> {
|
|||||||
// check that the localStorage is updated as we expect (not sure this is
|
// check that the localStorage is updated as we expect (not sure this is
|
||||||
// an integration test, but meh)
|
// an integration test, but meh)
|
||||||
await Promise.all([p1(), p2()]);
|
await Promise.all([p1(), p2()]);
|
||||||
await aliTestClient.client.crypto.deviceList.saveIfDirty();
|
await aliTestClient.client.crypto!.deviceList.saveIfDirty();
|
||||||
// @ts-ignore - protected
|
// @ts-ignore - protected
|
||||||
aliTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
|
aliTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
|
||||||
const devices = data.devices[bobUserId];
|
const devices = data.devices[bobUserId];
|
||||||
@@ -494,7 +494,7 @@ describe("MatrixClient crypto", () => {
|
|||||||
aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} });
|
aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} });
|
||||||
await aliTestClient.start();
|
await aliTestClient.start();
|
||||||
await bobTestClient.start();
|
await bobTestClient.start();
|
||||||
bobTestClient.client.crypto.deviceList.downloadKeys = () => Promise.resolve({});
|
bobTestClient.client.crypto!.deviceList.downloadKeys = () => Promise.resolve({});
|
||||||
await firstSync(aliTestClient);
|
await firstSync(aliTestClient);
|
||||||
await aliEnablesEncryption();
|
await aliEnablesEncryption();
|
||||||
await aliSendsFirstMessage();
|
await aliSendsFirstMessage();
|
||||||
@@ -505,7 +505,7 @@ describe("MatrixClient crypto", () => {
|
|||||||
aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} });
|
aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} });
|
||||||
await aliTestClient.start();
|
await aliTestClient.start();
|
||||||
await bobTestClient.start();
|
await bobTestClient.start();
|
||||||
bobTestClient.client.crypto.deviceList.downloadKeys = () => Promise.resolve({});
|
bobTestClient.client.crypto!.deviceList.downloadKeys = () => Promise.resolve({});
|
||||||
await firstSync(aliTestClient);
|
await firstSync(aliTestClient);
|
||||||
await aliEnablesEncryption();
|
await aliEnablesEncryption();
|
||||||
await aliSendsFirstMessage();
|
await aliSendsFirstMessage();
|
||||||
@@ -569,7 +569,7 @@ describe("MatrixClient crypto", () => {
|
|||||||
aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} });
|
aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} });
|
||||||
await aliTestClient.start();
|
await aliTestClient.start();
|
||||||
await bobTestClient.start();
|
await bobTestClient.start();
|
||||||
bobTestClient.client.crypto.deviceList.downloadKeys = () => Promise.resolve({});
|
bobTestClient.client.crypto!.deviceList.downloadKeys = () => Promise.resolve({});
|
||||||
await firstSync(aliTestClient);
|
await firstSync(aliTestClient);
|
||||||
await aliEnablesEncryption();
|
await aliEnablesEncryption();
|
||||||
await aliSendsFirstMessage();
|
await aliSendsFirstMessage();
|
||||||
|
@@ -225,6 +225,44 @@ describe("MatrixClient syncing", () => {
|
|||||||
|
|
||||||
return httpBackend!.flushAllExpected();
|
return httpBackend!.flushAllExpected();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should emit ClientEvent.Room when invited while crypto is disabled", async () => {
|
||||||
|
const roomId = "!invite:example.org";
|
||||||
|
|
||||||
|
// First sync: an invite
|
||||||
|
const inviteSyncRoomSection = {
|
||||||
|
invite: {
|
||||||
|
[roomId]: {
|
||||||
|
invite_state: {
|
||||||
|
events: [{
|
||||||
|
type: "m.room.member",
|
||||||
|
state_key: selfUserId,
|
||||||
|
content: {
|
||||||
|
membership: "invite",
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
httpBackend!.when("GET", "/sync").respond(200, {
|
||||||
|
...syncData,
|
||||||
|
rooms: inviteSyncRoomSection,
|
||||||
|
});
|
||||||
|
|
||||||
|
// First fire: an initial invite
|
||||||
|
let fires = 0;
|
||||||
|
client!.once(ClientEvent.Room, (room) => {
|
||||||
|
fires++;
|
||||||
|
expect(room.roomId).toBe(roomId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// noinspection ES6MissingAwait
|
||||||
|
client!.startClient();
|
||||||
|
await httpBackend!.flushAllExpected();
|
||||||
|
|
||||||
|
expect(fires).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("initial sync", () => {
|
describe("initial sync", () => {
|
||||||
|
@@ -923,7 +923,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
public urlPreviewCache: { [key: string]: Promise<IPreviewUrlResponse> } = {};
|
public urlPreviewCache: { [key: string]: Promise<IPreviewUrlResponse> } = {};
|
||||||
public identityServer: IIdentityServerProvider;
|
public identityServer: IIdentityServerProvider;
|
||||||
public http: MatrixHttpApi; // XXX: Intended private, used in code.
|
public http: MatrixHttpApi; // XXX: Intended private, used in code.
|
||||||
public crypto: Crypto; // XXX: Intended private, used in code.
|
public crypto?: Crypto; // XXX: Intended private, used in code.
|
||||||
public cryptoCallbacks: ICryptoCallbacks; // XXX: Intended private, used in code.
|
public cryptoCallbacks: ICryptoCallbacks; // XXX: Intended private, used in code.
|
||||||
public callEventHandler: CallEventHandler; // XXX: Intended private, used in code.
|
public callEventHandler: CallEventHandler; // XXX: Intended private, used in code.
|
||||||
public supportsCallTransfer = false; // XXX: Intended private, used in code.
|
public supportsCallTransfer = false; // XXX: Intended private, used in code.
|
||||||
|
29
src/sync.ts
29
src/sync.ts
@@ -1200,19 +1200,22 @@ export class SyncApi {
|
|||||||
await this.processRoomEvents(room, stateEvents);
|
await this.processRoomEvents(room, stateEvents);
|
||||||
|
|
||||||
const inviter = room.currentState.getStateEvents(EventType.RoomMember, client.getUserId())?.getSender();
|
const inviter = room.currentState.getStateEvents(EventType.RoomMember, client.getUserId())?.getSender();
|
||||||
const parkedHistory = await client.crypto.cryptoStore.takeParkedSharedHistory(room.roomId);
|
|
||||||
for (const parked of parkedHistory) {
|
if (client.isCryptoEnabled()) {
|
||||||
if (parked.senderId === inviter) {
|
const parkedHistory = await client.crypto.cryptoStore.takeParkedSharedHistory(room.roomId);
|
||||||
await this.client.crypto.olmDevice.addInboundGroupSession(
|
for (const parked of parkedHistory) {
|
||||||
room.roomId,
|
if (parked.senderId === inviter) {
|
||||||
parked.senderKey,
|
await client.crypto.olmDevice.addInboundGroupSession(
|
||||||
parked.forwardingCurve25519KeyChain,
|
room.roomId,
|
||||||
parked.sessionId,
|
parked.senderKey,
|
||||||
parked.sessionKey,
|
parked.forwardingCurve25519KeyChain,
|
||||||
parked.keysClaimed,
|
parked.sessionId,
|
||||||
true,
|
parked.sessionKey,
|
||||||
{ sharedHistory: true, untrusted: true },
|
parked.keysClaimed,
|
||||||
);
|
true,
|
||||||
|
{ sharedHistory: true, untrusted: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user