fix(files): sharing root folder is not allowed
This commit is contained in:
parent
0db1903e42
commit
9ff28ecce4
3 changed files with 30 additions and 1 deletions
|
@ -929,7 +929,21 @@ func (h *FileHandlers) AddSharing(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := h.deps.FileInfos().AddSharing(req.SharingPath)
|
if req.SharingPath == "" || req.SharingPath == "/" {
|
||||||
|
c.JSON(q.ErrResp(c, 403, errors.New("forbidden")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := h.deps.FS().Stat(req.SharingPath)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(q.ErrResp(c, 500, err))
|
||||||
|
return
|
||||||
|
} else if !info.IsDir() {
|
||||||
|
c.JSON(q.ErrResp(c, 400, errors.New("can not sharing a file")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.deps.FileInfos().AddSharing(req.SharingPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(q.ErrResp(c, 500, err))
|
c.JSON(q.ErrResp(c, 500, err))
|
||||||
return
|
return
|
||||||
|
|
|
@ -441,6 +441,21 @@ func TestFileHandlers(t *testing.T) {
|
||||||
} else if res.StatusCode != 200 {
|
} else if res.StatusCode != 200 {
|
||||||
t.Fatal(res.StatusCode)
|
t.Fatal(res.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res, _, errs = cl.AddSharing(filePath)
|
||||||
|
if res.StatusCode != 400 {
|
||||||
|
t.Fatal(res.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, _, errs = cl.AddSharing(filepath.Join(filePath, "not_exist"))
|
||||||
|
if res.StatusCode != 500 {
|
||||||
|
t.Fatal(res.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res, _, errs := cl.AddSharing("/")
|
||||||
|
if res.StatusCode != 403 {
|
||||||
|
t.Fatal(res.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check listSharings
|
// check listSharings
|
||||||
|
|
BIN
src/server/testdata/test_quickshare.db
vendored
BIN
src/server/testdata/test_quickshare.db
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue