Skip to content

Commit

Permalink
Update the verifier *before* emitting erificationRequestEvent.Change
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Jun 23, 2023
1 parent f3a9aa4 commit 40498f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions spec/integ/crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,21 @@ function runTests(backend: string, initCrypto: InitCrypto, methods: string[] | u
short_authentication_string: ["decimal", "emoji"],
},
});
await waitForVerificationRequestChanged(request);
expect(request.phase).toEqual(VerificationPhase.Started);
expect(request.otherPartySupportsMethod("m.sas.v1")).toBe(true);
expect(request.chosenMethod).toEqual("m.sas.v1");

// there should now be a verifier
const verifier: Verifier = request.verifier!;
expect(verifier).toBeDefined();
expect(verifier.getShowSasCallbacks()).toBeNull();
// as soon as the Changed event arrives, `verifier` should be defined
const verifier = await new Promise<Verifier>((resolve) => {
function onChange() {
expect(request.phase).toEqual(VerificationPhase.Started);
expect(request.otherPartySupportsMethod("m.sas.v1")).toBe(true);
expect(request.chosenMethod).toEqual("m.sas.v1");

const verifier: Verifier = request.verifier!;
expect(verifier).toBeDefined();
expect(verifier.getShowSasCallbacks()).toBeNull();

resolve(verifier);
}
request.once(VerificationRequestEvent.Change, onChange);
});

// start off the verification process: alice will send an `accept`
const sendToDevicePromise = expectSendToDeviceMessage("m.key.verification.accept");
Expand Down
4 changes: 2 additions & 2 deletions src/rust-crypto/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export class RustVerificationRequest
super();

const onChange = async (): Promise<void> => {
this.emit(VerificationRequestEvent.Change);

// if we now have a `Verification` where we lacked one before, wrap it.
// TODO: QR support
if (this._verifier === undefined) {
Expand All @@ -57,6 +55,8 @@ export class RustVerificationRequest
this._verifier = new RustSASVerifier(verification, this, outgoingRequestProcessor);
}
}

this.emit(VerificationRequestEvent.Change);
};
inner.registerChangesCallback(onChange);
}
Expand Down

0 comments on commit 40498f0

Please sign in to comment.