@@ -650,6 +650,55 @@ describe("megolm", () => {
650
650
] ) ;
651
651
} ) ;
652
652
653
+ describe ( "get|setGlobalErrorOnUnknownDevices" , ( ) => {
654
+ it ( "should raise an error if crypto is disabled" , ( ) => {
655
+ aliceTestClient . client [ "cryptoBackend" ] = undefined ;
656
+ expect ( ( ) => aliceTestClient . client . setGlobalErrorOnUnknownDevices ( true ) ) . toThrowError (
657
+ "encryption disabled" ,
658
+ ) ;
659
+ expect ( ( ) => aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toThrowError ( "encryption disabled" ) ;
660
+ } ) ;
661
+
662
+ it ( "should permit sending to unknown devices" , async ( ) => {
663
+ expect ( aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toBeTruthy ( ) ;
664
+
665
+ aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
666
+ await aliceTestClient . start ( ) ;
667
+ const p2pSession = await establishOlmSession ( aliceTestClient , testOlmAccount ) ;
668
+
669
+ aliceTestClient . httpBackend . when ( "GET" , "/sync" ) . respond ( 200 , getSyncResponse ( [ "@bob:xyz" ] ) ) ;
670
+ await aliceTestClient . flushSync ( ) ;
671
+
672
+ // start out with the device unknown - the send should be rejected.
673
+ aliceTestClient . httpBackend . when ( "POST" , "/keys/query" ) . respond ( 200 , getTestKeysQueryResponse ( "@bob:xyz" ) ) ;
674
+ aliceTestClient . httpBackend . when ( "POST" , "/keys/query" ) . respond ( 200 , getTestKeysQueryResponse ( "@bob:xyz" ) ) ;
675
+
676
+ await Promise . all ( [
677
+ aliceTestClient . client . sendTextMessage ( ROOM_ID , "test" ) . then (
678
+ ( ) => {
679
+ throw new Error ( "sendTextMessage failed on an unknown device" ) ;
680
+ } ,
681
+ ( e ) => {
682
+ expect ( e . name ) . toEqual ( "UnknownDeviceError" ) ;
683
+ } ,
684
+ ) ,
685
+ aliceTestClient . httpBackend . flushAllExpected ( ) ,
686
+ ] ) ;
687
+
688
+ // enable sending to unknown devices, and resend
689
+ aliceTestClient . client . setGlobalErrorOnUnknownDevices ( false ) ;
690
+ expect ( aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toBeFalsy ( ) ;
691
+
692
+ const room = aliceTestClient . client . getRoom ( ROOM_ID ) ! ;
693
+ const pendingMsg = room . getPendingEvents ( ) [ 0 ] ;
694
+
695
+ await Promise . all ( [
696
+ aliceTestClient . client . resendEvent ( pendingMsg , room ) ,
697
+ expectSendKeyAndMessage ( aliceTestClient . httpBackend , "@bob:xyz" , testOlmAccount , p2pSession ) ,
698
+ ] ) ;
699
+ } ) ;
700
+ } ) ;
701
+
653
702
describe ( "get|setGlobalBlacklistUnverifiedDevices" , ( ) => {
654
703
it ( "should raise an error if crypto is disabled" , ( ) => {
655
704
aliceTestClient . client [ "cryptoBackend" ] = undefined ;
0 commit comments