@@ -23,7 +23,7 @@ import HttpBackend from "matrix-mock-request";
2323import * as olmlib from "../../../src/crypto/olmlib" ;
2424import { MatrixError } from '../../../src/http-api' ;
2525import { logger } from '../../../src/logger' ;
26- import { ICrossSigningKey , ICreateClientOpts , ISignedKey } from '../../../src/client' ;
26+ import { ICrossSigningKey , ICreateClientOpts , ISignedKey , MatrixClient } from '../../../src/client' ;
2727import { CryptoEvent , IBootstrapCrossSigningOpts } from '../../../src/crypto' ;
2828import { IDevice } from '../../../src/crypto/deviceinfo' ;
2929import { TestClient } from '../../TestClient' ;
@@ -1137,3 +1137,67 @@ 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+
1199+ it ( "throws an error if crypto is disabled" , ( ) => {
1200+ aliceClient . crypto = undefined ;
1201+ expect ( ( ) => aliceClient . userHasCrossSigningKeys ( ) ) . toThrowError ( "encryption disabled" ) ;
1202+ } ) ;
1203+ } ) ;
0 commit comments