From 43de82305887d0d32b05222b7e522ec6fd2ff68c Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Thu, 9 Mar 2023 21:03:56 +0800 Subject: [PATCH] fix: path `IsApply` check (close #3784) --- server/common/check.go | 2 +- server/common/check_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 server/common/check_test.go diff --git a/server/common/check.go b/server/common/check.go index 787dd2f5..84479ad2 100644 --- a/server/common/check.go +++ b/server/common/check.go @@ -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 { diff --git a/server/common/check_test.go b/server/common/check_test.go new file mode 100644 index 00000000..33114603 --- /dev/null +++ b/server/common/check_test.go @@ -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) + } + } +}