fix: path `IsApply` check (close #3784)

pull/3787/head
Andy Hsu 2023-03-09 21:03:56 +08:00
parent 02d0aef611
commit 43de823058
2 changed files with 25 additions and 1 deletions

View File

@ -20,7 +20,7 @@ func IsApply(metaPath, reqPath string, applySub bool) bool {
if utils.PathEqual(metaPath, reqPath) {
return true
}
return utils.IsSubPath(reqPath, metaPath) && applySub
return utils.IsSubPath(metaPath, reqPath) && applySub
}
func CanAccess(user *model.User, meta *model.Meta, reqPath string, password string) bool {

View File

@ -0,0 +1,24 @@
package common
import "testing"
func TestIsApply(t *testing.T) {
datas := []struct {
metaPath string
reqPath string
applySub bool
result bool
}{
{
metaPath: "/",
reqPath: "/test",
applySub: true,
result: true,
},
}
for i, data := range datas {
if IsApply(data.metaPath, data.reqPath, data.applySub) != data.result {
t.Errorf("TestIsApply %d failed", i)
}
}
}