1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-03 00:56:59 +02:00

Fixed basic auth middleware, closes #799

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2017-01-05 12:12:31 -08:00
parent bf317578d7
commit 4cbef06bef
3 changed files with 7 additions and 15 deletions

View File

@ -15,7 +15,7 @@ func TestBasicAuth(t *testing.T) {
req, _ := http.NewRequest(echo.GET, "/", nil)
res := httptest.NewRecorder()
c := e.NewContext(req, res)
f := func(u, p string) bool {
f := func(u, p string, c echo.Context) bool {
if u == "joe" && p == "secret" {
return true
}
@ -40,11 +40,11 @@ func TestBasicAuth(t *testing.T) {
// Missing Authorization header
req.Header.Del(echo.HeaderAuthorization)
he = h(c).(*echo.HTTPError)
assert.Equal(t, http.StatusBadRequest, he.Code)
assert.Equal(t, http.StatusUnauthorized, he.Code)
// Invalid Authorization header
auth = base64.StdEncoding.EncodeToString([]byte("invalid"))
req.Header.Set(echo.HeaderAuthorization, auth)
he = h(c).(*echo.HTTPError)
assert.Equal(t, http.StatusBadRequest, he.Code)
assert.Equal(t, http.StatusUnauthorized, he.Code)
}