fix(files): 服务器运行时下载文件的拒绝说明改为先停服再操作文件
This commit is contained in:
3 files changed
+8
-3
No files matched your search
@@ -582,7 +582,7 @@ func (a *API) handleDownloadFile(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, r, err)
|
||||
return
|
||||
}
|
||||
release, ok := a.acquireWorld(w, r, name, maintenance.KindExport, "stop the server before editing its files")
|
||||
release, ok := a.acquireWorld(w, r, name, maintenance.KindExport, "stop the server before downloading its files")
|
||||
if !ok {
|
||||
reg.drop(e)
|
||||
return
|
||||
|
||||
@@ -938,11 +938,13 @@ func TestFileDownloadGate(t *testing.T) {
|
||||
edit func(*API, *fakeCluster)
|
||||
code int
|
||||
errCode string
|
||||
// msg, when set, is what the refusal must say.
|
||||
msg string
|
||||
}{
|
||||
{name: "stranger", user: "stranger", query: "a.yml", code: http.StatusForbidden, errCode: "forbidden"},
|
||||
{name: "principal without an account", user: "nouser", query: "a.yml", code: http.StatusForbidden, errCode: "forbidden"},
|
||||
{name: "running", user: "owner1", query: "a.yml", edit: func(_ *API, c *fakeCluster) { c.byName["survival"].Ready = true },
|
||||
code: http.StatusConflict, errCode: "not_stopped"},
|
||||
code: http.StatusConflict, errCode: "not_stopped", msg: "stop the server before working with its files"},
|
||||
{name: "no world volume", user: "owner1", query: "a.yml", edit: func(_ *API, c *fakeCluster) { c.noWorld["survival"] = true },
|
||||
code: http.StatusConflict, errCode: "no_world_volume"},
|
||||
{name: "no file editor", user: "owner1", query: "a.yml", edit: func(a *API, _ *fakeCluster) { a.Files = nil },
|
||||
@@ -970,6 +972,9 @@ func TestFileDownloadGate(t *testing.T) {
|
||||
if got := decodeErr(t, w); got != tc.errCode {
|
||||
t.Errorf("error code = %q, want %q", got, tc.errCode)
|
||||
}
|
||||
if tc.msg != "" && !strings.Contains(w.Body.String(), tc.msg) {
|
||||
t.Errorf("body %s does not say %q", w.Body.String(), tc.msg)
|
||||
}
|
||||
// Nothing is left behind: no Job, no audit, no ticket, no start
|
||||
// counted against the hour.
|
||||
reg := a.exportTickets()
|
||||
|
||||
@@ -608,7 +608,7 @@ func (a *API) authorizeFileOp(w http.ResponseWriter, r *http.Request) (string, b
|
||||
}
|
||||
if info.Ready || info.DesiredState != string(v1alpha1.DesiredStopped) {
|
||||
writeError(w, r, newError(http.StatusConflict, "not_stopped",
|
||||
"stop the server before editing its files"))
|
||||
"stop the server before working with its files"))
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user