mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
Updated auth test
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
cccaa1ee26
commit
0da05cb7f2
@ -19,7 +19,6 @@ func BasicAuth(fn AuthFunc) echo.HandlerFunc {
|
||||
return func(c *echo.Context) (he *echo.HTTPError) {
|
||||
auth := c.Request.Header.Get(echo.Authorization)
|
||||
i := 0
|
||||
l := len(Basic)
|
||||
he = &echo.HTTPError{Code: http.StatusUnauthorized}
|
||||
|
||||
for ; i < len(auth); i++ {
|
||||
@ -30,7 +29,7 @@ func BasicAuth(fn AuthFunc) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
// Check scheme
|
||||
if i < l {
|
||||
if i < len(Basic) {
|
||||
// Ignore case
|
||||
if i == 0 {
|
||||
if c != Basic[i] && c != 'b' {
|
||||
|
@ -49,10 +49,16 @@ func TestBasicAuth(t *testing.T) {
|
||||
}
|
||||
|
||||
// Invalid scheme
|
||||
auth = "foo " + base64.StdEncoding.EncodeToString([]byte(" joe: secret"))
|
||||
auth = "Base " + base64.StdEncoding.EncodeToString([]byte(" :secret"))
|
||||
req.Header.Set(echo.Authorization, auth)
|
||||
b = BasicAuth(fn)
|
||||
if b(c) == nil {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user