Skip to content

Commit

Permalink
Merge pull request #14 from matrix-org/andybalaam/verify-query-reques…
Browse files Browse the repository at this point in the history
…t-is-made-in-device-key-retry

Verify that the /keys/query is really made in the device keys retry test
  • Loading branch information
kegsay authored Mar 1, 2024
2 parents 6b7c77f + 5f5cc1d commit a21a4f0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/device_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"time"

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

// If a client cannot query device keys for a user, it retries.
Expand All @@ -16,6 +18,16 @@ import (
func TestFailedDeviceKeyDownloadRetries(t *testing.T) {
ForEachClientType(t, func(t *testing.T, clientType api.ClientType) {
tc := CreateTestContext(t, clientType, clientType)

// Track whether we received any requests on /keys/query
queryReceived := false
callbackUrl, closeCallbackServer := deploy.NewCallbackServer(
t,
tc.Deployment,
func(data deploy.CallbackData) { queryReceived = true },
)
defer closeCallbackServer()

// Given that the first 4 attempts to download device keys will fail
tc.Deployment.WithMITMOptions(t, map[string]interface{}{
"statuscode": map[string]interface{}{
Expand All @@ -24,6 +36,10 @@ func TestFailedDeviceKeyDownloadRetries(t *testing.T) {
"count": 4,
"filter": "~u .*\\/keys\\/query.* ~m POST",
},
"callback": map[string]interface{}{
"callback_url": callbackUrl,
"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})
Expand All @@ -42,5 +58,8 @@ func TestFailedDeviceKeyDownloadRetries(t *testing.T) {

})
})

// Sanity: we did receive some requests (which we initially blocked)
must.Equal(t, queryReceived, true, "No request to /keys/query was received!")
})
}

0 comments on commit a21a4f0

Please sign in to comment.