You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-10 21:23:02 +03:00
Implement VerificationRequest.cancel
(#3505)
This commit is contained in:
committed by
GitHub
parent
326a13bcfe
commit
d1dec4cd08
@@ -290,6 +290,10 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
|
|||||||
await verificationPromise;
|
await verificationPromise;
|
||||||
expect(request.phase).toEqual(VerificationPhase.Done);
|
expect(request.phase).toEqual(VerificationPhase.Done);
|
||||||
|
|
||||||
|
// at this point, cancelling should do nothing.
|
||||||
|
await request.cancel();
|
||||||
|
expect(request.phase).toEqual(VerificationPhase.Done);
|
||||||
|
|
||||||
// we're done with the temporary keypair
|
// we're done with the temporary keypair
|
||||||
olmSAS.free();
|
olmSAS.free();
|
||||||
});
|
});
|
||||||
@@ -406,11 +410,41 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
|
|||||||
await verificationPromise;
|
await verificationPromise;
|
||||||
expect(request.phase).toEqual(VerificationPhase.Done);
|
expect(request.phase).toEqual(VerificationPhase.Done);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("cancellation", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
// pretend that we have another device, which we will start verifying
|
||||||
|
e2eKeyResponder.addDeviceKeys(TEST_USER_ID, TEST_DEVICE_ID, SIGNED_TEST_DEVICE_DATA);
|
||||||
|
|
||||||
it("can cancel during the SAS phase", async () => {
|
|
||||||
aliceClient = await startTestClient();
|
aliceClient = await startTestClient();
|
||||||
await waitForDeviceList();
|
await waitForDeviceList();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can cancel during the Ready phase", async () => {
|
||||||
|
// have alice initiate a verification. She should send a m.key.verification.request
|
||||||
|
const [, request] = await Promise.all([
|
||||||
|
expectSendToDeviceMessage("m.key.verification.request"),
|
||||||
|
aliceClient.getCrypto()!.requestDeviceVerification(TEST_USER_ID, TEST_DEVICE_ID),
|
||||||
|
]);
|
||||||
|
const transactionId = request.transactionId!;
|
||||||
|
|
||||||
|
// The dummy device replies with an m.key.verification.ready...
|
||||||
|
returnToDeviceMessageFromSync(buildReadyMessage(transactionId, ["m.sas.v1"]));
|
||||||
|
await waitForVerificationRequestChanged(request);
|
||||||
|
|
||||||
|
// now alice changes her mind
|
||||||
|
const [requestBody] = await Promise.all([
|
||||||
|
expectSendToDeviceMessage("m.key.verification.cancel"),
|
||||||
|
request.cancel(),
|
||||||
|
]);
|
||||||
|
const toDeviceMessage = requestBody.messages[TEST_USER_ID][TEST_DEVICE_ID];
|
||||||
|
expect(toDeviceMessage.transaction_id).toEqual(transactionId);
|
||||||
|
expect(toDeviceMessage.code).toEqual("m.user");
|
||||||
|
expect(request.phase).toEqual(VerificationPhase.Cancelled);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can cancel during the SAS phase", async () => {
|
||||||
// have alice initiate a verification. She should send a m.key.verification.request
|
// have alice initiate a verification. She should send a m.key.verification.request
|
||||||
const [, request] = await Promise.all([
|
const [, request] = await Promise.all([
|
||||||
expectSendToDeviceMessage("m.key.verification.request"),
|
expectSendToDeviceMessage("m.key.verification.request"),
|
||||||
|
@@ -108,7 +108,7 @@ export interface VerificationRequest
|
|||||||
* Cancels the request, sending a cancellation to the other party
|
* Cancels the request, sending a cancellation to the other party
|
||||||
*
|
*
|
||||||
* @param params - Details for the cancellation, including `reason` (defaults to "User declined"), and `code`
|
* @param params - Details for the cancellation, including `reason` (defaults to "User declined"), and `code`
|
||||||
* (defaults to `m.user`).
|
* (defaults to `m.user`). **Deprecated**: this parameter is ignored by the Rust cryptography implementation.
|
||||||
*
|
*
|
||||||
* @returns Promise which resolves when the event has been sent.
|
* @returns Promise which resolves when the event has been sent.
|
||||||
*/
|
*/
|
||||||
|
@@ -42,7 +42,7 @@ export class RustVerificationRequest
|
|||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly inner: RustSdkCryptoJs.VerificationRequest,
|
private readonly inner: RustSdkCryptoJs.VerificationRequest,
|
||||||
outgoingRequestProcessor: OutgoingRequestProcessor,
|
private readonly outgoingRequestProcessor: OutgoingRequestProcessor,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -210,8 +210,11 @@ export class RustVerificationRequest
|
|||||||
*
|
*
|
||||||
* @returns Promise which resolves when the event has been sent.
|
* @returns Promise which resolves when the event has been sent.
|
||||||
*/
|
*/
|
||||||
public cancel(params?: { reason?: string; code?: string }): Promise<void> {
|
public async cancel(params?: { reason?: string; code?: string }): Promise<void> {
|
||||||
throw new Error("not implemented");
|
const req: undefined | OutgoingRequest = this.inner.cancel();
|
||||||
|
if (req) {
|
||||||
|
await this.outgoingRequestProcessor.makeOutgoingRequest(req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user