Merge branch 'master' into develop

This commit is contained in:
RiotRobot 2023-03-28 14:30:52 +01:00
commit 0475e7107f
15 changed files with 186 additions and 125 deletions

View file

@ -76,7 +76,10 @@ describe("<SessionManagerTab />", () => {
const mockCrossSigningInfo = {
checkDeviceTrust: jest.fn(),
};
const mockVerificationRequest = { cancel: jest.fn(), on: jest.fn() } as unknown as VerificationRequest;
const mockVerificationRequest = {
cancel: jest.fn(),
on: jest.fn(),
} as unknown as VerificationRequest;
const mockClient = getMockClientWithEventEmitter({
...mockClientMethodsUser(aliceId),
getStoredCrossSigningForUser: jest.fn().mockReturnValue(mockCrossSigningInfo),
@ -185,7 +188,7 @@ describe("<SessionManagerTab />", () => {
});
// @ts-ignore mock
mockClient.store = { accountData: {} };
mockClient.store = { accountData: new Map() };
mockClient.getAccountData.mockReset().mockImplementation((eventType) => {
if (eventType.startsWith(LOCAL_NOTIFICATION_SETTINGS_PREFIX.name)) {
@ -222,7 +225,9 @@ describe("<SessionManagerTab />", () => {
it("does not fail when checking device verification fails", async () => {
const logSpy = jest.spyOn(logger, "error").mockImplementation(() => {});
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
const noCryptoError = new Error("End-to-end encryption disabled");
mockClient.getStoredDevice.mockImplementation(() => {
throw noCryptoError;
@ -277,7 +282,9 @@ describe("<SessionManagerTab />", () => {
});
it("extends device with client information when available", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
mockClient.getAccountData.mockImplementation((eventType: string) => {
const content = {
name: "Element Web",
@ -305,7 +312,9 @@ describe("<SessionManagerTab />", () => {
});
it("renders devices without available client information without error", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
const { getByTestId, queryByTestId } = render(getComponent());
@ -343,7 +352,9 @@ describe("<SessionManagerTab />", () => {
});
it("goes to filtered list from security recommendations", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
const { getByTestId, container } = render(getComponent());
await act(async () => {
@ -376,7 +387,9 @@ describe("<SessionManagerTab />", () => {
});
it("renders current session section with an unverified session", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
const { getByTestId } = render(getComponent());
await act(async () => {
@ -387,7 +400,9 @@ describe("<SessionManagerTab />", () => {
});
it("opens encryption setup dialog when verifiying current session", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
const { getByTestId } = render(getComponent());
const modalSpy = jest.spyOn(Modal, "createDialog");
@ -402,7 +417,9 @@ describe("<SessionManagerTab />", () => {
});
it("renders current session section with a verified session", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
mockClient.getStoredDevice.mockImplementation(() => new DeviceInfo(alicesDevice.device_id));
mockCrossSigningInfo.checkDeviceTrust.mockReturnValue(new DeviceTrustLevel(true, true, false, false));
@ -416,7 +433,9 @@ describe("<SessionManagerTab />", () => {
});
it("expands current session details", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
const { getByTestId } = render(getComponent());
await act(async () => {
@ -500,7 +519,9 @@ describe("<SessionManagerTab />", () => {
const modalSpy = jest.spyOn(Modal, "createDialog");
// make the current device verified
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
mockCrossSigningInfo.checkDeviceTrust.mockImplementation((_userId, { deviceId }) => {
if (deviceId === alicesDevice.device_id) {
@ -525,7 +546,9 @@ describe("<SessionManagerTab />", () => {
});
it("does not allow device verification on session that do not support encryption", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
mockCrossSigningInfo.checkDeviceTrust.mockImplementation((_userId, { deviceId }) => {
// current session verified = able to verify other sessions
@ -557,7 +580,9 @@ describe("<SessionManagerTab />", () => {
const modalSpy = jest.spyOn(Modal, "createDialog");
// make the current device verified
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice],
});
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
mockCrossSigningInfo.checkDeviceTrust.mockImplementation((_userId, { deviceId }) => {
if (deviceId === alicesDevice.device_id) {
@ -595,7 +620,9 @@ describe("<SessionManagerTab />", () => {
it("Signs out of current device", async () => {
const modalSpy = jest.spyOn(Modal, "createDialog");
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice],
});
const { getByTestId } = render(getComponent());
await act(async () => {
@ -614,7 +641,9 @@ describe("<SessionManagerTab />", () => {
it("Signs out of current device from kebab menu", async () => {
const modalSpy = jest.spyOn(Modal, "createDialog");
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice],
});
const { getByTestId, getByLabelText } = render(getComponent());
await act(async () => {
@ -629,7 +658,9 @@ describe("<SessionManagerTab />", () => {
});
it("does not render sign out other devices option when only one device", async () => {
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice] });
mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice],
});
const { getByTestId, queryByLabelText } = render(getComponent());
await act(async () => {
@ -671,9 +702,7 @@ describe("<SessionManagerTab />", () => {
// @ts-ignore setup mock
mockClient.store = {
// @ts-ignore setup mock
accountData: {
[mobileDeviceClientInfo.getType()]: mobileDeviceClientInfo,
},
accountData: new Map([[mobileDeviceClientInfo.getType(), mobileDeviceClientInfo]]),
};
mockClient.getDevices
@ -703,7 +732,10 @@ describe("<SessionManagerTab />", () => {
});
describe("other devices", () => {
const interactiveAuthError = { httpStatus: 401, data: { flows: [{ stages: ["m.login.password"] }] } };
const interactiveAuthError = {
httpStatus: 401,
data: { flows: [{ stages: ["m.login.password"] }] },
};
beforeEach(() => {
mockClient.deleteMultipleDevices.mockReset();
@ -712,9 +744,13 @@ describe("<SessionManagerTab />", () => {
it("deletes a device when interactive auth is not required", async () => {
mockClient.deleteMultipleDevices.mockResolvedValue({});
mockClient.getDevices
.mockResolvedValueOnce({ devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice] })
.mockResolvedValueOnce({
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
})
// pretend it was really deleted on refresh
.mockResolvedValueOnce({ devices: [alicesDevice, alicesOlderMobileDevice] });
.mockResolvedValueOnce({
devices: [alicesDevice, alicesOlderMobileDevice],
});
const { getByTestId } = render(getComponent());
@ -785,9 +821,13 @@ describe("<SessionManagerTab />", () => {
.mockResolvedValueOnce({});
mockClient.getDevices
.mockResolvedValueOnce({ devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice] })
.mockResolvedValueOnce({
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
})
// pretend it was really deleted on refresh
.mockResolvedValueOnce({ devices: [alicesDevice, alicesOlderMobileDevice] });
.mockResolvedValueOnce({
devices: [alicesDevice, alicesOlderMobileDevice],
});
const { getByTestId, getByLabelText } = render(getComponent());
@ -821,7 +861,9 @@ describe("<SessionManagerTab />", () => {
// fill password and submit for interactive auth
act(() => {
fireEvent.change(getByLabelText("Password"), { target: { value: "topsecret" } });
fireEvent.change(getByLabelText("Password"), {
target: { value: "topsecret" },
});
fireEvent.submit(getByLabelText("Password"));
});
@ -1062,7 +1104,9 @@ describe("<SessionManagerTab />", () => {
await updateDeviceName(getByTestId, alicesDevice, "");
expect(mockClient.setDeviceDetails).toHaveBeenCalledWith(alicesDevice.device_id, { display_name: "" });
expect(mockClient.setDeviceDetails).toHaveBeenCalledWith(alicesDevice.device_id, {
display_name: "",
});
});
it("displays an error when session display name fails to save", async () => {