Skip to content

Commit

Permalink
Fix device list test
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Sep 25, 2024
1 parent 76cac40 commit 54d791b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/csapi/device_lists_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package csapi_tests

import (
"encoding/base64"
"fmt"
"testing"

"math/rand"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/helpers"
Expand All @@ -18,15 +21,22 @@ import (
// 1. `/sync`'s `device_lists.changed/left` contain the correct user IDs.
// 2. `/keys/query` returns the correct information after device list updates.
func TestDeviceListUpdates(t *testing.T) {
prng := rand.New(rand.NewSource(42))
// uploadNewKeys uploads a new set of keys for a given client.
// Returns a check function that can be passed to mustQueryKeys.
uploadNewKeys := func(t *testing.T, user *client.CSAPI) []match.JSON {
t.Helper()
ed25519KeyID := fmt.Sprintf("ed25519:%s", user.DeviceID)
curve25519KeyID := fmt.Sprintf("curve25519:%s", user.DeviceID)
// valid keys generated by a client
ed25519Key := "aPtHi1NV5O66InHYyrAtjEBTP+Ua33St/3aS4PVR+IE"
curve25519Key := "BLTpDRieneXv24C4IVCAq6pte9u2qo1zT5Ee3jB0pzk"
// generate key-like looking values
ed25519KeyBytes := make([]byte, 32)
_, err := prng.Read(ed25519KeyBytes)
must.NotError(t, "failed to read from prng", err)
ed25519Key := base64.RawStdEncoding.EncodeToString(ed25519KeyBytes)
curve25519KeyBytes := make([]byte, 32)
_, err = prng.Read(curve25519KeyBytes)
must.NotError(t, "failed to read from prng", err)
curve25519Key := base64.RawStdEncoding.EncodeToString(curve25519KeyBytes)

user.MustDo(t, "POST", []string{"_matrix", "client", "v3", "keys", "upload"},
client.WithJSONBody(t, map[string]interface{}{
Expand Down

0 comments on commit 54d791b

Please sign in to comment.