Skip to content

Commit d1c731a

Browse files
committed
add tests
1 parent c566261 commit d1c731a

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

spec/unit/crypto/cross-signing.spec.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import HttpBackend from "matrix-mock-request";
2323
import * as olmlib from "../../../src/crypto/olmlib";
2424
import { MatrixError } from '../../../src/http-api';
2525
import { logger } from '../../../src/logger';
26-
import { ICrossSigningKey, ICreateClientOpts, ISignedKey } from '../../../src/client';
26+
import {ICrossSigningKey, ICreateClientOpts, ISignedKey, MatrixClient} from '../../../src/client';
2727
import { CryptoEvent, IBootstrapCrossSigningOpts } from '../../../src/crypto';
2828
import { IDevice } from '../../../src/crypto/deviceinfo';
2929
import { TestClient } from '../../TestClient';
@@ -1137,3 +1137,63 @@ describe("Cross Signing", function() {
11371137
alice.stopClient();
11381138
});
11391139
});
1140+
1141+
1142+
describe("userHasCrossSigningKeys", function() {
1143+
if (!global.Olm) {
1144+
return;
1145+
}
1146+
1147+
beforeAll(function () {
1148+
return global.Olm.init();
1149+
});
1150+
1151+
let aliceClient: MatrixClient;
1152+
let httpBackend: HttpBackend;
1153+
beforeEach(async () => {
1154+
const testClient = await makeTestClient({ userId: "@alice:example.com", deviceId: "Osborne2" });
1155+
aliceClient = testClient.client;
1156+
httpBackend = testClient.httpBackend;
1157+
});
1158+
1159+
afterEach(() => {
1160+
aliceClient.stopClient();
1161+
});
1162+
1163+
it("should download devices and return true if one is a cross-signing key", async () => {
1164+
httpBackend
1165+
.when("POST", "/keys/query")
1166+
.respond(200, {
1167+
"master_keys": {
1168+
"@alice:example.com": {
1169+
user_id: "@alice:example.com",
1170+
usage: ["master"],
1171+
keys: {
1172+
"ed25519:nqOvzeuGWT/sRx3h7+MHoInYj3Uk2LD/unI9kDYcHwk":
1173+
"nqOvzeuGWT/sRx3h7+MHoInYj3Uk2LD/unI9kDYcHwk",
1174+
},
1175+
},
1176+
},
1177+
});
1178+
1179+
let result: boolean;
1180+
await Promise.all([
1181+
httpBackend.flush("/keys/query"),
1182+
aliceClient.userHasCrossSigningKeys().then((res) => {result = res}),
1183+
]);
1184+
expect(result!).toBeTruthy();
1185+
});
1186+
1187+
it("should download devices and return false if there is no cross-signing key", async () => {
1188+
httpBackend
1189+
.when("POST", "/keys/query")
1190+
.respond(200, {});
1191+
1192+
let result: boolean;
1193+
await Promise.all([
1194+
httpBackend.flush("/keys/query"),
1195+
aliceClient.userHasCrossSigningKeys().then((res) => {result = res}),
1196+
]);
1197+
expect(result!).toBeFalsy();
1198+
});
1199+
});

0 commit comments

Comments
 (0)