Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

seafile: fix double slash in the URL when getting a 2FA token

Nick Craig-Wood2fc95aef84d6
diff --git a/backend/seafile/seafile.go b/backend/seafile/seafile.go
index 26bcd25a4..b22564471 100644
--- a/backend/seafile/seafile.go
+++ b/backend/seafile/seafile.go
@@ -370,7 +370,7 @@ func Config(ctx context.Context, name string, m configmap.Mapper, config fs.Conf
// Create rest client for getAuthorizationToken
url := u.String()
- if !strings.HasPrefix(url, "/") {
+ if !strings.HasSuffix(url, "/") {
url += "/"
}
srv := rest.NewClient(newClient(ctx)).SetRoot(url)
diff --git a/backend/seafile/seafile_internal_test.go b/backend/seafile/seafile_internal_test.go
index 51c0bd7de..e6b1167e0 100644
--- a/backend/seafile/seafile_internal_test.go
+++ b/backend/seafile/seafile_internal_test.go
@@ -297,6 +297,27 @@ func TestUploadErrorReleasesSource(t *testing.T) {
// field names of the authentication request.
const testPassword = "s3cret-pass-4242"
+// Test2FAGetToken checks the 2FA config flow posts the credentials to
+// the auth token endpoint without doubling the slash when the
+// configured URL ends in one, and saves the token it gets back.
+func Test2FAGetToken(t *testing.T) {
+ var gotPath string
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ gotPath = r.URL.Path
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"token":"token123"}`))
+ }))
+ defer srv.Close()
+
+ m := configmap.Simple{"url": srv.URL + "/", "2fa": "true", "user": "username", "pass": obscure.MustObscure(testPassword)}
+ out, err := Config(context.Background(), "test", m, fs.ConfigIn{State: "2fa_do", Result: "123456"})
+ require.NoError(t, err)
+ assert.Nil(t, out)
+ assert.Equal(t, "/api2/auth-token/", gotPath)
+ assert.Equal(t, "token123", m["auth_token"])
+ assert.Equal(t, "", m["pass"])
+}
+
// newDowngradeServers returns an HTTPS server which answers the server
// info request itself and redirects every other request to a plaintext
// HTTP server on the same machine. The returned flags record whether