Skip to content

Commit

Permalink
Implement VerificationRequest.timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Jul 3, 2023
1 parent b4fc2b9 commit 283a08a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
],
"dependencies": {
"@babel/runtime": "^7.12.5",
"@matrix-org/matrix-sdk-crypto-js": "^0.1.0-alpha.11",
"@matrix-org/matrix-sdk-crypto-js": "^0.1.0",
"another-json": "^0.2.0",
"bs58": "^5.0.0",
"content-type": "^1.0.4",
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
expect(request.initiatedByMe).toBe(true);
expect(request.otherUserId).toEqual(TEST_USER_ID);
expect(request.pending).toBe(true);
// we're using fake timers, so the timeout should have exactly 10 minutes left still.
expect(request.timeout).toEqual(600_000);

// and now the request should be visible via `getVerificationRequestsToDeviceInProgress`
{
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/rust-crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ describe("VerificationRequest", () => {
});
});

describe("timeout", () => {
it("passes through the result", () => {
const mockedInner = makeMockedInner();
const request = makeTestRequest(mockedInner);
mockedInner.timeRemainingMillis.mockReturnValue(10_000);
expect(request.timeout).toEqual(10_000);
});
});

describe("startVerification", () => {
let request: RustVerificationRequest;

Expand Down Expand Up @@ -88,5 +97,6 @@ function makeMockedInner(): Mocked<RustSdkCryptoJs.VerificationRequest> {
startSas: jest.fn(),
phase: jest.fn().mockReturnValue(RustSdkCryptoJs.VerificationRequestPhase.Created),
isPassive: jest.fn().mockReturnValue(false),
timeRemainingMillis: jest.fn(),
} as unknown as Mocked<RustSdkCryptoJs.VerificationRequest>;
}
2 changes: 1 addition & 1 deletion src/rust-crypto/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class RustVerificationRequest
* `null` indicates that there is no timeout
*/
public get timeout(): number | null {
throw new Error("not implemented");
return this.inner.timeRemainingMillis();
}

/** once the phase is Started (and !initiatedByMe) or Ready: common methods supported by both sides */
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@
dependencies:
lodash "^4.17.21"

"@matrix-org/matrix-sdk-crypto-js@^0.1.0-alpha.11":
"@matrix-org/matrix-sdk-crypto-js@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-js/-/matrix-sdk-crypto-js-0.1.0.tgz#766580036d4df12120ded223e13b5640e77db136"
integrity sha512-ra/bcFdleC1iRNms2I96UXA0NvQYWpMsHrV5EfJRS7qV1PtnQNvgsvMfjMbkx8QT2ErEmIhsvB5fPCpfp8BSuw==
Expand Down

0 comments on commit 283a08a

Please sign in to comment.