Skip to content

Commit d177654

Browse files
committed
add tests
1 parent c566261 commit d177654

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

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

Lines changed: 60 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,62 @@ describe("Cross Signing", function() {
11371137
alice.stopClient();
11381138
});
11391139
});
1140+
1141+
describe("userHasCrossSigningKeys", function() {
1142+
if (!global.Olm) {
1143+
return;
1144+
}
1145+
1146+
beforeAll(() => {
1147+
return global.Olm.init();
1148+
});
1149+
1150+
let aliceClient: MatrixClient;
1151+
let httpBackend: HttpBackend;
1152+
beforeEach(async () => {
1153+
const testClient = await makeTestClient({ userId: "@alice:example.com", deviceId: "Osborne2" });
1154+
aliceClient = testClient.client;
1155+
httpBackend = testClient.httpBackend;
1156+
});
1157+
1158+
afterEach(() => {
1159+
aliceClient.stopClient();
1160+
});
1161+
1162+
it("should download devices and return true if one is a cross-signing key", async () => {
1163+
httpBackend
1164+
.when("POST", "/keys/query")
1165+
.respond(200, {
1166+
"master_keys": {
1167+
"@alice:example.com": {
1168+
user_id: "@alice:example.com",
1169+
usage: ["master"],
1170+
keys: {
1171+
"ed25519:nqOvzeuGWT/sRx3h7+MHoInYj3Uk2LD/unI9kDYcHwk":
1172+
"nqOvzeuGWT/sRx3h7+MHoInYj3Uk2LD/unI9kDYcHwk",
1173+
},
1174+
},
1175+
},
1176+
});
1177+
1178+
let result: boolean;
1179+
await Promise.all([
1180+
httpBackend.flush("/keys/query"),
1181+
aliceClient.userHasCrossSigningKeys().then((res) => {result = res;}),
1182+
]);
1183+
expect(result!).toBeTruthy();
1184+
});
1185+
1186+
it("should download devices and return false if there is no cross-signing key", async () => {
1187+
httpBackend
1188+
.when("POST", "/keys/query")
1189+
.respond(200, {});
1190+
1191+
let result: boolean;
1192+
await Promise.all([
1193+
httpBackend.flush("/keys/query"),
1194+
aliceClient.userHasCrossSigningKeys().then((res) => {result = res;}),
1195+
]);
1196+
expect(result!).toBeFalsy();
1197+
});
1198+
});

0 commit comments

Comments
 (0)