build / windows (push) Skipped
build / other_os (push) Skipped
build / mac_amd64 (push) Skipped
build / mac_arm64 (push) Skipped
build / linux (push) Skipped
build / go1.26 (push) Skipped
build / linux_386 (push) Skipped
build / lint (push) Skipped
build / android-all (push) Skipped
Build & Push Docker Images / Build Docker Image for linux/386 (push) Skipped
Build & Push Docker Images / Build Docker Image for linux/amd64 (push) Skipped
Build & Push Docker Images / Build Docker Image for linux/arm/v6 (push) Skipped
Build & Push Docker Images / Build Docker Image for linux/arm/v7 (push) Skipped
Build & Push Docker Images / Build Docker Image for linux/arm64 (push) Skipped
Build & Push Docker Images / Merge & Push Final Docker Image (push) Waiting for needed jobs
Replace Proton-API-Bridge and go-proton-api with a client in backend/protondrive written against Proton's current Drive API, following the behaviour of Proton's official Drive SDK: - volume-based and v2 routes only - upload block verification, signed manifests and extended attributes - current content encryption (v4 node keys, v6 PKESK, SEIPDv2) - browser (session fork) sign-in, with username and password still supported - the volume's change events, used to keep the metadata cache current and for ChangeNotify, polled at most every 30 s - an in-memory fake Proton server (protontest) so the tests run without an account Uses ProtonMail/gopenpgp/v3 and ProtonMail/go-srp directly; no cgo. Written with heavy AI assistance (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.6 KiB
Go
89 lines
3.6 KiB
Go
package protondrive_test
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/rclone/rclone/backend/protondrive"
|
|
"github.com/rclone/rclone/backend/protondrive/api"
|
|
"github.com/rclone/rclone/backend/protondrive/protontest"
|
|
"github.com/rclone/rclone/fstest"
|
|
"github.com/rclone/rclone/fstest/fstests"
|
|
"github.com/rclone/rclone/lib/random"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// fakeEnvPrefix starts the environment variables configuring the
|
|
// TestProtonDriveFake: remote.
|
|
const fakeEnvPrefix = "RCLONE_CONFIG_TESTPROTONDRIVEFAKE_"
|
|
|
|
// setupFakeRemote starts a fake Proton server with one user and
|
|
// configures the TestProtonDriveFake: remote, through environment
|
|
// variables, with a saved session of that user. It polls events every
|
|
// second, as the remote protonfake configures does.
|
|
func setupFakeRemote(t *testing.T) (remoteName string, srv *protontest.Server, user *protontest.User) {
|
|
srv = protontest.New(t)
|
|
user = srv.AddUser("user", "pass")
|
|
sess := srv.NewSession(user)
|
|
t.Setenv(fakeEnvPrefix+"TYPE", "protondrive")
|
|
t.Setenv(fakeEnvPrefix+"ENDPOINT", srv.URL())
|
|
t.Setenv(fakeEnvPrefix+"CLIENT_UID", sess.UID)
|
|
t.Setenv(fakeEnvPrefix+"CLIENT_ACCESS_TOKEN", sess.AccessToken)
|
|
t.Setenv(fakeEnvPrefix+"CLIENT_REFRESH_TOKEN", sess.RefreshToken)
|
|
// The config holds the salted key password base64 encoded.
|
|
t.Setenv(fakeEnvPrefix+"CLIENT_SALTED_KEY_PASS", base64.StdEncoding.EncodeToString([]byte(user.KeyPassword())))
|
|
t.Setenv(fakeEnvPrefix+"DRAFT_CLIENT_UID", random.String(32))
|
|
t.Setenv(fakeEnvPrefix+"EVENTS_MIN_INTERVAL", "1s")
|
|
return "TestProtonDriveFake:", srv, user
|
|
}
|
|
|
|
// TestSetupFakeRemote checks the configured session is accepted by the
|
|
// fake server.
|
|
func TestSetupFakeRemote(t *testing.T) {
|
|
remoteName, srv, user := setupFakeRemote(t)
|
|
assert.Equal(t, "TestProtonDriveFake:", remoteName)
|
|
assert.Equal(t, "protondrive", os.Getenv(fakeEnvPrefix+"TYPE"))
|
|
assert.Equal(t, srv.URL(), os.Getenv(fakeEnvPrefix+"ENDPOINT"))
|
|
assert.NotEmpty(t, os.Getenv(fakeEnvPrefix+"DRAFT_CLIENT_UID"))
|
|
keyPass, err := base64.StdEncoding.DecodeString(os.Getenv(fakeEnvPrefix + "CLIENT_SALTED_KEY_PASS"))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, user.KeyPassword(), string(keyPass))
|
|
require.NotEmpty(t, os.Getenv(fakeEnvPrefix+"CLIENT_REFRESH_TOKEN"))
|
|
|
|
req, err := http.NewRequest("GET", os.Getenv(fakeEnvPrefix+"ENDPOINT")+"/core/v4/users", nil)
|
|
require.NoError(t, err)
|
|
req.Header.Set("x-pm-appversion", "external-drive-rclone@1.0.0-stable")
|
|
req.Header.Set("x-pm-uid", os.Getenv(fakeEnvPrefix+"CLIENT_UID"))
|
|
req.Header.Set("Authorization", "Bearer "+os.Getenv(fakeEnvPrefix+"CLIENT_ACCESS_TOKEN"))
|
|
resp, err := srv.Client().Do(req)
|
|
require.NoError(t, err)
|
|
_ = resp.Body.Close()
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
}
|
|
|
|
// TestIntegrationFake runs integration tests against the fake server.
|
|
func TestIntegrationFake(t *testing.T) {
|
|
if *fstest.RemoteName != "" {
|
|
t.Skip("skipping as -remote is set")
|
|
}
|
|
remoteName, srv, _ := setupFakeRemote(t)
|
|
t.Cleanup(func() {
|
|
// fstests leaves Fs of the remote behind which go on polling
|
|
// events, and logging, into later tests. Gone, the volume
|
|
// stops them for good before the server closes.
|
|
for _, pattern := range []string{"/drive/volumes/{volumeID}/events/latest", "/drive/v2/volumes/{volumeID}/events/{eventID}"} {
|
|
srv.Inject(protontest.Fault{Pattern: pattern, Status: http.StatusUnprocessableEntity, Code: api.CodeNotExists})
|
|
}
|
|
time.Sleep(3 * time.Second) // an interval of 1s, up to 1s of jitter, and slack
|
|
})
|
|
fstests.Run(t, &fstests.Opt{
|
|
RemoteName: remoteName,
|
|
NilObject: (*protondrive.Object)(nil),
|
|
QuickTestOK: true,
|
|
})
|
|
}
|