(cherry picked from commit dddef858f1
)
Co-authored-by: Michael Weimann <michaelw@matrix.org>
This commit is contained in:
parent
500a543662
commit
3693255cd5
2 changed files with 55 additions and 29 deletions
|
@ -147,35 +147,56 @@ describe("createRoom", () => {
|
|||
});
|
||||
|
||||
describe("canEncryptToAllUsers", () => {
|
||||
const trueUser = new Map([
|
||||
[
|
||||
"@goodUser:localhost",
|
||||
new Map([
|
||||
["DEV1", {} as unknown as DeviceInfo],
|
||||
["DEV2", {} as unknown as DeviceInfo],
|
||||
]),
|
||||
],
|
||||
const user1Id = "@user1:example.com";
|
||||
const user2Id = "@user2:example.com";
|
||||
|
||||
const devices = new Map([
|
||||
["DEV1", {} as unknown as DeviceInfo],
|
||||
["DEV2", {} as unknown as DeviceInfo],
|
||||
]);
|
||||
|
||||
const falseUser = {
|
||||
"@badUser:localhost": {},
|
||||
};
|
||||
|
||||
let client: Mocked<MatrixClient>;
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.get());
|
||||
|
||||
beforeAll(() => {
|
||||
client = mocked(stubClient());
|
||||
});
|
||||
|
||||
it("returns true if all devices have crypto", async () => {
|
||||
client.downloadKeys.mockResolvedValue(trueUser);
|
||||
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost"]);
|
||||
expect(response).toBe(true);
|
||||
it("should return false if download keys does not return any user", async () => {
|
||||
client.downloadKeys.mockResolvedValue(new Map());
|
||||
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false if not all users have crypto", async () => {
|
||||
client.downloadKeys.mockResolvedValue({ ...trueUser, ...falseUser });
|
||||
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost", "@badUser:localhost"]);
|
||||
expect(response).toBe(false);
|
||||
it("should return false if none of the users has a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, new Map()],
|
||||
[user2Id, new Map()],
|
||||
]),
|
||||
);
|
||||
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if some of the users don't have a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, new Map()],
|
||||
[user2Id, devices],
|
||||
]),
|
||||
);
|
||||
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("should return true if all users have a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, devices],
|
||||
[user2Id, devices],
|
||||
]),
|
||||
);
|
||||
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue