mirror of
https://github.com/volatiletech/authboss.git
synced 2025-02-03 13:21:22 +02:00
24fc6196c7
- This addresses the problem of having to update multiple times during one request. It's hard to have a nice interface especially with JWT because you always end up having to decode the request, encode new response, write header, then a second write to it comes, and where do you grab the value from? Often you don't have access to the response as a "read" structure. So we store it as events instead, and play those events against the original data right before the response is written to set the headers.
106 lines
2.1 KiB
Go
106 lines
2.1 KiB
Go
package authboss
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
)
|
|
|
|
func TestAuthBossInit(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ab := New()
|
|
ab.LogWriter = ioutil.Discard
|
|
ab.ViewLoader = mockRenderLoader{}
|
|
err := ab.Init()
|
|
if err != nil {
|
|
t.Error("Unexpected error:", err)
|
|
}
|
|
}
|
|
|
|
func TestAuthbossUpdatePassword(t *testing.T) {
|
|
t.Skip("TODO(aarondl): Implement")
|
|
/*
|
|
t.Parallel()
|
|
|
|
ab := New()
|
|
session := mockClientStore{}
|
|
cookies := mockClientStore{}
|
|
ab.SessionStoreMaker = newMockClientStoreMaker(session)
|
|
ab.CookieStoreMaker = newMockClientStoreMaker(cookies)
|
|
|
|
called := false
|
|
ab.Callbacks.After(EventPasswordReset, func(ctx context.Context) error {
|
|
called = true
|
|
return nil
|
|
})
|
|
|
|
user1 := struct {
|
|
Password string
|
|
}{}
|
|
user2 := struct {
|
|
Password sql.NullString
|
|
}{}
|
|
|
|
r, _ := http.NewRequest("GET", "http://localhost", nil)
|
|
|
|
called = false
|
|
err := ab.UpdatePassword(nil, r, "newpassword", &user1, func() error { return nil })
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(user1.Password) == 0 {
|
|
t.Error("Password not updated")
|
|
}
|
|
if !called {
|
|
t.Error("Callbacks should have been called.")
|
|
}
|
|
|
|
called = false
|
|
err = ab.UpdatePassword(nil, r, "newpassword", &user2, func() error { return nil })
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if !user2.Password.Valid || len(user2.Password.String) == 0 {
|
|
t.Error("Password not updated")
|
|
}
|
|
if !called {
|
|
t.Error("Callbacks should have been called.")
|
|
}
|
|
|
|
called = false
|
|
oldPassword := user1.Password
|
|
err = ab.UpdatePassword(nil, r, "", &user1, func() error { return nil })
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if user1.Password != oldPassword {
|
|
t.Error("Password not updated")
|
|
}
|
|
if called {
|
|
t.Error("Callbacks should not have been called")
|
|
}
|
|
*/
|
|
}
|
|
|
|
func TestAuthbossUpdatePasswordFail(t *testing.T) {
|
|
t.Skip("TODO(aarondl): Implement")
|
|
/*
|
|
t.Parallel()
|
|
|
|
ab := New()
|
|
|
|
user1 := struct {
|
|
Password string
|
|
}{}
|
|
|
|
anErr := errors.New("anError")
|
|
err := ab.UpdatePassword(nil, nil, "update", &user1, func() error { return anErr })
|
|
if err != anErr {
|
|
t.Error("Expected an specific error:", err)
|
|
}
|
|
*/
|
|
}
|