Chore: Imperative request data binding (#39837)

* rename Bind to BindMiddleware

* make things private

* removed unused part of data bindings

* provide json and form binding helpers

* add example of binding migration in login api

* implement validation

* fix tests

* remove debug output

* put new bind api into macaron pacakge

* revert bind api breaking change
This commit is contained in:
Serge Zaitsev
2021-10-06 12:52:27 +02:00
committed by GitHub
parent 7fd7c98540
commit 3131388084
6 changed files with 225 additions and 129 deletions

View File

@ -1,9 +1,11 @@
package api
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
@ -336,11 +338,9 @@ func TestLoginPostRedirect(t *testing.T) {
hs.Cfg.CookieSecure = true
sc.defaultHandler = routing.Wrap(func(w http.ResponseWriter, c *models.ReqContext) response.Response {
cmd := dtos.LoginCommand{
User: "admin",
Password: "admin",
}
return hs.LoginPost(c, cmd)
c.Req.Header.Set("Content-Type", "application/json")
c.Req.Body = io.NopCloser(bytes.NewBufferString(`{"user":"admin","password":"admin"}`))
return hs.LoginPost(c)
})
bus.AddHandler("grafana-auth", func(query *models.LoginUserQuery) error {
@ -614,11 +614,10 @@ func TestLoginPostRunLokingHook(t *testing.T) {
}
sc.defaultHandler = routing.Wrap(func(w http.ResponseWriter, c *models.ReqContext) response.Response {
cmd := dtos.LoginCommand{
User: "admin",
Password: "admin",
}
return hs.LoginPost(c, cmd)
c.Req.Header.Set("Content-Type", "application/json")
c.Req.Body = io.NopCloser(bytes.NewBufferString(`{"user":"admin","password":"admin"}`))
x := hs.LoginPost(c)
return x
})
testHook := loginHookTest{}