riot-web/test/utils/ShieldUtils-test.ts

224 lines
8.2 KiB
TypeScript
Raw Normal View History

Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2022-12-12 12:24:14 +01:00
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
2022-12-12 12:24:14 +01:00
import { shieldStatusForRoom } from "../../src/utils/ShieldUtils";
import DMRoomMap from "../../src/utils/DMRoomMap";
2020-03-27 16:25:44 +01:00
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
function mkClient(selfTrust = false) {
2020-03-27 16:25:44 +01:00
return {
getUserId: () => "@self:localhost",
checkUserTrust: (userId) => ({
2020-03-27 16:37:59 +01:00
isCrossSigningVerified: () => userId[1] == "T",
2020-03-30 17:33:16 +02:00
wasCrossSigningVerified: () => userId[1] == "T" || userId[1] == "W",
2020-03-27 16:25:44 +01:00
}),
checkDeviceTrust: (userId, deviceId) => ({
2022-12-12 12:24:14 +01:00
isVerified: () => (userId === "@self:localhost" ? selfTrust : userId[2] == "T"),
2020-03-27 16:25:44 +01:00
}),
getStoredDevicesForUser: (userId) => ["DEVICE"],
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as MatrixClient;
2020-03-27 16:25:44 +01:00
}
2022-12-12 12:24:14 +01:00
describe("mkClient self-test", function () {
2020-03-27 16:25:44 +01:00
test.each([true, false])("behaves well for self-trust=%s", (v) => {
const client = mkClient(v);
expect(client.checkDeviceTrust("@self:localhost", "DEVICE").isVerified()).toBe(v);
});
test.each([
["@TT:h", true],
["@TF:h", true],
["@FT:h", false],
2022-12-12 12:24:14 +01:00
["@FF:h", false],
])("behaves well for user trust %s", (userId, trust) => {
2020-03-27 16:25:44 +01:00
expect(mkClient().checkUserTrust(userId).isCrossSigningVerified()).toBe(trust);
});
test.each([
["@TT:h", true],
["@TF:h", false],
["@FT:h", true],
2022-12-12 12:24:14 +01:00
["@FF:h", false],
])("behaves well for device trust %s", (userId, trust) => {
2020-03-27 16:25:44 +01:00
expect(mkClient().checkDeviceTrust(userId, "device").isVerified()).toBe(trust);
});
});
2022-12-12 12:24:14 +01:00
describe("shieldStatusForMembership self-trust behaviour", function () {
2020-03-27 16:25:44 +01:00
beforeAll(() => {
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
const mockInstance = {
2022-12-12 12:24:14 +01:00
getUserIdForRoomId: (roomId) => (roomId === "DM" ? "@any:h" : null),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as DMRoomMap;
2022-12-12 12:24:14 +01:00
jest.spyOn(DMRoomMap, "shared").mockReturnValue(mockInstance);
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
});
afterAll(() => {
2022-12-12 12:24:14 +01:00
jest.spyOn(DMRoomMap, "shared").mockRestore();
2020-03-27 16:25:44 +01:00
});
2022-12-12 12:24:14 +01:00
it.each([
[true, true],
[true, false],
[false, true],
[false, false],
])("2 unverified: returns 'normal', self-trust = %s, DM = %s", async (trusted, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(trusted);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@FF1:h", "@FF2:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual("normal");
});
2022-12-12 12:24:14 +01:00
it.each([
["verified", true, true],
["verified", true, false],
["verified", false, true],
["warning", false, false],
])("2 verified: returns '%s', self-trust = %s, DM = %s", async (result, trusted, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(trusted);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@TT1:h", "@TT2:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
2022-12-12 12:24:14 +01:00
it.each([
["normal", true, true],
["normal", true, false],
["normal", false, true],
["warning", false, false],
])("2 mixed: returns '%s', self-trust = %s, DM = %s", async (result, trusted, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(trusted);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@TT1:h", "@FF2:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
2022-12-12 12:24:14 +01:00
it.each([
["verified", true, true],
["verified", true, false],
["warning", false, true],
["warning", false, false],
])("0 others: returns '%s', self-trust = %s, DM = %s", async (result, trusted, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(trusted);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
2022-12-12 12:24:14 +01:00
it.each([
["verified", true, true],
["verified", true, false],
["verified", false, true],
["verified", false, false],
])("1 verified: returns '%s', self-trust = %s, DM = %s", async (result, trusted, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(trusted);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@TT:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
2022-12-12 12:24:14 +01:00
it.each([
["normal", true, true],
["normal", true, false],
["normal", false, true],
["normal", false, false],
])("1 unverified: returns '%s', self-trust = %s, DM = %s", async (result, trusted, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(trusted);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@FF:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
});
2022-12-12 12:24:14 +01:00
describe("shieldStatusForMembership other-trust behaviour", function () {
2020-03-27 16:25:44 +01:00
beforeAll(() => {
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
const mockInstance = {
2022-12-12 12:24:14 +01:00
getUserIdForRoomId: (roomId) => (roomId === "DM" ? "@any:h" : null),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as DMRoomMap;
2022-12-12 12:24:14 +01:00
jest.spyOn(DMRoomMap, "shared").mockReturnValue(mockInstance);
2020-03-27 16:25:44 +01:00
});
2022-12-12 12:24:14 +01:00
it.each([
["warning", true],
["warning", false],
])("1 verified/untrusted: returns '%s', DM = %s", async (result, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(true);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@TF:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
2022-12-12 12:24:14 +01:00
it.each([
["warning", true],
["warning", false],
])("2 verified/untrusted: returns '%s', DM = %s", async (result, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(true);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@TF:h", "@TT:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
2022-12-12 12:24:14 +01:00
it.each([
["normal", true],
["normal", false],
])("2 unverified/untrusted: returns '%s', DM = %s", async (result, dm) => {
2020-03-27 16:25:44 +01:00
const client = mkClient(true);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@FF:h", "@FT:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 17:33:16 +02:00
const status = await shieldStatusForRoom(client, room);
expect(status).toEqual(result);
});
2022-12-12 12:24:14 +01:00
it.each([
["warning", true],
["warning", false],
])("2 was verified: returns '%s', DM = %s", async (result, dm) => {
2020-03-30 17:33:16 +02:00
const client = mkClient(true);
const room = {
roomId: dm ? "DM" : "other",
2021-06-29 14:11:58 +02:00
getEncryptionTargetMembers: () => ["@self:localhost", "@WF:h", "@FT:h"].map((userId) => ({ userId })),
Test typescriptification continued (#8327) * test/utils/MegolmExportEncryption-test.js -> test/utils/MegolmExportEncryption-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * test/utils/ShieldUtils-test.js - test/utils/ShieldUtils-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * type fixes for ShieldUtils-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unsupported assertion failure messages Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io> * add mock restores Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * remove commented decriptionfailuretracker code and test Signed-off-by: Kerry Archibald <kerrya@element.io> * make should aggregate error codes correctly pass Signed-off-by: Kerry Archibald <kerrya@element.io> * cheaters types in MegolmExportEncryption Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "fix ts issues in DecryptionFailureTracker" This reverts commit 1ae748cc51088d60722320dbefae04a62310e2e1. Signed-off-by: Kerry Archibald <kerrya@element.io> * Revert "remove unsupported assertion failure messages" This reverts commit 7bd93d075c4d8d45befcbfd59c889782c9a44b48. * Revert "test/DecryptionFailureTracker-test.js -> test/DecryptionFailureTracker-test.ts" This reverts commit 1670025bd2af9a355c2761998202f602d61f242e. * revert change to DecryptionFailureTracker Signed-off-by: Kerry Archibald <kerrya@element.io>
2022-05-02 09:57:35 +02:00
} as unknown as Room;
2020-03-30 11:18:47 +02:00
const status = await shieldStatusForRoom(client, room);
2020-03-27 16:25:44 +01:00
expect(status).toEqual(result);
});
});