Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Minor cleanups to handleVerificationRequest in cypress tests (#10941)
Browse files Browse the repository at this point in the history
* Remove redundant `verifier.done()` call

This `done` call completes the verification process and stops it responding
with further messages. It is unnecessary, *provided* the verification completes
successfully, for which see
matrix-org/matrix-js-sdk#3382.

* Remove duplicated code in `decryption-failure` test

* remove unused imports
  • Loading branch information
richvdh authored May 18, 2023
1 parent 7d0c68a commit 8654a24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
27 changes: 6 additions & 21 deletions cypress/e2e/crypto/decryption-failure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ limitations under the License.
*/

import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { UserCredentials } from "../../support/login";
import Chainable = Cypress.Chainable;
import { handleVerificationRequest } from "./utils";

const ROOM_NAME = "Test room";
const TEST_USER = "Alia";
Expand All @@ -39,24 +38,6 @@ const waitForVerificationRequest = (cli: MatrixClient): Promise<VerificationRequ
});
};

const handleVerificationRequest = (request: VerificationRequest): Chainable<EmojiMapping[]> => {
return cy.wrap(
new Promise<EmojiMapping[]>((resolve) => {
const onShowSas = (event: ISasEvent) => {
verifier.off("show_sas", onShowSas);
event.confirm();
resolve(event.sas.emoji);
};

const verifier = request.beginKeyVerification("m.sas.v1");
verifier.on("show_sas", onShowSas);
verifier.verify();
}),
// extra timeout, as this sometimes takes a while
{ timeout: 30_000 },
);
};

const checkTimelineNarrow = (button = true) => {
cy.viewport(800, 600); // SVGA
cy.get(".mx_LeftPanel_minimized").should("exist"); // Wait until the left panel is minimized
Expand Down Expand Up @@ -161,7 +142,11 @@ describe("Decryption Failure Bar", () => {
);
cy.wrap(verificationRequestPromise).then((verificationRequest: VerificationRequest) => {
cy.wrap(verificationRequest.accept());
handleVerificationRequest(verificationRequest).then((emojis) => {
cy.wrap(
handleVerificationRequest(verificationRequest),
// extra timeout, as this sometimes takes a while
{ timeout: 30_000 },
).then((emojis: EmojiMapping[]) => {
cy.get(".mx_VerificationShowSas_emojiSas_block").then((emojiBlocks) => {
emojis.forEach((emoji: EmojiMapping, index: number) => {
expect(emojiBlocks[index].textContent.toLowerCase()).to.eq(emoji[0] + emoji[1]);
Expand Down
8 changes: 3 additions & 5 deletions cypress/e2e/crypto/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ export function waitForVerificationRequest(cli: MatrixClient): Promise<Verificat
}

/**
* Handle an incoming verification request
* Automatically handle an incoming verification request
*
* Starts the key verification process, and, once it is accepted on the other side, confirms that the
* emojis match.
*
* Returns a promise that resolves, with the emoji list, once we confirm the emojis
*
* @param request - incoming verification request
* @returns A promise that resolves, with the emoji list, once we confirm the emojis
*/
export function handleVerificationRequest(request: VerificationRequest) {
export function handleVerificationRequest(request: VerificationRequest): Promise<EmojiMapping[]> {
return new Promise<EmojiMapping[]>((resolve) => {
const onShowSas = (event: ISasEvent) => {
verifier.off("show_sas", onShowSas);
event.confirm();
verifier.done();
resolve(event.sas.emoji);
};

Expand Down

0 comments on commit 8654a24

Please sign in to comment.