This commit is contained in:
Wenkai Yin 2017-07-31 13:58:41 +08:00
parent cdb75519a9
commit 67200db678
2 changed files with 0 additions and 42 deletions

View File

@ -50,11 +50,6 @@ const (
var (
reqCtxModifiers []ReqCtxModifier
// the pattern needs security filter
reqPatterns = []string{
"/api/",
"/service/",
}
// basic auth request context modifier only takes effect on the patterns
// in the slice
basicAuthReqPatterns = []*pathMethod{
@ -113,11 +108,6 @@ func SecurityFilter(ctx *beegoctx.Context) {
return
}
if !filterReq(req) {
log.Debugf("%s doesn't match security filter pattern, skip", req.URL.Path)
return
}
// add security context and project manager to request context
for _, modifier := range reqCtxModifiers {
if modifier.Modify(ctx) {
@ -126,21 +116,6 @@ func SecurityFilter(ctx *beegoctx.Context) {
}
}
func filterReq(req *http.Request) bool {
path := req.URL.Path
for _, pattern := range reqPatterns {
match, err := regexp.MatchString(pattern, path)
if err != nil {
log.Errorf("failed to match %s with pattern %s", path, pattern)
continue
}
if match {
return true
}
}
return false
}
// ReqCtxModifier modifies the context of request
type ReqCtxModifier interface {
Modify(*beegoctx.Context) bool

View File

@ -322,20 +322,3 @@ func TestGetProjectManager(t *testing.T) {
_, ok := pm.(projectmanager.ProjectManager)
assert.True(t, ok)
}
func TestFilterReq(t *testing.T) {
cases := []struct {
path string
result bool
}{
{"http://server/api/", true},
{"http://server/service/", true},
{"http://server/registryproxy/v2/", false},
}
for _, c := range cases {
req, err := http.NewRequest(http.MethodGet, c.path, nil)
assert.Nil(t, err)
assert.Equal(t, c.result, filterReq(req))
}
}