mirror of
https://github.com/labstack/echo.git
synced 2025-12-05 23:08:17 +02:00
@@ -19,7 +19,6 @@ func BasicAuth(fn AuthFunc) echo.HandlerFunc {
|
|||||||
return func(c *echo.Context) (he *echo.HTTPError) {
|
return func(c *echo.Context) (he *echo.HTTPError) {
|
||||||
auth := c.Request.Header.Get(echo.Authorization)
|
auth := c.Request.Header.Get(echo.Authorization)
|
||||||
i := 0
|
i := 0
|
||||||
l := len(Basic)
|
|
||||||
he = &echo.HTTPError{Code: http.StatusUnauthorized}
|
he = &echo.HTTPError{Code: http.StatusUnauthorized}
|
||||||
|
|
||||||
for ; i < len(auth); i++ {
|
for ; i < len(auth); i++ {
|
||||||
@@ -30,7 +29,7 @@ func BasicAuth(fn AuthFunc) echo.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check scheme
|
// Check scheme
|
||||||
if i < l {
|
if i < len(Basic) {
|
||||||
// Ignore case
|
// Ignore case
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if c != Basic[i] && c != 'b' {
|
if c != Basic[i] && c != 'b' {
|
||||||
|
|||||||
@@ -49,10 +49,16 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invalid scheme
|
// Invalid scheme
|
||||||
auth = "foo " + base64.StdEncoding.EncodeToString([]byte(" joe: secret"))
|
auth = "Base " + base64.StdEncoding.EncodeToString([]byte(" :secret"))
|
||||||
req.Header.Set(echo.Authorization, auth)
|
req.Header.Set(echo.Authorization, auth)
|
||||||
b = BasicAuth(fn)
|
b = BasicAuth(fn)
|
||||||
if b(c) == nil {
|
if b(c) == nil {
|
||||||
t.Error("basic auth should fail for invalid scheme")
|
t.Error("basic auth should fail for invalid scheme")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty auth header
|
||||||
|
b = BasicAuth(fn)
|
||||||
|
if b(c) == nil {
|
||||||
|
t.Error("basic auth should fail for empty auth header")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user