Auth: change the error HTTP status codes (#18584)
* Auth: change the error HTTP status codes * Use 407 HTTP status code for incorrect credentials error * Improve proxy auth logs * Remove no longer needed TODO comment Fixes #18439
This commit is contained in:
@@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"context"
|
||||
"encoding/base32"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
@@ -374,7 +375,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
sc.exec()
|
||||
|
||||
assert.False(t, *actualAuthProxyAutoSignUp)
|
||||
assert.Equal(t, sc.resp.Code, 500)
|
||||
assert.Equal(t, sc.resp.Code, 407)
|
||||
assert.Nil(t, sc.context)
|
||||
})
|
||||
|
||||
@@ -480,6 +481,36 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
So(sc.context, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
middlewareScenario(t, "Should return 407 status code if LDAP says no", func(sc *scenarioContext) {
|
||||
bus.AddHandler("LDAP", func(cmd *models.UpsertUserCommand) error {
|
||||
return errors.New("Do not add user")
|
||||
})
|
||||
|
||||
sc.fakeReq("GET", "/")
|
||||
sc.req.Header.Add(setting.AuthProxyHeaderName, name)
|
||||
sc.exec()
|
||||
|
||||
Convey("Should return 407 status code", func() {
|
||||
So(sc.resp.Code, ShouldEqual, 407)
|
||||
So(sc.context, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
middlewareScenario(t, "Should return 407 status code if there is cache mishap", func(sc *scenarioContext) {
|
||||
bus.AddHandler("Do not have the user", func(query *models.GetSignedInUserQuery) error {
|
||||
return errors.New("Do not add user")
|
||||
})
|
||||
|
||||
sc.fakeReq("GET", "/")
|
||||
sc.req.Header.Add(setting.AuthProxyHeaderName, name)
|
||||
sc.exec()
|
||||
|
||||
Convey("Should return 407 status code", func() {
|
||||
So(sc.resp.Code, ShouldEqual, 407)
|
||||
So(sc.context, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user