mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
update
This commit is contained in:
parent
cdb75519a9
commit
67200db678
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user