Skip to content

Commit

Permalink
Merge pull request #5 from matrix-org/andybalaam/test-retrying-device…
Browse files Browse the repository at this point in the history
…-key-download

Test 'If a client cannot query device keys for a user, it retries.'
  • Loading branch information
kegsay authored Feb 28, 2024
2 parents 60a6e31 + 6ab5175 commit d6658d6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
js-sdk/node_modules
js-sdk/dist
internal/api/js/chrome/dist
__pycache__
/internal/api/js/chrome/dist
__pycache__
/rust-sdk/
/tests/logs/
/tests/chromedp/
/tests/rust_storage/
2 changes: 1 addition & 1 deletion TEST_HITLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Network connectivity tests are extremely time sensitive as retries are often usi
- [x] If a client cannot upload OTKs, it retries.
- [x] If a client cannot claim OTKs, it retries.
- [x] If a server cannot send device list updates over federation, it retries. https://github.com/matrix-org/complement/pull/695
- [ ] If a client cannot query device keys for a user, it retries.
- [x] If a client cannot query device keys for a user, it retries.
- [ ] If a server cannot query device keys on another server, it retries.
- [x] If a client cannot send a to-device msg, it retries.
- [x] If a server cannot send a to-device msg to another server, it retries. https://github.com/matrix-org/complement/pull/694
Expand Down
52 changes: 52 additions & 0 deletions tests/device_keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tests

import (
"net/http"
"testing"
"time"

"github.com/matrix-org/complement-crypto/internal/api"
)

// If a client cannot query device keys for a user, it retries.
//
// Block the first few requests to /keys/query so device key download fails.
// Create two users and ensure they can send encrypted messages to each other.
// This proves that device keys download requests get retried.
func TestFailedDeviceKeyDownloadRetries(t *testing.T) {
ForEachClientType(t, func(t *testing.T, clientType api.ClientType) {
tc := CreateTestContext(t, clientType, clientType)
// Given that the first 4 attempts to download device keys will fail
tc.Deployment.WithMITMOptions(t, map[string]interface{}{
"statuscode": map[string]interface{}{
"return_status": http.StatusGatewayTimeout,
"block_request": true,
"count": 4,
"filter": "~u .*\\/keys\\/query.* ~m POST",
},
}, func() {
// And Alice and Bob are in an encrypted room together
roomID := tc.CreateNewEncryptedRoom(t, tc.Alice, "private_chat", []string{tc.Bob.UserID})
tc.Bob.MustJoinRoom(t, roomID, []string{"hs1"})

alice := tc.MustLoginClient(t, tc.Alice, clientType)
defer alice.Close(t)
bob := tc.MustLoginClient(t, tc.Bob, clientType)
defer bob.Close(t)
aliceStopSyncing := alice.MustStartSyncing(t)
defer aliceStopSyncing()
bobStopSyncing := bob.MustStartSyncing(t)
defer bobStopSyncing()

// When Alice sends a message
alice.SendMessage(t, roomID, "checking whether we can send a message")

// Then Bob should receive it
bob.WaitUntilEventInRoom(
t,
roomID,
api.CheckEventHasBody("checking whether we can send a message"),
).Wait(t, 5*time.Second)
})
})
}

0 comments on commit d6658d6

Please sign in to comment.