davsync: a 403 on the write names the folder it went to, and a full quota (#4927)
The error for a write the server refused, with the address's folder listing fine, said the account couldn't write in that folder (/dav) - but the write went to magpie's own folder inside it, and the listing never proved anything about writing. On 坚果云 (Nutstore) the refusal is usually the free tier's upload quota used up, which answers 403 on a PUT with everything else fine (#4927), so the old text sent the user to check a thing they can't check. The error now looks at magpie's own folder first: there, the server refused to change files in it, and the text says so and mentions the quota; missing, the server refused to have magpie make it, and the text says to make the folder by hand, or put an existing folder in the address. Review, changed from ggbdpq's patch: the folder is named with path.Join(dir, folder). The patch's dir+"/"+folder said "//magpie" for an address with no folder of its own (dir "/"). The test now covers that address too. Broken by hand at the reviewed head: dir+"/"+folder back, TestDAVWriteRefused red; dav.go reverted to its parent, red; restored, green. Run at the pushed tree (this stack of nine on origin/main3c2dceb34), on mote (macOS arm64, Go 1.26.8): - go test -count=1 -timeout 45m ./internal/catalog/... ./internal/plugin/... ./internal/davsync/... ./internal/gateway/...: catalog, plugin and davsync ok; gateway red on one test only, TestCodexPoolSaysTheClientsVersion, the open #4807 (another test's Codex identity reaches it in a full package run). It passes run alone at this tree, 3 of 3. - go vet ./... (darwin); GOOS=linux and GOOS=windows go vet -tags nogui ./...: ok. gofmt -l on every tracked .go file: clean. - The hand breaks above ran on this stack before its rebase onto3c2dceb34. That commit changed member.go only, nothing these tests reach. Not tried: the GUI suite, since no GUI file changed. Windows and Linux test runs (the Claude bridge tests use a shell fake and skip on Windows). No real vendor, Claude Code or network was used; every case runs against fakes. Generated-by: GLM-5.3-Flash (ZCode)
This commit is contained in:
+12
-2
@@ -201,7 +201,8 @@ var errLogin = errors.New("the WebDAV server refused the user name or password (
|
||||
|
||||
// forbidden says why a 403 was: servers answer it for a folder that isn't
|
||||
// there as much as for one the account may not use — a Synology does for a
|
||||
// shared folder not made — so the folder in the address is looked at first.
|
||||
// shared folder not made — so the folder in the address is looked at first,
|
||||
// and then magpie's own folder inside it, where the write went.
|
||||
func (d *dav) forbidden(ctx context.Context) error {
|
||||
dir := d.base.Path
|
||||
if dir == "" {
|
||||
@@ -221,7 +222,16 @@ func (d *dav) forbidden(ctx context.Context) error {
|
||||
case res.StatusCode == http.StatusNotFound || res.StatusCode == http.StatusConflict || res.StatusCode == http.StatusGone:
|
||||
return fmt.Errorf("there is no folder %s on the WebDAV server (HTTP 403): make it there first, or leave it out of the address", dir)
|
||||
case res.StatusCode >= 200 && res.StatusCode < 300:
|
||||
return fmt.Errorf("the WebDAV server doesn't let this account write in %s (HTTP 403): check the account may change files in that folder", dir)
|
||||
// the address's folder lists fine, so the refusal is about
|
||||
// magpie's own folder inside it, where the write went: the
|
||||
// server may have kept the account from making it, or, with
|
||||
// it there, from changing files in it — 坚果云 (Nutstore)'s
|
||||
// free tier refuses writes with 403 once the account's
|
||||
// upload quota is used up (#4927)
|
||||
if !d.there(ctx, d.url(folder)+"/") {
|
||||
return fmt.Errorf("the WebDAV server doesn't let magpie make its folder %s (HTTP 403): make the folder %s there first, or put an existing folder in the address", pathpkg.Join(dir, folder), folder)
|
||||
}
|
||||
return fmt.Errorf("the WebDAV server doesn't let this account change files in %s (HTTP 403): check the account may change files in that folder, and the account's storage quota is not used up", pathpkg.Join(dir, folder))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestDAVForbidden(t *testing.T) {
|
||||
}
|
||||
path := strings.TrimSuffix(r.URL.Path, "/")
|
||||
switch {
|
||||
case r.Method == "PROPFIND" && (path == "" || path == "/ro"):
|
||||
case r.Method == "PROPFIND" && (path == "" || path == "/ro" || path == "/ro/magpie"):
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
case r.Method == "PROPFIND" && path == "/missing":
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
@@ -35,8 +35,10 @@ func TestDAVForbidden(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, c := range []struct{ dir, pass, want string }{
|
||||
{"/missing", "pw", "there is no folder /missing"},
|
||||
{"/ro", "pw", "doesn't let this account write in /ro"},
|
||||
{"/ro", "pw", "doesn't let this account change files in /ro/magpie"},
|
||||
{"/secret", "pw", "doesn't let this account use /secret"},
|
||||
// the server's root in the address: its folder is /magpie, not //magpie
|
||||
{"", "pw", "doesn't let magpie make its folder /magpie ("},
|
||||
{"/missing", "bad", "user name or password"},
|
||||
} {
|
||||
d, err := newDAV(Config{URL: srv.URL + c.dir, User: "me", Password: c.pass})
|
||||
@@ -53,6 +55,73 @@ func TestDAVForbidden(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A 403 on the write itself, with everything listing fine, is told apart by
|
||||
// magpie's own folder: there, the server refuses to change files in it —
|
||||
// 坚果云 (Nutstore)'s free tier refuses writes with 403 once the account's
|
||||
// upload quota is used up (#4927) — and the error names the folder the write
|
||||
// went to, not just the address's, and says the quota. Missing, the server
|
||||
// refused to have magpie make it, and the error says to make it by hand.
|
||||
func TestDAVWriteRefused(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
refuse := func(statusOf func(r *http.Request) int) *dav {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(statusOf(r))
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
d, err := newDAV(Config{URL: srv.URL + "/dav/"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// the folder is there (an earlier sync made it), the write is refused
|
||||
d := refuse(func(r *http.Request) int {
|
||||
switch {
|
||||
case r.Method == "PROPFIND" && (r.URL.Path == "/dav/" || r.URL.Path == "/dav/magpie/"):
|
||||
return http.StatusMultiStatus
|
||||
default:
|
||||
return http.StatusForbidden
|
||||
}
|
||||
})
|
||||
if _, err := d.put(ctx, []byte("x"), ""); err == nil || !strings.Contains(err.Error(), "change files in /dav/magpie") || !strings.Contains(err.Error(), "quota") {
|
||||
t.Fatalf("a refused write into the folder there: %v", err)
|
||||
}
|
||||
|
||||
// the folder isn't there, and the server refuses to have magpie make it
|
||||
d = refuse(func(r *http.Request) int {
|
||||
switch {
|
||||
case r.Method == "PROPFIND" && r.URL.Path == "/dav/":
|
||||
return http.StatusMultiStatus
|
||||
case r.Method == "MKCOL":
|
||||
return http.StatusForbidden
|
||||
default:
|
||||
return http.StatusConflict
|
||||
}
|
||||
})
|
||||
if _, err := d.put(ctx, []byte("x"), ""); err == nil || !strings.Contains(err.Error(), "doesn't let magpie make its folder /dav/magpie") || !strings.Contains(err.Error(), "make the folder magpie there first") {
|
||||
t.Fatalf("a refused folder: %v", err)
|
||||
}
|
||||
|
||||
// an address with no folder of its own: magpie's is at the root,
|
||||
// named once, not "//magpie"
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "PROPFIND" && (r.URL.Path == "/" || r.URL.Path == "/magpie/") {
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
d, err := newDAV(Config{URL: srv.URL})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := d.put(ctx, []byte("x"), ""); err == nil || !strings.Contains(err.Error(), "change files in /magpie ") || strings.Contains(err.Error(), "//") {
|
||||
t.Fatalf("a refused write under an address with no folder: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenList's and Alist's /dav/ lists their storages: a folder can't be made
|
||||
// there (MKCOL 405, as if it were) and a file can't be put (404). The error
|
||||
// says to put a storage in the address, naming them.
|
||||
|
||||
Reference in New Issue
Block a user