Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ export default {
// Used in script which only runs in environment with `@octokit/rest` installed
"@octokit/rest",
// Used by jest
"jest-fixed-jsdom",
"jest-environment-jsdom",
"babel-jest",
"ts-node",
// Used by `@babel/plugin-transform-runtime`
"@babel/runtime",
// Transitive dep of jest
"jsdom",
// Not sure what knip is thinking here, we don't have vitest yet
"vitest-environment-jest-fixed-jsdom",
],
ignoreBinaries: [
// Used when available by reusable workflow `.github/workflows/release-make.yml`
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"@babel/preset-env": "^7.12.11",
"@babel/preset-typescript": "^7.12.7",
"@casualbot/jest-sonar-reporter": "2.5.0",
"@fetch-mock/jest": "^0.2.20",
"@jest/globals": "^30.2.0",
"@matrix-org/olm": "3.2.15",
"@peculiar/webcrypto": "^1.4.5",
"@stylistic/eslint-plugin": "^5.0.0",
Expand All @@ -104,17 +106,16 @@
"eslint-plugin-tsdoc": "^0.5.0",
"eslint-plugin-unicorn": "^56.0.0",
"fake-indexeddb": "^5.0.2",
"fetch-mock": "11.1.5",
"fetch-mock-jest": "^1.5.1",
"fetch-mock": "^12.6.0",
"husky": "^9.0.0",
"jest": "^30.0.0",
"jest-environment-jsdom": "^30.0.0",
"jest-environment-jsdom": "^30.2.0",
"jest-fixed-jsdom": "^0.0.11",
"jest-localstorage-mock": "^2.4.6",
"jest-mock": "^30.0.0",
"knip": "^5.0.0",
"lint-staged": "^16.0.0",
"matrix-mock-request": "^2.5.0",
"node-fetch": "^2.7.0",
"prettier": "3.7.4",
"rimraf": "^6.0.0",
"ts-node": "^10.9.2",
Expand Down
2 changes: 1 addition & 1 deletion spec/TestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { type ISyncResponder } from "./test-utils/SyncResponder";
* Wrapper for a MockStorageApi, MockHttpBackend and MatrixClient
*
* @deprecated Avoid using this; it is tied too tightly to matrix-mock-request and is generally inconvenient to use.
* Instead, construct a MatrixClient manually, use fetch-mock-jest to intercept the HTTP requests, and
* Instead, construct a MatrixClient manually, use fetch-mock to intercept the HTTP requests, and
* use things like {@link E2EKeyReceiver} and {@link SyncResponder} to manage the requests.
*/
export class TestClient implements IE2EKeyReceiver, ISyncResponder {
Expand Down
43 changes: 15 additions & 28 deletions spec/integ/crypto/cross-signing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import fetchMock from "fetch-mock-jest";
import fetchMock from "@fetch-mock/jest";
import "fake-indexeddb/auto";
import { IDBFactory } from "fake-indexeddb";
import debug from "debug";
Expand Down Expand Up @@ -83,7 +83,6 @@ describe("cross-signing", () => {
async () => {
// anything that we don't have a specific matcher for silently returns a 404
fetchMock.catch(404);
fetchMock.config.warnOnFallback = false;

const homeserverUrl = "https://alice-server.com";
aliceClient = createClient({
Expand Down Expand Up @@ -114,7 +113,6 @@ describe("cross-signing", () => {

afterEach(async () => {
aliceClient.stopClient();
fetchMock.mockReset();
});

/**
Expand All @@ -138,8 +136,8 @@ describe("cross-signing", () => {
await bootstrapCrossSigning(authDict);

// check that the cross-signing keys have been uploaded
expect(fetchMock.called("upload-cross-signing-keys")).toBeTruthy();
const [, keysOpts] = fetchMock.lastCall("upload-cross-signing-keys")!;
expect(fetchMock.callHistory.called("upload-cross-signing-keys")).toBeTruthy();
const keysOpts = fetchMock.callHistory.lastCall("upload-cross-signing-keys")!.options;
const keysBody = JSON.parse(keysOpts!.body as string);
expect(keysBody.auth).toEqual(authDict); // check uia dict was passed
// there should be a key of each type
Expand All @@ -152,8 +150,8 @@ describe("cross-signing", () => {
const sskId = Object.keys(keysBody.self_signing_key.keys)[0];

// check the publish call
expect(fetchMock.called("upload-sigs")).toBeTruthy();
const [, sigsOpts] = fetchMock.lastCall("upload-sigs")!;
expect(fetchMock.callHistory.called("upload-sigs")).toBeTruthy();
const sigsOpts = fetchMock.callHistory.lastCall("upload-sigs")!.options;
const body = JSON.parse(sigsOpts!.body as string);
// there should be a signature for our device, by our self-signing key.
expect(body).toHaveProperty(
Expand Down Expand Up @@ -237,8 +235,8 @@ describe("cross-signing", () => {
expect(await userTrustStatusChangedPromise).toBe(aliceClient.getUserId());

// Expect the signature to be uploaded
expect(fetchMock.called("upload-sigs")).toBeTruthy();
const [, sigsOpts] = fetchMock.lastCall("upload-sigs")!;
expect(fetchMock.callHistory.called("upload-sigs")).toBeTruthy();
const sigsOpts = fetchMock.callHistory.lastCall("upload-sigs")!.options;
const body = JSON.parse(sigsOpts!.body as string);
// the device should have a signature with the public self cross signing keys.
expect(body).toHaveProperty(
Expand All @@ -255,8 +253,7 @@ describe("cross-signing", () => {
// a second call should do nothing except GET requests
fetchMock.mockClear();
await bootstrapCrossSigning(authDict);
const calls = fetchMock.calls((url, opts) => opts.method != "GET");
expect(calls.length).toEqual(0);
expect(fetchMock).toHaveFetchedTimes(0, "unmatched");
});

it("will upload existing cross-signing keys to an established secret storage", async () => {
Expand All @@ -267,7 +264,6 @@ describe("cross-signing", () => {
// To arrange that, we call `bootstrapCrossSigning` on our main device, and then (pretend to) set up 4S from
// a *different* device. Then, when we call `bootstrapCrossSigning` again, it should do the honours.

mockSetupCrossSigningRequests();
const accountDataAccumulator = new AccountDataAccumulator(syncResponder);
accountDataAccumulator.interceptGetAccountData();

Expand All @@ -282,7 +278,7 @@ describe("cross-signing", () => {
});

// Prepare for the cross-signing keys
const p = accountDataAccumulator.interceptSetAccountData(":type(m.cross_signing..*)");
const p = accountDataAccumulator.waitForAccountData("m.cross_signing.master");

await bootstrapCrossSigning(authDict);
await p;
Expand Down Expand Up @@ -415,22 +411,13 @@ describe("cross-signing", () => {
*/
function awaitCrossSigningKeysUpload() {
return new Promise<any>((resolve) => {
fetchMock.post(
{
url: new URL(
"/_matrix/client/v3/keys/device_signing/upload",
aliceClient.getHomeserverUrl(),
).toString(),
name: "upload-cross-signing-keys",
},
(url, options) => {
const content = JSON.parse(options.body as string);
fetchMock.modifyRoute("upload-cross-signing-keys", {
response: (callLog) => {
const content = JSON.parse(callLog.options.body as string);
resolve(content);
return {};
},
// Override the route defined in E2EKeyReceiver
{ overwriteRoutes: true },
);
});
});
}

Expand Down Expand Up @@ -493,9 +480,9 @@ describe("cross-signing", () => {
await aliceClient.getCrypto()!.crossSignDevice(testData.TEST_DEVICE_ID);

// check that a sig for the device was uploaded
const calls = fetchMock.calls("upload-sigs");
const calls = fetchMock.callHistory.calls("upload-sigs");
expect(calls.length).toEqual(1);
const body = JSON.parse(calls[0][1]!.body as string);
const body = JSON.parse(calls[0].options!.body as string);
const deviceSig = body[aliceClient.getSafeUserId()][testData.TEST_DEVICE_ID];
expect(deviceSig).toHaveProperty("signatures");
});
Expand Down
Loading
Loading