-
-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process m.room.encryption
events before emitting RoomMember
events
#2914
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e2aefa2
Pass a `room` parameter into `Crypto.onCryptoEvent`
richvdh dc0d751
Factor out `setRoomEncryptionImpl` which takes a `Room`
richvdh 248d244
Factor out `trackRoomDevicesImpl` which takes a `Room`
richvdh 5656b22
Inline a call to `trackRoomDevices`
richvdh 4928d33
Call onCryptoEvent before processing state events
richvdh 7c41145
Add a new test
richvdh 9d20db1
lint
richvdh f660a6f
Add a test for `setRoomEncryption`
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { MemoryStore } from "../../src"; | |
import { RoomKeyRequestState } from '../../src/crypto/OutgoingRoomKeyRequestManager'; | ||
import { RoomMember } from '../../src/models/room-member'; | ||
import { IStore } from '../../src/store'; | ||
import { IRoomEncryption, RoomList } from "../../src/crypto/RoomList"; | ||
|
||
const Olm = global.Olm; | ||
|
||
|
@@ -1140,4 +1141,48 @@ describe("Crypto", function() { | |
await client!.client.crypto!.start(); | ||
}); | ||
}); | ||
|
||
describe("setRoomEncryption", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is really just to keep the coverage metric high. It's testing the now-essentially-unused |
||
let mockClient: MatrixClient; | ||
let mockRoomList: RoomList; | ||
let clientStore: IStore; | ||
let crypto: Crypto; | ||
|
||
beforeEach(async function() { | ||
mockClient = {} as MatrixClient; | ||
const mockStorage = new MockStorageApi() as unknown as Storage; | ||
clientStore = new MemoryStore({ localStorage: mockStorage }) as unknown as IStore; | ||
const cryptoStore = new MemoryCryptoStore(); | ||
|
||
mockRoomList = { | ||
getRoomEncryption: jest.fn().mockReturnValue(null), | ||
setRoomEncryption: jest.fn().mockResolvedValue(undefined), | ||
} as unknown as RoomList; | ||
|
||
crypto = new Crypto( | ||
mockClient, | ||
"@alice:home.server", | ||
"FLIBBLE", | ||
clientStore, | ||
cryptoStore, | ||
mockRoomList, | ||
[], | ||
); | ||
}); | ||
|
||
it("should set the algorithm if called for a known room", async () => { | ||
const room = new Room("!room:id", mockClient, "@my.user:id"); | ||
await clientStore.storeRoom(room); | ||
await crypto.setRoomEncryption("!room:id", { algorithm: "m.megolm.v1.aes-sha2" } as IRoomEncryption); | ||
expect(mockRoomList!.setRoomEncryption).toHaveBeenCalledTimes(1); | ||
expect(jest.mocked(mockRoomList!.setRoomEncryption).mock.calls[0][0]).toEqual("!room:id"); | ||
}); | ||
|
||
it("should raise if called for an unknown room", async () => { | ||
await expect(async () => { | ||
await crypto.setRoomEncryption("!room:id", { algorithm: "m.megolm.v1.aes-sha2" } as IRoomEncryption); | ||
}).rejects.toThrow(/unknown room/); | ||
expect(mockRoomList!.setRoomEncryption).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is needed due to timing differences in processing
/sync
responses: there are fewerawait
s, which means that we finish processing the/sync
while there are still to-device messages in the queue for processing.