1
0
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:
Aaron L 2018-02-27 07:41:01 -08:00
parent 982025bbc3
commit 38268f7a6b
2 changed files with 16 additions and 0 deletions

View File

@ -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)
})
}

View File

@ -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) {