Fix 4590: Forget to check URL when FilterChain invoke next()
This commit is contained in:
parent
4df8804f5c
commit
e9df040142
@ -15,16 +15,18 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/beego/beego/v2/server/web/context"
|
||||
)
|
||||
|
||||
func TestControllerRegister_InsertFilterChain(t *testing.T) {
|
||||
func TestControllerRegisterInsertFilterChain(t *testing.T) {
|
||||
|
||||
InsertFilterChain("/*", func(next FilterFunc) FilterFunc {
|
||||
return func(ctx *context.Context) {
|
||||
@ -46,3 +48,24 @@ func TestControllerRegister_InsertFilterChain(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "filter-chain", w.Header().Get("filter"))
|
||||
}
|
||||
|
||||
func TestFilterChainRouter(t *testing.T) {
|
||||
InsertFilterChain("/app/hello1/*", func(next FilterFunc) FilterFunc {
|
||||
return func(ctx *context.Context) {
|
||||
logs.Info("aaa")
|
||||
next(ctx)
|
||||
}
|
||||
})
|
||||
|
||||
InsertFilterChain("/app/*", func(next FilterFunc) FilterFunc {
|
||||
return func(ctx *context.Context) {
|
||||
start := time.Now()
|
||||
ctx.Input.SetData("start", start)
|
||||
logs.Info("start_time", start)
|
||||
next(ctx)
|
||||
logs.Info("run_time", time.Since(start).String())
|
||||
}
|
||||
})
|
||||
|
||||
Run()
|
||||
}
|
||||
|
||||
@ -486,7 +486,11 @@ func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter Filter
|
||||
// }
|
||||
func (p *ControllerRegister) InsertFilterChain(pattern string, chain FilterChain, opts ...FilterOpt) {
|
||||
root := p.chainRoot
|
||||
filterFunc := chain(root.filterFunc)
|
||||
//filterFunc := chain(root.filterFunc)
|
||||
filterFunc := chain(func(ctx *beecontext.Context) {
|
||||
var preFilterParams map[string]string
|
||||
root.filter(ctx, p.getUrlPath(ctx), preFilterParams)
|
||||
})
|
||||
opts = append(opts, WithCaseSensitive(p.cfg.RouterCaseSensitive))
|
||||
p.chainRoot = newFilterRouter(pattern, filterFunc, opts...)
|
||||
p.chainRoot.next = root
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user