webdav: honour auth_redirect on listAll PROPFIND - fixes #9159
This commit is contained in:
committed by
Nick Craig-Wood
parent
7e08899a2c
commit
75773e4d72
@@ -796,6 +796,7 @@ func (f *Fs) listAll(ctx context.Context, dir string, directoriesOnly bool, file
|
|||||||
ExtraHeaders: map[string]string{
|
ExtraHeaders: map[string]string{
|
||||||
"Depth": depth,
|
"Depth": depth,
|
||||||
},
|
},
|
||||||
|
AuthRedirect: f.opt.AuthRedirect, // allow redirects to preserve Auth
|
||||||
}
|
}
|
||||||
if f.hasOCMD5 || f.hasOCSHA1 {
|
if f.hasOCMD5 || f.hasOCSHA1 {
|
||||||
opts.Body = bytes.NewBuffer(owncloudProps)
|
opts.Body = bytes.NewBuffer(owncloudProps)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/config/configfile"
|
"github.com/rclone/rclone/fs/config/configfile"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -81,6 +82,44 @@ func TestHeaders(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestListAllAuthRedirect checks auth_redirect is honoured on listAll PROPFIND.
|
||||||
|
func TestListAllAuthRedirect(t *testing.T) {
|
||||||
|
var targetAuth string
|
||||||
|
var targetHits int
|
||||||
|
|
||||||
|
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
targetHits++
|
||||||
|
targetAuth = r.Header.Get("Authorization")
|
||||||
|
_, err := fmt.Fprint(w, `<d:multistatus xmlns:d="DAV:"></d:multistatus>`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}))
|
||||||
|
defer target.Close()
|
||||||
|
|
||||||
|
// Redirect via a different hostname so net/http strips Authorization on cross-host redirect.
|
||||||
|
targetURL := strings.Replace(target.URL, "127.0.0.1", "localhost", 1)
|
||||||
|
source := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Redirect(w, r, targetURL+r.URL.Path, http.StatusTemporaryRedirect)
|
||||||
|
}))
|
||||||
|
defer source.Close()
|
||||||
|
|
||||||
|
configfile.Install()
|
||||||
|
m := configmap.Simple{
|
||||||
|
"type": "webdav",
|
||||||
|
"url": source.URL,
|
||||||
|
"user": "alice",
|
||||||
|
"pass": obscure.MustObscure("secret"),
|
||||||
|
"auth_redirect": "true",
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := webdav.NewFs(context.Background(), remoteName, "", m)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, _ = f.List(context.Background(), "")
|
||||||
|
|
||||||
|
assert.GreaterOrEqual(t, targetHits, 1, "redirect target should receive the request")
|
||||||
|
assert.NotEmpty(t, targetAuth, "Authorization header should be preserved across redirect")
|
||||||
|
}
|
||||||
|
|
||||||
// TestReservedCharactersInPathAreEscaped verifies that reserved characters
|
// TestReservedCharactersInPathAreEscaped verifies that reserved characters
|
||||||
// like semicolons and equals signs in file paths are percent-encoded in
|
// like semicolons and equals signs in file paths are percent-encoded in
|
||||||
// HTTP requests to the WebDAV server (RFC 3986 compliance).
|
// HTTP requests to the WebDAV server (RFC 3986 compliance).
|
||||||
|
|||||||
Reference in New Issue
Block a user