mirror of https://github.com/cloudreve/Cloudreve
Fix: able to upload empty file
parent
948059ec1c
commit
671d031d00
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
func TestFileSystem_AddFile(t *testing.T) {
|
func TestFileSystem_AddFile(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
file := local.FileData{
|
file := local.FileStream{
|
||||||
Size: 5,
|
Size: 5,
|
||||||
Name: "1.txt",
|
Name: "1.txt",
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
func TestGenericBeforeUpload(t *testing.T) {
|
func TestGenericBeforeUpload(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
file := local.FileData{
|
file := local.FileStream{
|
||||||
Size: 5,
|
Size: 5,
|
||||||
Name: "1.txt",
|
Name: "1.txt",
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,18 @@ func (fs *FileSystem) ValidateLegalName(ctx context.Context, name string) bool {
|
||||||
if len(name) >= 256 {
|
if len(name) >= 256 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否为空限制
|
||||||
|
if len(name) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateFileSize 验证上传的文件大小是否超出限制
|
// ValidateFileSize 验证上传的文件大小是否超出限制
|
||||||
func (fs *FileSystem) ValidateFileSize(ctx context.Context, size uint64) bool {
|
func (fs *FileSystem) ValidateFileSize(ctx context.Context, size uint64) bool {
|
||||||
return size <= fs.User.Policy.MaxSize
|
return size <= fs.User.Policy.MaxSize && size != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateCapacity 验证并扣除用户容量
|
// ValidateCapacity 验证并扣除用户容量
|
||||||
|
|
|
@ -36,6 +36,7 @@ func TestFileSystem_ValidateLegalName(t *testing.T) {
|
||||||
asserts.False(fs.ValidateLegalName(ctx, "../11.txt"))
|
asserts.False(fs.ValidateLegalName(ctx, "../11.txt"))
|
||||||
asserts.False(fs.ValidateLegalName(ctx, "/11.txt"))
|
asserts.False(fs.ValidateLegalName(ctx, "/11.txt"))
|
||||||
asserts.False(fs.ValidateLegalName(ctx, "\\11.txt"))
|
asserts.False(fs.ValidateLegalName(ctx, "\\11.txt"))
|
||||||
|
asserts.False(fs.ValidateLegalName(ctx, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileSystem_ValidateCapacity(t *testing.T) {
|
func TestFileSystem_ValidateCapacity(t *testing.T) {
|
||||||
|
@ -72,6 +73,7 @@ func TestFileSystem_ValidateFileSize(t *testing.T) {
|
||||||
asserts.True(fs.ValidateFileSize(ctx, 5))
|
asserts.True(fs.ValidateFileSize(ctx, 5))
|
||||||
asserts.True(fs.ValidateFileSize(ctx, 10))
|
asserts.True(fs.ValidateFileSize(ctx, 10))
|
||||||
asserts.False(fs.ValidateFileSize(ctx, 11))
|
asserts.False(fs.ValidateFileSize(ctx, 11))
|
||||||
|
asserts.False(fs.ValidateFileSize(ctx, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileSystem_ValidateExtension(t *testing.T) {
|
func TestFileSystem_ValidateExtension(t *testing.T) {
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package serializer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCheckSettingValue(t *testing.T) {
|
||||||
|
asserts := assert.New(t)
|
||||||
|
|
||||||
|
asserts.Equal("", checkSettingValue(map[string]string{}, "key"))
|
||||||
|
asserts.Equal("123", checkSettingValue(map[string]string{"key": "123"}, "key"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildSiteConfig(t *testing.T) {
|
||||||
|
asserts := assert.New(t)
|
||||||
|
|
||||||
|
res := BuildSiteConfig(map[string]string{"not exist": ""})
|
||||||
|
asserts.Equal("", res.Data.(SiteConfig).SiteName)
|
||||||
|
|
||||||
|
res = BuildSiteConfig(map[string]string{"siteName": "123"})
|
||||||
|
asserts.Equal("123", res.Data.(SiteConfig).SiteName)
|
||||||
|
|
||||||
|
res = BuildSiteConfig(map[string]string{"qq_login": "1"})
|
||||||
|
asserts.Equal(true, res.Data.(SiteConfig).QQLogin)
|
||||||
|
}
|
|
@ -50,7 +50,7 @@ func InitRouter() *gin.Engine {
|
||||||
auth := v3.Group("")
|
auth := v3.Group("")
|
||||||
auth.Use(middleware.AuthRequired())
|
auth.Use(middleware.AuthRequired())
|
||||||
{
|
{
|
||||||
// 用户类
|
// 用户
|
||||||
user := auth.Group("User")
|
user := auth.Group("User")
|
||||||
{
|
{
|
||||||
// 当前登录用户信息
|
// 当前登录用户信息
|
||||||
|
@ -64,6 +64,13 @@ func InitRouter() *gin.Engine {
|
||||||
file.POST("Upload", controllers.FileUploadStream)
|
file.POST("Upload", controllers.FileUploadStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 目录
|
||||||
|
directory := auth.Group("Directory")
|
||||||
|
{
|
||||||
|
// 文件上传
|
||||||
|
directory.PUT("", controllers.Ping)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue