diff --git a/internal/api/client.go b/internal/api/client.go index 71df69f..666821e 100644 --- a/internal/api/client.go +++ b/internal/api/client.go @@ -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 @@ -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()) } diff --git a/internal/api/js.go b/internal/api/js.go index a7137d8..25519bf 100644 --- a/internal/api/js.go +++ b/internal/api/js.go @@ -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 { diff --git a/internal/api/rust.go b/internal/api/rust.go index 36da2c9..1590c57 100644 --- a/internal/api/rust.go +++ b/internal/api/rust.go @@ -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 { diff --git a/tests/main_test.go b/tests/main_test.go index 90f62f4..a228a5b 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -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)) diff --git a/tests/membership_acls_test.go b/tests/membership_acls_test.go index 4d711e1..3a1bef6 100644 --- a/tests/membership_acls_test.go +++ b/tests/membership_acls_test.go @@ -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" ) @@ -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() { @@ -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()