@@ -2069,6 +2069,9 @@ describe('MatrixClient', () => {
2069
2069
const { client } = createTestClient ( null , "@user:example.org" , true ) ;
2070
2070
const syncClient = < ProcessSyncClient > ( < any > client ) ;
2071
2071
2072
+ // Override to fix test as we aren't testing this here.
2073
+ client . crypto . updateFallbackKey = async ( ) => null ;
2074
+
2072
2075
const deviceMessage = {
2073
2076
type : "m.room.encrypted" ,
2074
2077
content : {
@@ -2103,10 +2106,51 @@ describe('MatrixClient', () => {
2103
2106
expect ( processSpy . callCount ) . toBe ( 1 ) ;
2104
2107
} ) ;
2105
2108
2109
+ it ( 'should handle fallback key updates' , async ( ) => {
2110
+ const { client } = createTestClient ( null , "@user:example.org" , true ) ;
2111
+ const syncClient = < ProcessSyncClient > ( < any > client ) ;
2112
+
2113
+ await client . cryptoStore . setDeviceId ( TEST_DEVICE_ID ) ;
2114
+ await feedStaticOlmAccount ( client ) ;
2115
+ client . uploadDeviceKeys = ( ) => Promise . resolve ( { } ) ;
2116
+ client . uploadDeviceOneTimeKeys = ( ) => Promise . resolve ( { } ) ;
2117
+ client . checkOneTimeKeyCounts = ( ) => Promise . resolve ( { } ) ;
2118
+
2119
+ await client . crypto . prepare ( [ ] ) ;
2120
+
2121
+ const updateSpy = simple . stub ( ) ;
2122
+ client . crypto . updateFallbackKey = updateSpy ;
2123
+
2124
+ // Test workaround for https://github.com/matrix-org/synapse/issues/10618
2125
+ await syncClient . processSync ( {
2126
+ // no content
2127
+ } ) ;
2128
+ expect ( updateSpy . callCount ) . toBe ( 1 ) ;
2129
+ updateSpy . reset ( ) ;
2130
+
2131
+ // Test "no more fallback keys" state
2132
+ await syncClient . processSync ( {
2133
+ "org.matrix.msc2732.device_unused_fallback_key_types" : [ ] ,
2134
+ "device_unused_fallback_key_types" : [ ] ,
2135
+ } ) ;
2136
+ expect ( updateSpy . callCount ) . toBe ( 1 ) ;
2137
+ updateSpy . reset ( ) ;
2138
+
2139
+ // Test "has remaining fallback keys"
2140
+ await syncClient . processSync ( {
2141
+ "org.matrix.msc2732.device_unused_fallback_key_types" : [ "signed_curve25519" ] ,
2142
+ "device_unused_fallback_key_types" : [ "signed_curve25519" ] ,
2143
+ } ) ;
2144
+ expect ( updateSpy . callCount ) . toBe ( 0 ) ;
2145
+ } ) ;
2146
+
2106
2147
it ( 'should decrypt timeline events' , async ( ) => {
2107
2148
const { client : realClient } = await createPreparedCryptoTestClient ( "@alice:example.org" ) ;
2108
2149
const client = < ProcessSyncClient > ( < any > realClient ) ;
2109
2150
2151
+ // Override to fix test as we aren't testing this here.
2152
+ realClient . crypto . updateFallbackKey = async ( ) => null ;
2153
+
2110
2154
const userId = "@syncing:example.org" ;
2111
2155
const roomId = "!testing:example.org" ;
2112
2156
const events = [
0 commit comments