2015-01-05 00:18:41 -08:00
|
|
|
package authboss
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAuthBossInit(t *testing.T) {
|
2015-03-31 12:34:03 -07:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
ab := New()
|
|
|
|
err := ab.Init()
|
2015-01-05 00:18:41 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:58:32 -07:00
|
|
|
func TestAuthbossUpdatePassword(t *testing.T) {
|
2017-02-23 16:13:25 -08:00
|
|
|
t.Skip("TODO(aarondl): Implement")
|
|
|
|
/*
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
ab := New()
|
|
|
|
session := mockClientStore{}
|
|
|
|
cookies := mockClientStore{}
|
|
|
|
ab.SessionStoreMaker = newMockClientStoreMaker(session)
|
|
|
|
ab.CookieStoreMaker = newMockClientStoreMaker(cookies)
|
|
|
|
|
|
|
|
called := false
|
2018-02-01 16:31:08 -08:00
|
|
|
ab.Events.After(EventPasswordReset, func(ctx context.Context) error {
|
2017-02-23 16:13:25 -08:00
|
|
|
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 {
|
2018-02-01 16:31:08 -08:00
|
|
|
t.Error("Events should have been called.")
|
2017-02-23 16:13:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2018-02-01 16:31:08 -08:00
|
|
|
t.Error("Events should have been called.")
|
2017-02-23 16:13:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2018-02-01 16:31:08 -08:00
|
|
|
t.Error("Events should not have been called")
|
2017-02-23 16:13:25 -08:00
|
|
|
}
|
|
|
|
*/
|
2015-03-16 22:58:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAuthbossUpdatePasswordFail(t *testing.T) {
|
2017-02-23 16:13:25 -08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
*/
|
2015-03-16 22:58:32 -07:00
|
|
|
}
|