Skip to content

Commit 85711be

Browse files
authored
Show the correct shield status in tooltip for more conditions (element-hq#28476)
* Add support for new shield codes in JS SDK * change string used for shield message * fix test
1 parent de820e1 commit 85711be

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

playwright/e2e/crypto/event-shields.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
logOutOfElement,
1717
verify,
1818
} from "./utils";
19+
import { bootstrapCrossSigningForClient } from "../../pages/client.ts";
1920

2021
test.describe("Cryptography", function () {
2122
test.use({
@@ -307,5 +308,30 @@ test.describe("Cryptography", function () {
307308
const penultimate = page.locator(".mx_EventTile").filter({ hasText: "test encrypted from verified" });
308309
await expect(penultimate.locator(".mx_EventTile_e2eIcon")).not.toBeVisible();
309310
});
311+
312+
test("should show correct shields on events sent by users with changed identity", async ({
313+
page,
314+
app,
315+
bot: bob,
316+
homeserver,
317+
}) => {
318+
// Verify Bob
319+
await verify(app, bob);
320+
321+
// Bob logs in a new device and resets cross-signing
322+
const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob);
323+
await bootstrapCrossSigningForClient(await bobSecondDevice.prepareClient(), bob.credentials, true);
324+
325+
/* should show an error for a message from a previously verified device */
326+
await bobSecondDevice.sendMessage(testRoomId, "test encrypted from user that was previously verified");
327+
const last = page.locator(".mx_EventTile_last");
328+
await expect(last).toContainText("test encrypted from user that was previously verified");
329+
const lastE2eIcon = last.locator(".mx_EventTile_e2eIcon");
330+
await expect(lastE2eIcon).toHaveClass(/mx_EventTile_e2eIcon_warning/);
331+
await lastE2eIcon.focus();
332+
await expect(await app.getTooltipForElement(lastE2eIcon)).toContainText(
333+
"Sender's verified identity has changed",
334+
);
335+
});
310336
});
311337
});

src/components/views/rooms/EventTile.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,13 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
758758
shieldReasonMessage = _t("encryption|event_shield_reason_mismatched_sender_key");
759759
break;
760760

761-
default:
762-
shieldReasonMessage = _t("error|unknown");
761+
case EventShieldReason.SENT_IN_CLEAR:
762+
shieldReasonMessage = _t("common|unencrypted");
763+
break;
764+
765+
case EventShieldReason.VERIFICATION_VIOLATION:
766+
shieldReasonMessage = _t("timeline|decryption_failure|sender_identity_previously_verified");
767+
break;
763768
}
764769

765770
if (this.state.shieldColour === EventShieldColour.GREY) {

test/unit-tests/components/views/rooms/EventTile-test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ describe("EventTile", () => {
301301
[EventShieldReason.UNKNOWN_DEVICE, "unknown or deleted device"],
302302
[EventShieldReason.AUTHENTICITY_NOT_GUARANTEED, "can't be guaranteed"],
303303
[EventShieldReason.MISMATCHED_SENDER_KEY, "Encrypted by an unverified session"],
304+
[EventShieldReason.SENT_IN_CLEAR, "Not encrypted"],
305+
[EventShieldReason.VERIFICATION_VIOLATION, "Sender's verified identity has changed"],
304306
])("shows the correct reason code for %i (%s)", async (reasonCode: EventShieldReason, expectedText: string) => {
305307
mxEvent = await mkEncryptedMatrixEvent({
306308
plainContent: { msgtype: "m.text", body: "msg1" },

0 commit comments

Comments
 (0)