Skip to content

Commit f871227

Browse files
authored
Update to latest Complement (#191)
A few changes have landed in Complement, so we need to update. The breaking changes in the API are: * `MustJoinRoom` now takes an array of `ServerName`s rather than an array of `string`s. To make it easier to build such an array, I've also changed the type of `ClientType.HS` to ServerName. * `WithCleanup` now takes a function which receives a parameter.
1 parent 6ae2a6a commit f871227

14 files changed

+96
-88
lines changed

go.mod

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
module github.com/matrix-org/complement-crypto
22

3-
go 1.23
3+
go 1.23.0
44

5-
toolchain go1.23.1
5+
toolchain go1.23.9
66

77
require (
88
github.com/chromedp/cdproto v0.0.0-20250403032234-65de8f5d025b
99
github.com/chromedp/chromedp v0.13.6
1010
github.com/docker/docker v28.0.4+incompatible
1111
github.com/docker/go-connections v0.5.0
12-
github.com/matrix-org/complement v0.0.0-20250508081216-d2e04c995666
12+
github.com/matrix-org/complement v0.0.0-20250606075022-5daf877cbabb
13+
github.com/matrix-org/gomatrixserverlib v0.0.0-20250119093516-0a1b2bafb5cf
1314
github.com/testcontainers/testcontainers-go v0.35.0
1415
github.com/tidwall/gjson v1.18.0
1516
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
1617
)
1718

1819
require (
1920
dario.cat/mergo v1.0.1 // indirect
21+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
2022
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
2123
github.com/Microsoft/go-winio v0.6.2 // indirect
22-
github.com/Microsoft/hcsshim v0.11.7 // indirect
2324
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2425
github.com/chromedp/sysutil v1.1.0 // indirect
25-
github.com/containerd/containerd v1.7.22 // indirect
2626
github.com/containerd/log v0.1.0 // indirect
2727
github.com/containerd/platforms v0.2.1 // indirect
2828
github.com/cpuguy83/dockercfg v0.3.2 // indirect
@@ -39,13 +39,11 @@ require (
3939
github.com/gobwas/ws v1.4.0 // indirect
4040
github.com/gogo/protobuf v1.3.2 // indirect
4141
github.com/google/uuid v1.6.0 // indirect
42-
github.com/josharian/intern v1.0.0 // indirect
4342
github.com/klauspost/compress v1.17.10 // indirect
43+
github.com/kr/pretty v0.3.1 // indirect
4444
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
4545
github.com/magiconair/properties v1.8.7 // indirect
46-
github.com/mailru/easyjson v0.7.7 // indirect
4746
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 // indirect
48-
github.com/matrix-org/gomatrixserverlib v0.0.0-20250119093516-0a1b2bafb5cf // indirect
4947
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 // indirect
5048
github.com/moby/docker-image-spec v1.3.1 // indirect
5149
github.com/moby/patternmatcher v0.6.0 // indirect
@@ -59,6 +57,7 @@ require (
5957
github.com/pkg/errors v0.9.1 // indirect
6058
github.com/pmezard/go-difflib v1.0.0 // indirect
6159
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
60+
github.com/rogpeppe/go-internal v1.10.0 // indirect
6261
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
6362
github.com/shoenig/go-m1cpu v0.1.6 // indirect
6463
github.com/sirupsen/logrus v1.9.3 // indirect
@@ -71,10 +70,15 @@ require (
7170
github.com/yusufpapurcu/wmi v1.2.4 // indirect
7271
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
7372
go.opentelemetry.io/otel v1.30.0 // indirect
73+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
7474
go.opentelemetry.io/otel/metric v1.30.0 // indirect
7575
go.opentelemetry.io/otel/trace v1.30.0 // indirect
76-
golang.org/x/crypto v0.32.0 // indirect
77-
golang.org/x/sys v0.29.0 // indirect
78-
google.golang.org/grpc v1.64.1 // indirect
76+
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
77+
golang.org/x/crypto v0.36.0 // indirect
78+
golang.org/x/sys v0.31.0 // indirect
79+
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
80+
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
81+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
82+
google.golang.org/protobuf v1.33.0 // indirect
7983
gopkg.in/yaml.v3 v3.0.1 // indirect
8084
)

go.sum

Lines changed: 30 additions & 38 deletions
Large diffs are not rendered by default.

internal/api/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package api
22

33
import (
44
"fmt"
5+
"github.com/matrix-org/gomatrixserverlib/spec"
56
"time"
67

78
"github.com/matrix-org/complement/client"
89
"github.com/matrix-org/complement/ct"
910
)
1011

1112
type ClientType struct {
12-
Lang ClientTypeLang // rust or js
13-
HS string // hs1 or hs2
13+
Lang ClientTypeLang // rust or js
14+
HS spec.ServerName // hs1 or hs2
1415
}
1516

1617
// Client represents a generic crypto client.

internal/cc/instance.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/matrix-org/complement-crypto/internal/api"
1010
"github.com/matrix-org/complement-crypto/internal/config"
1111
"github.com/matrix-org/complement-crypto/internal/deploy"
12+
13+
complementconfig "github.com/matrix-org/complement/config"
1214
)
1315

1416
// Instance represents a test instance.
@@ -37,7 +39,7 @@ func (i *Instance) TestMain(m *testing.M, namespace string) {
3739
}
3840

3941
// Defer to complement to run the test suite
40-
complement.TestMain(m, namespace, complement.WithCleanup(func() { // always teardown even if panicking
42+
complement.TestMain(m, namespace, complement.WithCleanup(func(conf *complementconfig.Complement) { // always teardown even if panicking
4143
i.ssMutex.Lock()
4244
if i.ssDeployment != nil {
4345
i.ssDeployment.Teardown()

internal/cc/test_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type TestContext struct {
5656
// This User can then be passed to other functions to login on new test devices.
5757
func (c *TestContext) RegisterNewUser(t *testing.T, clientType api.ClientType, localpartSuffix string) *User {
5858
return &User{
59-
CSAPI: c.Deployment.Register(t, clientType.HS, helpers.RegistrationOpts{
59+
CSAPI: c.Deployment.Register(t, string(clientType.HS), helpers.RegistrationOpts{
6060
LocalpartSuffix: localpartSuffix,
6161
Password: "complement-crypto-password",
6262
}),
@@ -277,7 +277,7 @@ func (encRoomOptions) RotationPeriodMs(milliseconds int) EncRoomOption {
277277

278278
// MustRegisterNewDevice logs in a new device for this client, else fails the test.
279279
func (c *TestContext) MustRegisterNewDevice(t *testing.T, user *User, newDeviceID string) *User {
280-
newDevice := c.Deployment.Login(t, user.ClientType.HS, user.CSAPI, helpers.LoginOpts{
280+
newDevice := c.Deployment.Login(t, string(user.ClientType.HS), user.CSAPI, helpers.LoginOpts{
281281
DeviceID: newDeviceID,
282282
Password: user.Password, // TODO: remove? not needed as inherited from client?
283283
})

internal/tests/client_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package tests
55

66
import (
77
"fmt"
8+
complementconfig "github.com/matrix-org/complement/config"
89
"log"
910
"os"
1011
"path/filepath"
@@ -74,8 +75,8 @@ func TestMain(m *testing.M) {
7475
})
7576
}
7677
rust.SetupLogs("rust_sdk_logs")
77-
js.SetupJSLogs("./logs/js_sdk.log") // rust sdk logs on its own
78-
complement.TestMain(m, "clienttests", complement.WithCleanup(func() { // always teardown even if panicking
78+
js.SetupJSLogs("./logs/js_sdk.log") // rust sdk logs on its own
79+
complement.TestMain(m, "clienttests", complement.WithCleanup(func(conf *complementconfig.Complement) { // always teardown even if panicking
7980
ssMutex.Lock()
8081
if ssDeployment != nil {
8182
ssDeployment.Teardown()

tests/delayed_requests_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"github.com/matrix-org/gomatrixserverlib/spec"
45
"strings"
56
"testing"
67
"time"
@@ -70,7 +71,7 @@ func TestDelayedInviteResponse(t *testing.T) {
7071
eventID := alice.MustSendMessage(t, roomID, "hello world!")
7172

7273
// bob joins, ensure he can decrypt the message.
73-
tc.Bob.JoinRoom(t, roomID, []string{clientType.HS})
74+
tc.Bob.JoinRoom(t, roomID, []spec.ServerName{clientType.HS})
7475
bob.WaitUntilEventInRoom(t, roomID, api.CheckEventHasMembership(tc.Bob.UserID, "join")).Waitf(t, 7*time.Second, "did not see own join")
7576
bob.MustBackpaginate(t, roomID, 3)
7677

tests/device_keys_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"github.com/matrix-org/gomatrixserverlib/spec"
45
"net/http"
56
"sync/atomic"
67
"testing"
@@ -39,7 +40,7 @@ func TestFailedDeviceKeyDownloadRetries(t *testing.T) {
3940
}, func() {
4041
// And Alice and Bob are in an encrypted room together
4142
roomID := tc.CreateNewEncryptedRoom(t, tc.Alice, cc.EncRoomOptions.Invite([]string{tc.Bob.UserID}))
42-
tc.Bob.MustJoinRoom(t, roomID, []string{"hs1"})
43+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{"hs1"})
4344

4445
tc.WithAliceAndBobSyncing(t, func(alice, bob api.TestClient) {
4546
// When Alice sends a message

tests/federation_connectivity_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"github.com/matrix-org/gomatrixserverlib/spec"
45
"testing"
56
"time"
67

@@ -30,7 +31,7 @@ func TestNewUserCannotGetKeysForOfflineServer(t *testing.T) {
3031
})
3132
roomID := tc.CreateNewEncryptedRoom(t, tc.Alice, cc.EncRoomOptions.Invite([]string{tc.Bob.UserID}))
3233
t.Logf("%s joining room %s", tc.Bob.UserID, roomID)
33-
tc.Bob.MustJoinRoom(t, roomID, []string{"hs1"})
34+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{"hs1"})
3435

3536
tc.WithAliceAndBobSyncing(t, func(alice, bob api.TestClient) {
3637
// let clients sync device keys
@@ -51,7 +52,7 @@ func TestNewUserCannotGetKeysForOfflineServer(t *testing.T) {
5152
tc.WithClientSyncing(t, &cc.ClientCreationRequest{
5253
User: tc.Charlie,
5354
}, func(charlie api.TestClient) {
54-
tc.Charlie.MustJoinRoom(t, roomID, []string{"hs1"})
55+
tc.Charlie.MustJoinRoom(t, roomID, []spec.ServerName{"hs1"})
5556

5657
// let charlie sync device keys... and fail to get bob's keys!
5758
time.Sleep(time.Second)
@@ -118,8 +119,8 @@ func TestExistingSessionCannotGetKeysForOfflineServer(t *testing.T) {
118119
roomIDbc := tc.CreateNewEncryptedRoom(t, tc.Charlie, cc.EncRoomOptions.Invite([]string{tc.Bob.UserID}))
119120
roomIDab := tc.CreateNewEncryptedRoom(t, tc.Alice, cc.EncRoomOptions.Invite([]string{tc.Bob.UserID}))
120121
t.Logf("%s joining rooms %s and %s", tc.Bob.UserID, roomIDab, roomIDbc)
121-
tc.Bob.MustJoinRoom(t, roomIDab, []string{"hs1"})
122-
tc.Bob.MustJoinRoom(t, roomIDbc, []string{"hs1"})
122+
tc.Bob.MustJoinRoom(t, roomIDab, []spec.ServerName{"hs1"})
123+
tc.Bob.MustJoinRoom(t, roomIDbc, []spec.ServerName{"hs1"})
123124

124125
tc.WithAliceBobAndCharlieSyncing(t, func(alice, bob, charlie api.TestClient) {
125126
// let clients sync device keys
@@ -141,7 +142,7 @@ func TestExistingSessionCannotGetKeysForOfflineServer(t *testing.T) {
141142

142143
// C now joins the room ab
143144
tc.Alice.MustInviteRoom(t, roomIDab, tc.Charlie.UserID)
144-
tc.Charlie.MustJoinRoom(t, roomIDab, []string{"hs1"})
145+
tc.Charlie.MustJoinRoom(t, roomIDab, []spec.ServerName{"hs1"})
145146

146147
// let charlie sync device keys...
147148
time.Sleep(time.Second)

tests/membership_acls_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tests
22

33
import (
44
"fmt"
5+
"github.com/matrix-org/gomatrixserverlib/spec"
56
"testing"
67
"time"
78

@@ -30,7 +31,7 @@ func TestAliceBobEncryptionWorks(t *testing.T) {
3031
cc.EncRoomOptions.PresetTrustedPrivateChat(),
3132
cc.EncRoomOptions.Invite([]string{tc.Bob.UserID}),
3233
)
33-
tc.Bob.MustJoinRoom(t, roomID, []string{clientTypeA.HS})
34+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{clientTypeA.HS})
3435

3536
// SDK testing below
3637
// -----------------
@@ -87,7 +88,7 @@ func TestCanDecryptMessagesAfterInviteButBeforeJoin(t *testing.T) {
8788
alice.MustSendMessage(t, roomID, wantMsgBody)
8889

8990
// Bob joins the room (via Complement, but it shouldn't matter)
90-
tc.Bob.MustJoinRoom(t, roomID, []string{clientTypeA.HS})
91+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{clientTypeA.HS})
9192

9293
isEncrypted, err = bob.IsRoomEncrypted(t, roomID)
9394
must.NotError(t, "failed to check if room is encrypted", err)
@@ -131,7 +132,7 @@ func TestBobCanSeeButNotDecryptHistoryInPublicRoom(t *testing.T) {
131132
waiter.Waitf(t, 5*time.Second, "alice did not see own message")
132133

133134
// now bob joins the room
134-
tc.Bob.MustJoinRoom(t, roomID, []string{clientTypeA.HS})
135+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{clientTypeA.HS})
135136
time.Sleep(time.Second) // wait for it to appear on the client else rust crashes if it cannot find the room FIXME
136137
waiter = bob.WaitUntilEventInRoom(t, roomID, api.CheckEventHasMembership(bob.UserID(), "join"))
137138
waiter.Waitf(t, 5*time.Second, "bob did not see own join")
@@ -159,7 +160,7 @@ func TestOnRejoinBobCanSeeButNotDecryptHistoryInPublicRoom(t *testing.T) {
159160
tc := Instance().CreateTestContext(t, clientTypeA, clientTypeB)
160161
// shared history visibility
161162
roomID := tc.CreateNewEncryptedRoom(t, tc.Alice, cc.EncRoomOptions.PresetPublicChat())
162-
tc.Bob.MustJoinRoom(t, roomID, []string{clientTypeA.HS})
163+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{clientTypeA.HS})
163164

164165
// SDK testing below
165166
// -----------------
@@ -184,7 +185,7 @@ func TestOnRejoinBobCanSeeButNotDecryptHistoryInPublicRoom(t *testing.T) {
184185
waiter.Waitf(t, 5*time.Second, "alice did not see own message")
185186

186187
// now bob rejoins the room, wait until he sees it.
187-
tc.Bob.MustJoinRoom(t, roomID, []string{clientTypeA.HS})
188+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{clientTypeA.HS})
188189
waiter = bob.WaitUntilEventInRoom(t, roomID, api.CheckEventHasMembership(bob.UserID(), "join"))
189190
waiter.Waitf(t, 5*time.Second, "bob did not see own join")
190191
// this is required for some reason else tests fail
@@ -217,7 +218,7 @@ func TestOnNewDeviceBobCanSeeButNotDecryptHistoryInPublicRoom(t *testing.T) {
217218
tc := Instance().CreateTestContext(t, clientTypeA, clientTypeB)
218219
// shared history visibility
219220
roomID := tc.CreateNewEncryptedRoom(t, tc.Alice, cc.EncRoomOptions.PresetPublicChat())
220-
tc.Bob.MustJoinRoom(t, roomID, []string{clientTypeA.HS})
221+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{clientTypeA.HS})
221222

222223
// SDK testing below
223224
// -----------------
@@ -295,7 +296,7 @@ func TestChangingDeviceAfterInviteReEncrypts(t *testing.T) {
295296
User: csapiBob2,
296297
}, func(bob2 api.TestClient) {
297298
time.Sleep(time.Second) // let device keys propagate
298-
tc.Bob.MustJoinRoom(t, roomID, []string{clientTypeA.HS})
299+
tc.Bob.MustJoinRoom(t, roomID, []spec.ServerName{clientTypeA.HS})
299300

300301
time.Sleep(time.Second) // let the client load the events
301302
bob2.MustBackpaginate(t, roomID, 5)

0 commit comments

Comments
 (0)