Log lines no longer cut a name inside a UTF-8 sequence, the "superseded upload" error says the file's state rather than claiming a revision is active, a test-only block decrypter moves to the tests, a one-line alias of encryptPassphrase goes, the upload godoc is rewrapped and the fake's server struct is gofmt clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package protondrive
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/ProtonMail/gopenpgp/v3/crypto"
|
|
"github.com/rclone/rclone/backend/protondrive/protontest"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// newTestClient returns a client with caching enabled for a new user
|
|
// of a new fake server, signed in without a login round trip.
|
|
func newTestClient(t testing.TB) (*client, *protontest.Server, *protontest.User) {
|
|
t.Helper()
|
|
return newTestClientOpt(t, clientOptions{EnableCaching: true})
|
|
}
|
|
|
|
// newTestClientOpt is newTestClient with the options opt.
|
|
func newTestClientOpt(t testing.TB, opt clientOptions) (*client, *protontest.Server, *protontest.User) {
|
|
t.Helper()
|
|
srv := protontest.New(t)
|
|
u := srv.AddUser("user", "pass")
|
|
return newTestClientFor(t, srv, u, opt), srv, u
|
|
}
|
|
|
|
// newTestClientFor returns a client for a new session of u.
|
|
func newTestClientFor(t testing.TB, srv *protontest.Server, u *protontest.User, opt clientOptions) *client {
|
|
t.Helper()
|
|
c, err := newClient(context.Background(), newAccountSession(srv, u), opt)
|
|
require.NoError(t, err)
|
|
t.Cleanup(c.close)
|
|
return c
|
|
}
|
|
|
|
// decryptBlock returns the encrypted block enc (SEIPDv1 or v2)
|
|
// decrypted with the content session key sk.
|
|
func decryptBlock(enc []byte, sk *crypto.SessionKey) ([]byte, error) {
|
|
r, err := blockDecrypter(bytes.NewReader(enc), sk)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
plain, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("decrypt block: %w", err)
|
|
}
|
|
return plain, nil
|
|
}
|