@@ -532,6 +532,55 @@ describe("megolm", () => {
532
532
] ) ;
533
533
} ) ;
534
534
535
+ describe ( "get|setGlobalErrorOnUnknownDevices" , ( ) => {
536
+ it ( "should raise an error if crypto is disabled" , ( ) => {
537
+ aliceTestClient . client [ "cryptoBackend" ] = undefined ;
538
+ expect ( ( ) => aliceTestClient . client . setGlobalErrorOnUnknownDevices ( true ) ) . toThrowError (
539
+ "encryption disabled" ,
540
+ ) ;
541
+ expect ( ( ) => aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toThrowError ( "encryption disabled" ) ;
542
+ } ) ;
543
+
544
+ it ( "should permit sending to unknown devices" , async ( ) => {
545
+ expect ( aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toBeTruthy ( ) ;
546
+
547
+ aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
548
+ await aliceTestClient . start ( ) ;
549
+ const p2pSession = await establishOlmSession ( aliceTestClient , testOlmAccount ) ;
550
+
551
+ aliceTestClient . httpBackend . when ( "GET" , "/sync" ) . respond ( 200 , getSyncResponse ( [ "@bob:xyz" ] ) ) ;
552
+ await aliceTestClient . flushSync ( ) ;
553
+
554
+ // start out with the device unknown - the send should be rejected.
555
+ aliceTestClient . httpBackend . when ( "POST" , "/keys/query" ) . respond ( 200 , getTestKeysQueryResponse ( "@bob:xyz" ) ) ;
556
+ aliceTestClient . httpBackend . when ( "POST" , "/keys/query" ) . respond ( 200 , getTestKeysQueryResponse ( "@bob:xyz" ) ) ;
557
+
558
+ await Promise . all ( [
559
+ aliceTestClient . client . sendTextMessage ( ROOM_ID , "test" ) . then (
560
+ ( ) => {
561
+ throw new Error ( "sendTextMessage failed on an unknown device" ) ;
562
+ } ,
563
+ ( e ) => {
564
+ expect ( e . name ) . toEqual ( "UnknownDeviceError" ) ;
565
+ } ,
566
+ ) ,
567
+ aliceTestClient . httpBackend . flushAllExpected ( ) ,
568
+ ] ) ;
569
+
570
+ // enable sending to unknown devices, and resend
571
+ aliceTestClient . client . setGlobalErrorOnUnknownDevices ( false ) ;
572
+ expect ( aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toBeFalsy ( ) ;
573
+
574
+ const room = aliceTestClient . client . getRoom ( ROOM_ID ) ! ;
575
+ const pendingMsg = room . getPendingEvents ( ) [ 0 ] ;
576
+
577
+ await Promise . all ( [
578
+ aliceTestClient . client . resendEvent ( pendingMsg , room ) ,
579
+ expectSendKeyAndMessage ( aliceTestClient . httpBackend , "@bob:xyz" , testOlmAccount , p2pSession ) ,
580
+ ] ) ;
581
+ } ) ;
582
+ } ) ;
583
+
535
584
describe ( "get|setGlobalBlacklistUnverifiedDevices" , ( ) => {
536
585
it ( "should raise an error if crypto is disabled" , ( ) => {
537
586
aliceTestClient . client [ "cryptoBackend" ] = undefined ;
0 commit comments