mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
Update to 8.3.2 | Read HISTORY.md file
Former-commit-id: e6ab761989d596cb004c39e65e04e8968d9461ab
This commit is contained in:
@@ -171,6 +171,53 @@ func TestControllerBeginAndEndRequestFunc(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerBeginAndEndRequestFuncBindMiddleware(t *testing.T) {
|
||||
app := iris.New()
|
||||
usernames := map[string]bool{
|
||||
"kataras": true,
|
||||
"makis": false,
|
||||
"efi": true,
|
||||
"rg": false,
|
||||
"bill": true,
|
||||
"whoisyourdaddy": false,
|
||||
}
|
||||
middlewareCheck := func(ctx context.Context) {
|
||||
for username, allow := range usernames {
|
||||
if ctx.Params().Get("username") == username && allow {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.StatusCode(httptest.StatusForbidden)
|
||||
ctx.Writef("forbidden")
|
||||
}
|
||||
|
||||
app.Controller("/profile/{username}", new(testControllerBeginAndEndRequestFunc), middlewareCheck)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
|
||||
doneResponse := "done"
|
||||
|
||||
for username, allow := range usernames {
|
||||
getEx := e.GET("/profile/" + username).Expect()
|
||||
if allow {
|
||||
getEx.Status(httptest.StatusOK).
|
||||
Body().Equal(username + doneResponse)
|
||||
} else {
|
||||
getEx.Status(httptest.StatusForbidden).Body().Equal("forbidden")
|
||||
}
|
||||
|
||||
postEx := e.POST("/profile/" + username).Expect()
|
||||
if allow {
|
||||
postEx.Status(httptest.StatusOK).
|
||||
Body().Equal(username + doneResponse)
|
||||
} else {
|
||||
postEx.Status(httptest.StatusForbidden).Body().Equal("forbidden")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
Username string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user