Skip to content

Commit 434f4d1

Browse files
committed
Fixed #990
Signed-off-by: Vishal Rana <[email protected]>
1 parent d174d65 commit 434f4d1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

middleware/csrf_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ func TestCSRFTokenFromQuery(t *testing.T) {
6969
q := make(url.Values)
7070
q.Set("csrf", "token")
7171
e := echo.New()
72-
req := httptest.NewRequest(echo.GET, "/?"+q.Encode(), nil)
72+
req := httptest.NewRequest(echo.GET, "/", nil)
7373
req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm)
74+
req.URL.RawQuery = q.Encode()
7475
c := e.NewContext(req, nil)
7576
token, err := csrfTokenFromQuery("csrf")(c)
7677
if assert.NoError(t, err) {

middleware/key_auth_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package middleware
33
import (
44
"net/http"
55
"net/http/httptest"
6+
"net/url"
7+
"strings"
68
"testing"
79

810
"github.com/labstack/echo"
@@ -12,8 +14,8 @@ import (
1214
func TestKeyAuth(t *testing.T) {
1315
e := echo.New()
1416
req := httptest.NewRequest(echo.GET, "/", nil)
15-
res := httptest.NewRecorder()
16-
c := e.NewContext(req, res)
17+
rec := httptest.NewRecorder()
18+
c := e.NewContext(req, rec)
1719
config := KeyAuthConfig{
1820
Validator: func(key string, c echo.Context) (bool, error) {
1921
return key == "valid-key", nil
@@ -56,4 +58,16 @@ func TestKeyAuth(t *testing.T) {
5658
q.Add("key", "valid-key")
5759
req.URL.RawQuery = q.Encode()
5860
assert.NoError(t, h(c))
61+
62+
// Key from form
63+
config.KeyLookup = "form:key"
64+
h = KeyAuthWithConfig(config)(func(c echo.Context) error {
65+
return c.String(http.StatusOK, "test")
66+
})
67+
f := make(url.Values)
68+
f.Set("key", "valid-key")
69+
req = httptest.NewRequest(echo.POST, "/", strings.NewReader(f.Encode()))
70+
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationForm)
71+
c = e.NewContext(req, rec)
72+
assert.NoError(t, h(c))
5973
}

0 commit comments

Comments
 (0)