mirror of https://github.com/Xhofe/alist
fix: resolve webdav handshake error in permission checks
- Updated role permission logic to handle bidirectional subpaths, fixing handshake termination by remote host due to path mismatch. - Refactored function naming for consistency and clarity. - Enhanced filtering of objects based on user permissions. - Modified `makePropstatResponse` to preserve encoded href paths. - Added test for `makePropstatResponse` to ensure href encoding.pull/9268/head
parent
fcfb3369d1
commit
d72bc5c635
|
@ -0,0 +1,33 @@
|
|||
package webdav
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
)
|
||||
|
||||
func TestMakePropstatResponseKeepsEncodedHref(t *testing.T) {
|
||||
// Non-ASCII directory path
|
||||
dir := "/测试"
|
||||
href := utils.EncodePath(dir, true)
|
||||
ps := []Propstat{{Status: http.StatusOK}}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
mw := multistatusWriter{w: rec}
|
||||
if err := mw.write(makePropstatResponse(href, ps)); err != nil {
|
||||
t.Fatalf("write: %v", err)
|
||||
}
|
||||
if err := mw.close(); err != nil {
|
||||
t.Fatalf("close: %v", err)
|
||||
}
|
||||
if rec.Code != StatusMulti {
|
||||
t.Fatalf("status = %d, want %d", rec.Code, StatusMulti)
|
||||
}
|
||||
body := rec.Body.String()
|
||||
if !strings.Contains(body, "<D:href>"+href+"</D:href>") {
|
||||
t.Fatalf("href not preserved: got body %q", body)
|
||||
}
|
||||
}
|
|
@ -833,7 +833,7 @@ func (h *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) (statu
|
|||
|
||||
func makePropstatResponse(href string, pstats []Propstat) *response {
|
||||
resp := response{
|
||||
Href: []string{(&url.URL{Path: href}).EscapedPath()},
|
||||
Href: []string{href},
|
||||
Propstat: make([]propstat, 0, len(pstats)),
|
||||
}
|
||||
for _, p := range pstats {
|
||||
|
|
Loading…
Reference in New Issue