Skip to content

Commit

Permalink
Add stub MustLoadBackup; factor out new device login to MustLoginDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 23, 2023
1 parent d802345 commit 558ce91
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
8 changes: 8 additions & 0 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Client interface {
MustGetEvent(t *testing.T, roomID, eventID string) Event
// MustBackupKeys will backup E2EE keys, else fail the test.
MustBackupKeys(t *testing.T)
// MustLoadBackup will recover E2EE keys from the latest backup, else fail the test.
MustLoadBackup(t *testing.T)
// Log something to stdout and the underlying client log file
Logf(t *testing.T, format string, args ...interface{})
// The user for this client
Expand Down Expand Up @@ -104,6 +106,12 @@ func (c *LoggedClient) MustBackupKeys(t *testing.T) {
c.Client.MustBackupKeys(t)
}

func (c *LoggedClient) MustLoadBackup(t *testing.T) {
t.Helper()
c.Logf(t, "%s MustLoadBackup", c.logPrefix())
c.Client.MustLoadBackup(t)
}

func (c *LoggedClient) logPrefix() string {
return fmt.Sprintf("[%s](%s)", c.UserID(), c.Type())
}
Expand Down
4 changes: 4 additions & 0 deletions internal/api/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ func (c *JSClient) MustBackpaginate(t *testing.T, roomID string, count int) {
}

func (c *JSClient) MustBackupKeys(t *testing.T) {
// TODO
}

func (c *JSClient) MustLoadBackup(t *testing.T) {
// TODO
}

func (c *JSClient) WaitUntilEventInRoom(t *testing.T, roomID string, checker func(e Event) bool) Waiter {
Expand Down
6 changes: 6 additions & 0 deletions internal/api/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ func (c *RustClient) MustBackupKeys(t *testing.T) {
return
}
} */
c.FFIClient.Encryption().EnableRecovery(true, nil)
}

func (c *RustClient) MustLoadBackup(t *testing.T) {
t.Helper()
// TODO
}

func (c *RustClient) WaitUntilEventInRoom(t *testing.T, roomID string, checker func(Event) bool) Waiter {
Expand Down
8 changes: 8 additions & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ func (c *TestContext) CreateNewEncryptedRoom(t *testing.T, creator *client.CSAPI
})
}

func (c *TestContext) MustLoginDevice(t *testing.T, existing *client.CSAPI, clientType api.ClientType, deviceID string) (*client.CSAPI, api.Client) {
newClient := c.Deployment.Login(t, clientType.HS, existing, helpers.LoginOpts{
DeviceID: deviceID,
Password: "complement-crypto-password",
})
return newClient, c.MustLoginClient(t, newClient, clientType)
}

func (c *TestContext) MustLoginClient(t *testing.T, cli *client.CSAPI, clientType api.ClientType) api.Client {
t.Helper()
return MustLoginClient(t, clientType, api.FromComplementClient(cli, "complement-crypto-password"), c.Deployment.SlidingSyncURL(t))
Expand Down
13 changes: 2 additions & 11 deletions tests/membership_acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

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

Expand Down Expand Up @@ -278,11 +277,7 @@ func TestOnNewDeviceBobCanSeeButNotDecryptHistoryInPublicRoom(t *testing.T) {
waiter.Wait(t, 5*time.Second)

// now bob logs in on a new device. He should NOT be able to decrypt this event (though can see it due to history visibility)
csapiBob2 := tc.Deployment.Login(t, clientTypeB.HS, tc.Bob, helpers.LoginOpts{
DeviceID: "NEW_DEVICE",
Password: "complement-crypto-password",
})
bob2 := tc.MustLoginClient(t, csapiBob2, clientTypeB)
csapiBob2, bob2 := tc.MustLoginDevice(t, tc.Bob, clientTypeB, "NEW_DEVICE")
bob2StopSyncing := bob2.StartSyncing(t)
bob2StoppedSyncing := false
defer func() {
Expand Down Expand Up @@ -358,11 +353,7 @@ func TestChangingDeviceAfterInviteReEncrypts(t *testing.T) {
evID := alice.SendMessage(t, roomID, body)

// now Bob logs in on a different device and accepts the invite. The different device should be able to decrypt the message.
csapiBob2 := tc.Deployment.Login(t, clientTypeB.HS, tc.Bob, helpers.LoginOpts{
DeviceID: "NEW_DEVICE",
Password: "complement-crypto-password",
})
bob2 := tc.MustLoginClient(t, csapiBob2, clientTypeB)
_, bob2 := tc.MustLoginDevice(t, tc.Bob, clientTypeB, "NEW_DEVICE")
bob2StopSyncing := bob2.StartSyncing(t)
defer bob2StopSyncing()

Expand Down

0 comments on commit 558ce91

Please sign in to comment.