mirror of
https://github.com/volatiletech/authboss.git
synced 2025-02-15 14:03:17 +02:00
Finish unfinished middleware
This commit is contained in:
parent
982025bbc3
commit
38268f7a6b
@ -242,6 +242,12 @@ func Middleware(ab *authboss.Authboss, next http.Handler) http.Handler {
|
||||
|
||||
logger := ab.RequestLogger(r)
|
||||
logger.Infof("user %s prevented from accessing %s: not confirmed", user.GetPID(), r.URL.Path)
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: "Your account has not been confirmed, please check your e-mail.",
|
||||
RedirectPath: ab.Config.Paths.ConfirmNotOK,
|
||||
}
|
||||
ab.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -331,7 +331,11 @@ func TestMiddlewareDisallow(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ab := authboss.New()
|
||||
redirector := &mocks.Redirector{}
|
||||
ab.Config.Paths.ConfirmNotOK = "/confirm/not/ok"
|
||||
ab.Config.Core.Logger = mocks.Logger{}
|
||||
ab.Config.Core.Redirector = redirector
|
||||
|
||||
called := false
|
||||
server := Middleware(ab, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
called = true
|
||||
@ -350,6 +354,12 @@ func TestMiddlewareDisallow(t *testing.T) {
|
||||
if called {
|
||||
t.Error("The user should not have been allowed through")
|
||||
}
|
||||
if redirector.Options.Code != http.StatusTemporaryRedirect {
|
||||
t.Error("expected a redirect, but got:", redirector.Options.Code)
|
||||
}
|
||||
if p := redirector.Options.RedirectPath; p != "/confirm/not/ok" {
|
||||
t.Error("redirect path wrong:", p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateToken(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user