protondrive: rewrite the backend on a native client following Proton's SDK
The backend no longer uses Proton-API-Bridge or go-proton-api at run time. Saved sessions from earlier versions keep working without signing in again, and every option keeps its name and meaning. rclone config now offers sign-in with a web browser. The full backend test suite runs against an in-process fake Proton server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
414de88c99
commit
0ec7dce0e5
7 files changed
+1221
-970
No files matched your search
@@ -66,8 +66,6 @@ func TestIntegrationFake(t *testing.T) {
|
||||
if *fstest.RemoteName != "" {
|
||||
t.Skip("skipping as -remote is set")
|
||||
}
|
||||
// TODO: remove once the backend has an endpoint option.
|
||||
t.Skip("the backend cannot be pointed at the fake server yet")
|
||||
remoteName, _, _ := setupFakeRemote(t)
|
||||
fstests.Run(t, &fstests.Opt{
|
||||
RemoteName: remoteName,
|
||||
|
||||
+801
-881
File diff suppressed because it is too large.
Load diff
@@ -2,96 +2,365 @@ package protondrive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rclone/go-proton-api"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"github.com/rclone/rclone/backend/protondrive/api"
|
||||
"github.com/rclone/rclone/backend/protondrive/protontest"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config/configmap"
|
||||
"github.com/rclone/rclone/fs/config/obscure"
|
||||
"github.com/rclone/rclone/fs/fserrors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var protonDriveAppVersionPattern = regexp.MustCompile(`(?i)^external-drive(-[a-z_]+)+@[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?-((stable|beta|RC|alpha)(([.-]?\d+)*)?)?([.-]?dev)?(\+.*)?$`)
|
||||
func TestTranslateError(t *testing.T) {
|
||||
apiErr := func(code int) error {
|
||||
return fmt.Errorf("call: %w", &api.Error{Status: 422, Code: code, Message: "proton says no"})
|
||||
}
|
||||
notFound := fmt.Errorf("get node: %w", errNotFound)
|
||||
exists := fmt.Errorf("create: %w", errExists)
|
||||
other := errors.New("other")
|
||||
|
||||
func TestProtonDriveAppVersionFromRcloneVersion(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
rcloneVersion string
|
||||
want string
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
err error
|
||||
op errorOp
|
||||
want error // compared with ==, if set
|
||||
check func(t *testing.T, got error)
|
||||
}{
|
||||
{
|
||||
name: "release",
|
||||
rcloneVersion: "v1.73.5",
|
||||
want: "external-drive-rclone@1.73.5-stable",
|
||||
},
|
||||
{
|
||||
name: "dev build",
|
||||
rcloneVersion: "v1.74.0-DEV",
|
||||
want: "external-drive-rclone@1.74.0-dev",
|
||||
},
|
||||
{
|
||||
name: "beta build with extra metadata",
|
||||
rcloneVersion: "v1.74.0-beta.9519.990f33f2a.fix-protondrive-sdk-2026",
|
||||
want: "external-drive-rclone@1.74.0-beta.9519+990f33f2a.fix-protondrive-sdk-2026",
|
||||
},
|
||||
{
|
||||
name: "beta build with unsanitized branch name",
|
||||
rcloneVersion: "v1.74.0-beta.9519.990f33f2a.fix/protondrive-sdk-2026",
|
||||
want: "external-drive-rclone@1.74.0-beta.9519+990f33f2a.fix-protondrive-sdk-2026",
|
||||
},
|
||||
{
|
||||
name: "invalid version falls back to stable",
|
||||
rcloneVersion: "not-a-version",
|
||||
want: "external-drive-rclone@1.0.0-stable",
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
got := protonDriveAppVersionFromRcloneVersion(testCase.rcloneVersion)
|
||||
|
||||
if got != testCase.want {
|
||||
t.Fatalf("unexpected app version: got %q, want %q", got, testCase.want)
|
||||
}
|
||||
if !protonDriveAppVersionPattern.MatchString(got) {
|
||||
t.Fatalf("app version %q does not match Proton pattern", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldRetry(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cancelledCtx, cancel := context.WithCancel(ctx)
|
||||
cancel()
|
||||
|
||||
apiErr := func(status int, code proton.Code) error {
|
||||
return &proton.APIError{Status: status, Code: code, Message: "test"}
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
err error
|
||||
wantRetry bool
|
||||
}{
|
||||
{"nil error", ctx, nil, false},
|
||||
{"cancelled context", cancelledCtx, errors.New("some error"), false},
|
||||
{"permanent validation error Code=200501 Status=422 (not retried)", ctx, apiErr(422, 200501), false},
|
||||
{"transient storage block error Code=200501 Status=500 (retried)", ctx, apiErr(500, 200501), true},
|
||||
{"server error Status=500", ctx, apiErr(500, 0), true},
|
||||
{"server error Status=502", ctx, apiErr(502, 0), true},
|
||||
{"server error Status=504", ctx, apiErr(504, 0), true},
|
||||
{"server error Status=503 (handled by SDK, not retried here)", ctx, apiErr(503, 0), false},
|
||||
{"rate limit Status=429 (handled by SDK, not retried here)", ctx, apiErr(429, 0), false},
|
||||
{"client error Status=400", ctx, apiErr(400, 0), false},
|
||||
{"client error Status=404", ctx, apiErr(404, 0), false},
|
||||
{"wrapped API error retried via errors.As", ctx, fmt.Errorf("wrapped: %w", apiErr(500, 0)), true},
|
||||
{"non-API error falls back to fserrors.ShouldRetry", ctx, errors.New("plain error"), false},
|
||||
{name: "nil", err: nil, op: opObject, want: nil},
|
||||
{name: "not found object", err: notFound, op: opObject, want: fs.ErrorObjectNotFound},
|
||||
{name: "not found dir", err: notFound, op: opDir, want: fs.ErrorDirNotFound},
|
||||
{name: "code 2501 object", err: apiErr(api.CodeNotExists), op: opObject, want: fs.ErrorObjectNotFound},
|
||||
{name: "code 2501 dir", err: apiErr(api.CodeNotExists), op: opDir, want: fs.ErrorDirNotFound},
|
||||
{name: "exists mkdir", err: exists, op: opMkdir, want: nil},
|
||||
{name: "exists move", err: exists, op: opMove, want: fs.ErrorCantMove},
|
||||
{name: "exists copy", err: exists, op: opCopy, want: fs.ErrorCantCopy},
|
||||
{name: "exists dirmove", err: exists, op: opDirMove, want: fs.ErrorDirExists},
|
||||
{name: "exists object", err: exists, op: opObject, check: func(t *testing.T, got error) {
|
||||
assert.ErrorIs(t, got, errExists)
|
||||
}},
|
||||
{name: "other unchanged", err: other, op: opObject, want: other},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
gotRetry, _ := shouldRetry(tc.ctx, tc.err)
|
||||
assert.Equal(t, tc.wantRetry, gotRetry)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := translateError(test.err, test.op)
|
||||
if test.check != nil {
|
||||
test.check(t, got)
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.want, got)
|
||||
})
|
||||
}
|
||||
|
||||
for _, code := range []int{
|
||||
api.CodeInsufficientQuota, api.CodeInsufficientSpace, api.CodeMaxFileSizeForFreeUser,
|
||||
api.CodeMaxPublicEditModeForFreeUser, api.CodeTooManyChildren, api.CodeNestingTooDeep,
|
||||
} {
|
||||
t.Run(fmt.Sprintf("code %d no retry", code), func(t *testing.T) {
|
||||
got := translateError(apiErr(code), opObject)
|
||||
assert.True(t, fserrors.IsNoRetryError(got))
|
||||
assert.False(t, fserrors.IsFatalError(got))
|
||||
assert.Contains(t, got.Error(), "proton says no")
|
||||
})
|
||||
}
|
||||
for _, code := range []int{api.CodeInvalidRequirements, api.CodeAppVersionBad} {
|
||||
t.Run(fmt.Sprintf("code %d fatal", code), func(t *testing.T) {
|
||||
got := translateError(apiErr(code), opObject)
|
||||
assert.True(t, fserrors.IsFatalError(got))
|
||||
assert.Contains(t, got.Error(), "upgrade rclone")
|
||||
assert.Contains(t, got.Error(), "proton says no")
|
||||
})
|
||||
}
|
||||
for _, err := range []error{errIntegrity, errUploadMismatch, errUploadSuperseded} {
|
||||
t.Run(err.Error()+" no retry", func(t *testing.T) {
|
||||
got := translateError(fmt.Errorf("op: %w", err), opObject)
|
||||
assert.True(t, fserrors.IsNoRetryError(got))
|
||||
assert.ErrorIs(t, got, err)
|
||||
})
|
||||
}
|
||||
t.Run("outcome unknown no low level retry", func(t *testing.T) {
|
||||
got := translateError(fmt.Errorf("op: %w", errUploadOutcomeUnknown), opObject)
|
||||
assert.True(t, fserrors.IsNoLowLevelRetryError(got))
|
||||
assert.False(t, fserrors.IsNoRetryError(got))
|
||||
assert.ErrorIs(t, got, errUploadOutcomeUnknown)
|
||||
})
|
||||
}
|
||||
|
||||
// sessionConfig returns the config keys of a v1.76 remote holding a new
|
||||
// saved session of u, pointed at srv.
|
||||
func sessionConfig(srv *protontest.Server, u *protontest.User) configmap.Simple {
|
||||
sess := srv.NewSession(u)
|
||||
return configmap.Simple{
|
||||
"type": "protondrive",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"mailbox_password": "",
|
||||
"2fa": "",
|
||||
"otp_secret_key": "",
|
||||
"client_uid": sess.UID,
|
||||
"client_access_token": sess.AccessToken,
|
||||
"client_refresh_token": sess.RefreshToken,
|
||||
"client_salted_key_pass": base64.StdEncoding.EncodeToString([]byte(u.KeyPassword())),
|
||||
"encoding": "Slash,LeftSpace,RightSpace,InvalidUtf8,Dot",
|
||||
"original_file_size": "true",
|
||||
"app_version": "",
|
||||
"replace_existing_draft": "false",
|
||||
"enable_caching": "true",
|
||||
// Not a v1.76 key, but the only way to reach the fake.
|
||||
"endpoint": srv.URL(),
|
||||
}
|
||||
}
|
||||
|
||||
// newTestFs returns an Fs for the config m, shut down when the test ends.
|
||||
func newTestFs(t *testing.T, m configmap.Mapper) *Fs {
|
||||
t.Helper()
|
||||
f, err := NewFs(context.Background(), "test", "", m)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = f.(*Fs).Shutdown(context.Background()) })
|
||||
return f.(*Fs)
|
||||
}
|
||||
|
||||
// authRequests returns the auth requests made to srv.
|
||||
func authRequests(srv *protontest.Server) []string {
|
||||
var out []string
|
||||
for route := range srv.Requests() {
|
||||
if strings.Contains(route, "/auth") {
|
||||
out = append(out, route)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestOptionsBackwardsCompatible(t *testing.T) {
|
||||
srv := protontest.New(t)
|
||||
u := srv.AddUser("user", "pass")
|
||||
m := sessionConfig(srv, u)
|
||||
want := m["client_access_token"]
|
||||
f := newTestFs(t, m)
|
||||
|
||||
_, err := f.List(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, authRequests(srv), "a saved session must be used without signing in")
|
||||
assert.Equal(t, want, m["client_access_token"])
|
||||
assert.Len(t, m["draft_client_uid"], 32, "draft_client_uid is generated and saved")
|
||||
assert.True(t, f.opt.ReportOriginalSize)
|
||||
assert.True(t, f.opt.EnableCaching)
|
||||
}
|
||||
|
||||
func TestNewFsPasswordFallback(t *testing.T) {
|
||||
srv := protontest.New(t)
|
||||
u := srv.AddUser("user", "pass")
|
||||
m := sessionConfig(srv, u)
|
||||
m["username"] = "user"
|
||||
m["password"] = obscure.MustObscure("pass")
|
||||
oldUID := m["client_uid"]
|
||||
srv.RevokeSession(oldUID)
|
||||
|
||||
f := newTestFs(t, m)
|
||||
_, err := f.List(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, oldUID, m["client_uid"])
|
||||
assert.NotEmpty(t, m["client_access_token"])
|
||||
assert.NotEmpty(t, m["client_refresh_token"])
|
||||
keyPass, err := base64.StdEncoding.DecodeString(m["client_salted_key_pass"])
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, u.KeyPassword(), string(keyPass))
|
||||
assert.Equal(t, 1, srv.Requests()["POST /core/v4/auth"])
|
||||
}
|
||||
|
||||
func TestNewFsPasswordFallbackTOTP(t *testing.T) {
|
||||
srv := protontest.New(t)
|
||||
u := srv.AddUser("user", "pass")
|
||||
secret := u.EnableTOTP()
|
||||
m := sessionConfig(srv, u)
|
||||
for _, k := range []string{"client_uid", "client_access_token", "client_refresh_token", "client_salted_key_pass"} {
|
||||
m[k] = ""
|
||||
}
|
||||
m["username"] = "user"
|
||||
m["password"] = obscure.MustObscure("pass")
|
||||
m["otp_secret_key"] = obscure.MustObscure(secret)
|
||||
|
||||
newTestFs(t, m)
|
||||
assert.NotEmpty(t, m["client_uid"])
|
||||
assert.Equal(t, 1, srv.Requests()["POST /core/v4/auth/2fa"])
|
||||
}
|
||||
|
||||
func TestNewFsNoCredentials(t *testing.T) {
|
||||
srv := protontest.New(t)
|
||||
u := srv.AddUser("user", "pass")
|
||||
|
||||
t.Run("none saved", func(t *testing.T) {
|
||||
m := configmap.Simple{"endpoint": srv.URL()}
|
||||
_, err := NewFs(context.Background(), "myremote", "", m)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), `rclone config reconnect myremote:`)
|
||||
})
|
||||
t.Run("revoked", func(t *testing.T) {
|
||||
m := sessionConfig(srv, u)
|
||||
srv.RevokeSession(m["client_uid"])
|
||||
_, err := NewFs(context.Background(), "myremote", "", m)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), `rclone config reconnect myremote:`)
|
||||
})
|
||||
t.Run("undecodable key password", func(t *testing.T) {
|
||||
m := sessionConfig(srv, u)
|
||||
m["client_salted_key_pass"] = "not base64!"
|
||||
_, err := NewFs(context.Background(), "myremote", "", m)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), `rclone config reconnect myremote:`)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTwoRemotesIsolated(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
srv := protontest.New(t)
|
||||
u1 := srv.AddUser("user1", "pass1")
|
||||
u2 := srv.AddUser("user2", "pass2")
|
||||
m1, m2 := sessionConfig(srv, u1), sessionConfig(srv, u2)
|
||||
uid1, uid2 := m1["client_uid"], m2["client_uid"]
|
||||
f1, f2 := newTestFs(t, m1), newTestFs(t, m2)
|
||||
require.NoError(t, f1.Mkdir(ctx, "one"))
|
||||
require.NoError(t, f2.Mkdir(ctx, "two"))
|
||||
|
||||
// Make both sessions refresh, saving new tokens.
|
||||
srv.ExpireAccessToken(uid1)
|
||||
srv.ExpireAccessToken(uid2)
|
||||
f1.DirCacheFlush()
|
||||
f2.DirCacheFlush()
|
||||
entries1, err := f1.List(ctx, "")
|
||||
require.NoError(t, err)
|
||||
entries2, err := f2.List(ctx, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, entries1, 1)
|
||||
assert.Equal(t, "one", entries1[0].Remote())
|
||||
require.Len(t, entries2, 1)
|
||||
assert.Equal(t, "two", entries2[0].Remote())
|
||||
assert.Equal(t, uid1, m1["client_uid"])
|
||||
assert.Equal(t, uid2, m2["client_uid"])
|
||||
for _, k := range []string{"client_uid", "client_access_token", "client_refresh_token", "client_salted_key_pass", "draft_client_uid"} {
|
||||
assert.NotEqual(t, m1[k], m2[k], k)
|
||||
}
|
||||
}
|
||||
|
||||
// configAnswers drives configure through its states, answering each
|
||||
// question by its state from answers, and returns the questions asked.
|
||||
func configAnswers(t *testing.T, m configmap.Mapper, signIn signInOptions, answers map[string]string) []*fs.ConfigOut {
|
||||
t.Helper()
|
||||
var asked []*fs.ConfigOut
|
||||
in := fs.ConfigIn{}
|
||||
for range 10 {
|
||||
out, err := configure(context.Background(), "test", m, in, signIn)
|
||||
require.NoError(t, err)
|
||||
if out == nil {
|
||||
return asked
|
||||
}
|
||||
require.Empty(t, out.Error)
|
||||
in = fs.ConfigIn{State: out.State}
|
||||
if out.Option != nil {
|
||||
asked = append(asked, out)
|
||||
answer, ok := answers[out.State]
|
||||
require.True(t, ok, "unexpected question in state %q: %s", out.State, out.Option.Help)
|
||||
in.Result = answer
|
||||
}
|
||||
}
|
||||
t.Fatal("config didn't finish")
|
||||
return nil
|
||||
}
|
||||
|
||||
// requireSession checks m holds a working session of u on srv.
|
||||
func requireSession(t *testing.T, srv *protontest.Server, m configmap.Simple, u *protontest.User) {
|
||||
t.Helper()
|
||||
keyPass, err := base64.StdEncoding.DecodeString(m["client_salted_key_pass"])
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, u.KeyPassword(), string(keyPass))
|
||||
srv.ResetRequests()
|
||||
newTestFs(t, m)
|
||||
assert.Empty(t, authRequests(srv))
|
||||
}
|
||||
|
||||
func TestConfigBrowser(t *testing.T) {
|
||||
srv := protontest.New(t)
|
||||
u := srv.AddUser("user", "pass")
|
||||
m := configmap.Simple{"endpoint": srv.URL()}
|
||||
var shown string
|
||||
signIn := signInOptions{
|
||||
pollInterval: 10 * time.Millisecond,
|
||||
pollTimeout: 10 * time.Second,
|
||||
showURL: func(signInURL string) {
|
||||
shown = signInURL
|
||||
require.NoError(t, srv.ApproveFork(signInURL, u))
|
||||
},
|
||||
}
|
||||
|
||||
asked := configAnswers(t, m, signIn, map[string]string{"choose": "true"})
|
||||
require.Len(t, asked, 1)
|
||||
assert.Contains(t, asked[0].Option.Help, "rclone is a third-party application not officially supported by Proton.")
|
||||
assert.Equal(t, true, asked[0].Option.Default)
|
||||
assert.True(t, strings.HasPrefix(shown, forkSignInURL), shown)
|
||||
requireSession(t, srv, m, u)
|
||||
}
|
||||
|
||||
func TestConfigPassword(t *testing.T) {
|
||||
srv := protontest.New(t)
|
||||
|
||||
t.Run("no 2fa", func(t *testing.T) {
|
||||
u := srv.AddUser("user", "pass")
|
||||
m := configmap.Simple{"endpoint": srv.URL(), "username": "user", "password": obscure.MustObscure("pass")}
|
||||
asked := configAnswers(t, m, signInOptions{}, map[string]string{"choose": "false"})
|
||||
require.Len(t, asked, 1)
|
||||
assert.Equal(t, false, asked[0].Option.Default, "password sign-in is the default when a password is set")
|
||||
requireSession(t, srv, m, u)
|
||||
})
|
||||
t.Run("2fa asked", func(t *testing.T) {
|
||||
u := srv.AddUser("user2fa", "pass")
|
||||
secret := u.EnableTOTP()
|
||||
m := configmap.Simple{"endpoint": srv.URL(), "username": "user2fa", "password": obscure.MustObscure("pass")}
|
||||
code, err := totp.GenerateCode(secret, time.Now())
|
||||
require.NoError(t, err)
|
||||
asked := configAnswers(t, m, signInOptions{}, map[string]string{"choose": "false", "password_2fa": code})
|
||||
require.Len(t, asked, 2)
|
||||
requireSession(t, srv, m, u)
|
||||
assert.Empty(t, m["2fa"], "the 2FA code is not saved")
|
||||
})
|
||||
t.Run("no password", func(t *testing.T) {
|
||||
m := configmap.Simple{"endpoint": srv.URL()}
|
||||
out, err := configure(context.Background(), "test", m, fs.ConfigIn{State: "password"}, signInOptions{})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, out)
|
||||
assert.NotEmpty(t, out.Error)
|
||||
})
|
||||
}
|
||||
|
||||
func TestConfigStore(t *testing.T) {
|
||||
creds := credentials{UID: "uid", AccessToken: "access", RefreshToken: "refresh", KeyPassword: "key\x00pass"}
|
||||
|
||||
t.Run("round trip", func(t *testing.T) {
|
||||
m := configmap.Simple{}
|
||||
s := &configStore{m: m}
|
||||
s.Save(creds)
|
||||
assert.Equal(t, base64.StdEncoding.EncodeToString([]byte(creds.KeyPassword)), m[clientSaltedKeyPassKey])
|
||||
assert.Equal(t, creds, s.Load())
|
||||
// Another user of the config saves newer tokens.
|
||||
m[clientRefreshTokenKey] = "newer"
|
||||
assert.Equal(t, "newer", s.Load().RefreshToken)
|
||||
})
|
||||
t.Run("overridden", func(t *testing.T) {
|
||||
// Values from the environment or the command line take
|
||||
// precedence over the config file the store saves to.
|
||||
env := configmap.Simple{clientUIDKey: "old uid", clientAccessTokenKey: "old access", clientRefreshTokenKey: "old refresh"}
|
||||
file := configmap.Simple{}
|
||||
m := configmap.New().AddGetter(env, configmap.PriorityNormal).AddGetter(file, configmap.PriorityConfig).AddSetter(file)
|
||||
s := &configStore{m: m}
|
||||
assert.Equal(t, "old refresh", s.Load().RefreshToken)
|
||||
s.Save(creds)
|
||||
assert.Equal(t, creds, s.Load(), "saved credentials must not be shadowed by spent ones")
|
||||
})
|
||||
}
|
||||
+30
-2
@@ -37,8 +37,36 @@ leaves out. Update in the same commit as any structural change.
|
||||
- cgo use differs per release target (the `cgo` and `build_flags` columns of
|
||||
the matrix in `.github/workflows/build.yml`), so a backend cannot assume cgo.
|
||||
|
||||
## `backend/protondrive`
|
||||
|
||||
A native client of the Proton Drive API, following Proton's Drive SDK
|
||||
(spec: `docs/specs/001-protondrive-tier1.md`).
|
||||
|
||||
| File | Responsibility |
|
||||
|---|---|
|
||||
| `protondrive.go` | `Fs`, `Object`, options, `Config` sign-in, dircache glue, `translateError` |
|
||||
| `session.go` | SRP and browser (session fork) sign-in, token refresh, app version |
|
||||
| `account.go` | User and address keys, public-key lookups |
|
||||
| `crypto.go` | Every OpenPGP operation |
|
||||
| `nodes.go` | The `client`: volume bootstrap, pacing, listing, folder/rename/move/copy/trash |
|
||||
| `cache.go` | In-memory node and listing cache |
|
||||
| `upload.go`, `download.go` | Block pipelines |
|
||||
| `api/` | Wire types |
|
||||
| `protontest/` | Fake Proton server, imported by tests only; never imports the backend |
|
||||
|
||||
- **The seam:** `protondrive.go` holds no cryptography and no API routes;
|
||||
the other files never take or return `fs.Fs`/`fs.Object`.
|
||||
- No package-level mutable state except `unlockMu` (key unlocking is
|
||||
serialised across `Fs` instances). Each `Fs` has its own client, session
|
||||
and cache; credentials go through a per-`Fs` `configStore` over the
|
||||
remote's config.
|
||||
- `fake_test.go` runs the full `fstests` contract suite against
|
||||
`protontest` through the hidden `endpoint` option, on every
|
||||
`go test`; `protondrive_test.go` is the live suite (`TestProtonDrive:`).
|
||||
|
||||
## Known rough edges
|
||||
|
||||
- `backend/protondrive` depends on the forks `github.com/rclone/Proton-API-Bridge`
|
||||
and `github.com/rclone/go-proton-api` (`go.mod`). See `docs/specs/`.
|
||||
- `backend/protondrive` tests still import `github.com/rclone/go-proton-api`
|
||||
for differential crypto tests, and `go.mod` still lists
|
||||
`github.com/rclone/Proton-API-Bridge`; both go in plan Task 19.
|
||||
- See `docs/TODO.md` for host tooling gaps.
|
||||
@@ -5,6 +5,28 @@ it with a new one that links back. One entry per decision a future maintainer
|
||||
would otherwise have to reverse-engineer.
|
||||
No index: `grep -n '^## ' docs/DECISIONS.md` lists every entry.
|
||||
|
||||
## 2026-11-11 - Proton Drive backend runs on its own client
|
||||
|
||||
**Status:** accepted
|
||||
**Context:** The backend sat on `rclone/Proton-API-Bridge` and
|
||||
`rclone/go-proton-api`, which share credentials through package globals,
|
||||
write files the official clients can't always read, and can't be tested
|
||||
without a live account (spec 001).
|
||||
**Decision:** `protondrive.go` was rewritten on the native client built in
|
||||
plan Tasks 2-12, keeping every option name and meaning and reading v1.76
|
||||
saved sessions without signing in again. `Config` offers browser sign-in
|
||||
(default unless a username and password are already set, so existing
|
||||
scripted setups keep using them) and password sign-in. An upload whose
|
||||
commit outcome can't be known is a no-low-level-retry error: an immediate
|
||||
retry could add a revision that already landed, while a later sync pass
|
||||
reads the destination first.
|
||||
**Alternatives:** Patching the bridge (globals and crypto stay outside the
|
||||
tree); keeping browser sign-in the default even with a password set
|
||||
(non-interactive `config create` would wait on a browser).
|
||||
**Consequences:** The full contract suite runs hermetically against
|
||||
`protontest`. Several `Fs` of one account in one process each cache
|
||||
separately until events land (spec 6.2).
|
||||
|
||||
## 2026-11-11 - Fork agent tooling is appended, not merged, into upstream files
|
||||
|
||||
**Status:** accepted
|
||||
|
||||
@@ -59,6 +59,20 @@ Small, specific, independently actionable. Remove only when actually done.
|
||||
bad verifier token, a missing block and a stale `CurrentRevisionID`
|
||||
(the fake uses 422 / 2000, which the spec maps to "upgrade rclone").
|
||||
|
||||
- [ ] protondrive: `Rmdir` checks emptiness with `listChildren`, which
|
||||
leaves out Proton Docs/Sheets, drafts and unreadable nodes, so a folder
|
||||
holding only those is trashed (recoverable from the trash). Needs a raw
|
||||
child count from the client.
|
||||
- [ ] protondrive: several `Fs` of one account in one process each have
|
||||
their own node cache; only Move/DirMove sources are invalidated across
|
||||
them. Events (spec 6.2) fix this.
|
||||
- [ ] protondrive: `go mod tidy` would drop `github.com/rclone/Proton-API-Bridge`
|
||||
from `go.mod` now (no Go file imports it; the differential tests import
|
||||
only `go-proton-api`). Left in place for Task 19, which removes both.
|
||||
- [ ] protondrive: browser sign-in in `rclone config` waits up to 10 minutes
|
||||
polling; a non-interactive `config create` without username and password
|
||||
waits the same.
|
||||
|
||||
- [ ] Propose a CI check for this fork: `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`
|
||||
and the `docs/` agent files exist, and `AGENTS.md` is at most 150 lines.
|
||||
- [ ] Upstream CI (`.github/workflows/build.yml`) is gated on
|
||||
|
||||
@@ -1085,7 +1085,7 @@ Decisions:
|
||||
**The differential tests still import the old libraries**, so they remain
|
||||
in `go.mod` after this task; their removal is Task 19.
|
||||
|
||||
- [ ] **Step 1: Write failing tests** in `protondrive_internal_test.go`:
|
||||
- [x] **Step 1: Write failing tests** in `protondrive_internal_test.go`:
|
||||
`TestTranslateError` table for every mapping above;
|
||||
`TestOptionsBackwardsCompatible`: a `configmap.Simple` holding exactly
|
||||
the keys of a v1.76 config (list in Global Constraints) builds an `Fs`
|
||||
@@ -1099,13 +1099,13 @@ Decisions:
|
||||
`TestConfigBrowser` and `TestConfigPassword`: drive `Config` through its
|
||||
states with `fs.ConfigIn` results; the browser state's text contains the
|
||||
third-party notice.
|
||||
- [ ] **Step 2: Run** - expect FAIL.
|
||||
- [ ] **Step 3: Rewrite `protondrive.go`.**
|
||||
- [ ] **Step 4: Run** `go test -race ./backend/protondrive/ -run TestIntegrationFake -v 2>&1 | tail -40`.
|
||||
- [x] **Step 2: Run** - expect FAIL.
|
||||
- [x] **Step 3: Rewrite `protondrive.go`.**
|
||||
- [x] **Step 4: Run** `go test -race ./backend/protondrive/ -run TestIntegrationFake -v 2>&1 | tail -40`.
|
||||
Fix failures in the new code (never by weakening the fake or skipping a
|
||||
test) until the suite passes. Then the four verification commands, and
|
||||
`go build ./...`.
|
||||
- [ ] **Step 5: Commit** `protondrive: rewrite the backend on a native client following Proton's SDK`.
|
||||
- [x] **Step 5: Commit** `protondrive: rewrite the backend on a native client following Proton's SDK`.
|
||||
|
||||
### Task 15: Regression tests for known failures
|
||||
|
||||
|
||||
Reference in new issue
Block a user