You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-02 17:02:31 +03:00
End the verification timer when verification is done
Fixes https://github.com/matrix-org/matrix-js-sdk/issues/980 This also improves cleanliness in the tests to cancel/terminate timers when needed.
This commit is contained in:
@@ -69,8 +69,14 @@ describe("verification request", function() {
|
|||||||
bob.on("crypto.verification.request", (request) => {
|
bob.on("crypto.verification.request", (request) => {
|
||||||
const bobVerifier = request.beginKeyVerification(verificationMethods.SAS);
|
const bobVerifier = request.beginKeyVerification(verificationMethods.SAS);
|
||||||
bobVerifier.verify();
|
bobVerifier.verify();
|
||||||
|
|
||||||
|
// XXX: Private function access (but it's a test, so we're okay)
|
||||||
|
bobVerifier._endTimer();
|
||||||
});
|
});
|
||||||
const aliceVerifier = await alice.requestVerification("@bob:example.com");
|
const aliceVerifier = await alice.requestVerification("@bob:example.com");
|
||||||
expect(aliceVerifier).toBeAn(SAS);
|
expect(aliceVerifier).toBeAn(SAS);
|
||||||
|
|
||||||
|
// XXX: Private function access (but it's a test, so we're okay)
|
||||||
|
aliceVerifier._endTimer();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ describe("SAS verification", function() {
|
|||||||
await sas.verify()
|
await sas.verify()
|
||||||
.catch(spy);
|
.catch(spy);
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
|
|
||||||
|
// Cancel the SAS for cleanup (we started a verification, so abort)
|
||||||
|
sas.cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("verification", function() {
|
describe("verification", function() {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
if (this._transactionTimeoutTimer !== null) {
|
if (this._transactionTimeoutTimer !== null) {
|
||||||
clearTimeout(this._transactionTimeoutTimer);
|
clearTimeout(this._transactionTimeoutTimer);
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
this._transactionTimeoutTimer = setTimeout(() => {
|
||||||
if (!this._done && !this.cancelled) {
|
if (!this._done && !this.cancelled) {
|
||||||
console.log("Triggering verification timeout");
|
console.log("Triggering verification timeout");
|
||||||
this.cancel(timeoutException);
|
this.cancel(timeoutException);
|
||||||
@@ -86,6 +86,13 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
}, 10 * 60 * 1000); // 10 minutes
|
}, 10 * 60 * 1000); // 10 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_endTimer() {
|
||||||
|
if (this._transactionTimeoutTimer !== null) {
|
||||||
|
clearTimeout(this._transactionTimeoutTimer);
|
||||||
|
this._transactionTimeoutTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_sendToDevice(type, content) {
|
_sendToDevice(type, content) {
|
||||||
if (this._done) {
|
if (this._done) {
|
||||||
return Promise.reject(new Error("Verification is already done"));
|
return Promise.reject(new Error("Verification is already done"));
|
||||||
@@ -131,12 +138,14 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
done() {
|
done() {
|
||||||
|
this._endTimer(); // always kill the activity timer
|
||||||
if (!this._done) {
|
if (!this._done) {
|
||||||
this._resolve();
|
this._resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel(e) {
|
cancel(e) {
|
||||||
|
this._endTimer(); // always kill the activity timer
|
||||||
if (!this._done) {
|
if (!this._done) {
|
||||||
this.cancelled = true;
|
this.cancelled = true;
|
||||||
if (this.userId && this.deviceId && this.transactionId) {
|
if (this.userId && this.deviceId && this.transactionId) {
|
||||||
@@ -196,10 +205,12 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
this._promise = new Promise((resolve, reject) => {
|
this._promise = new Promise((resolve, reject) => {
|
||||||
this._resolve = (...args) => {
|
this._resolve = (...args) => {
|
||||||
this._done = true;
|
this._done = true;
|
||||||
|
this._endTimer();
|
||||||
resolve(...args);
|
resolve(...args);
|
||||||
};
|
};
|
||||||
this._reject = (...args) => {
|
this._reject = (...args) => {
|
||||||
this._done = true;
|
this._done = true;
|
||||||
|
this._endTimer();
|
||||||
reject(...args);
|
reject(...args);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user