Minor cleanups to `handleVerificationRequest` in cypress tests (#10941)

* 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
https://github.com/matrix-org/matrix-js-sdk/pull/3382.

* Remove duplicated code in `decryption-failure` test

* remove unused imports
pull/28217/head
Richard van der Hoff 2023-05-18 16:12:41 +01:00 committed by GitHub
parent 7d0c68aa29
commit 8654a24405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 26 deletions

View File

@ -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";
@ -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
@ -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]);

View File

@ -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);
};