-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change GetLogin to Login. Include userid and full name in Redis session.
- Loading branch information
Rob Archibald
committed
Jan 24, 2017
1 parent
2a94ddd
commit 703ddf4
Showing
10 changed files
with
126 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,7 +303,7 @@ func TestCreateSession(t *testing.T) { | |
for i, test := range createSessionTests { | ||
backend := &mockBackend{CreateSessionReturn: test.CreateSessionReturn} | ||
store := getAuthStore(nil, test.SessionCookie, test.RememberMeCookie, test.HasCookieGetError, test.HasCookiePutError, nil, backend) | ||
val, err := store.createSession("[email protected]", test.RememberMe) | ||
val, err := store.createSession("[email protected]", 1, "fullname", test.RememberMe) | ||
methods := store.backend.(*mockBackend).MethodsCalled | ||
if (err == nil && test.ExpectedErr != "" || err != nil && test.ExpectedErr != err.Error()) || | ||
!collectionEqual(test.MethodsCalled, methods) { | ||
|
@@ -320,20 +320,20 @@ func TestAuthGetBasicAuth(t *testing.T) { | |
} | ||
|
||
// Credential error | ||
store = getAuthStore(nil, nil, nil, true, false, nil, &mockBackend{GetUserLoginReturn: loginErr()}) | ||
store = getAuthStore(nil, nil, nil, true, false, nil, &mockBackend{LoginReturn: loginErr()}) | ||
if _, err := store.GetBasicAuth(); err == nil || err.Error() != "Problem decoding credentials from basic auth" { | ||
t.Error("expected error") | ||
} | ||
|
||
// login error | ||
store = getAuthStore(nil, nil, nil, true, false, nil, &mockBackend{GetUserLoginReturn: loginErr(), GetSessionReturn: sessionSuccess(futureTime, futureTime)}) | ||
store = getAuthStore(nil, nil, nil, true, false, nil, &mockBackend{LoginReturn: loginErr(), GetSessionReturn: sessionSuccess(futureTime, futureTime)}) | ||
store.r = basicAuthRequest("[email protected]", "password") | ||
if _, err := store.GetBasicAuth(); err == nil || err.Error() != "Invalid username or password" { | ||
t.Error("expected error", err) | ||
} | ||
|
||
// login success | ||
store = getAuthStore(nil, nil, nil, true, false, nil, &mockBackend{GetUserLoginReturn: loginSuccess(), GetSessionReturn: sessionSuccess(futureTime, futureTime), CreateSessionReturn: sessionRemember(futureTime, futureTime)}) | ||
store = getAuthStore(nil, nil, nil, true, false, nil, &mockBackend{LoginReturn: loginSuccess(), GetSessionReturn: sessionSuccess(futureTime, futureTime), CreateSessionReturn: sessionRemember(futureTime, futureTime)}) | ||
store.r = basicAuthRequest("[email protected]", "correctPassword") | ||
if _, err := store.GetBasicAuth(); err != nil { | ||
t.Error("expected success") | ||
|
@@ -382,9 +382,9 @@ func TestAuthStoreEndToEnd(t *testing.T) { | |
|
||
// create profile | ||
err = s.createProfile("fullName", "company", "password", "picturePath", 1, 1) | ||
hashErr := cryptoHashEquals("password", b.Logins[0].ProviderKey) | ||
hashErr := cryptoHashEquals("password", b.Logins[0].PasswordHash) | ||
if err != nil || len(b.Users) != 1 || len(b.Sessions) != 1 || len(b.Logins) != 1 || b.Logins[0].Email != "[email protected]" || len(b.EmailSessions) != 0 || hashErr != nil { | ||
t.Fatal("expected valid user, login and session", b.Logins[0], b.Logins[0].ProviderKey, hashErr) | ||
t.Fatal("expected valid user, login and session", b.Logins[0], b.Logins[0].PasswordHash, hashErr) | ||
} | ||
|
||
// decode session cookie | ||
|
@@ -643,7 +643,7 @@ var loginTests = []struct { | |
Password string | ||
RememberMe bool | ||
CreateSessionReturn *SessionRememberReturn | ||
GetUserLoginReturn *LoginReturn | ||
LoginReturn *LoginReturn | ||
ErrReturn error | ||
MethodsCalled []string | ||
ExpectedResult *rememberMeSession | ||
|
@@ -661,34 +661,26 @@ var loginTests = []struct { | |
ExpectedErr: passwordValidationMessage, | ||
}, | ||
{ | ||
Scenario: "Can't get login", | ||
Email: "[email protected]", | ||
Password: "validPassword", | ||
GetUserLoginReturn: loginErr(), | ||
MethodsCalled: []string{"GetLogin"}, | ||
ExpectedErr: "Invalid username or password", | ||
}, | ||
{ | ||
Scenario: "Incorrect password", | ||
Email: "[email protected]", | ||
Password: "wrongPassword", | ||
GetUserLoginReturn: &LoginReturn{Login: &userLogin{Email: "[email protected]", ProviderKey: "1234"}}, | ||
MethodsCalled: []string{"GetLogin"}, | ||
ExpectedErr: "Invalid username or password", | ||
Scenario: "Can't get login", | ||
Email: "[email protected]", | ||
Password: "validPassword", | ||
LoginReturn: loginErr(), | ||
MethodsCalled: []string{"Login"}, | ||
ExpectedErr: "Invalid username or password", | ||
}, | ||
{ | ||
Scenario: "Got session", | ||
Email: "[email protected]", | ||
Password: "correctPassword", | ||
GetUserLoginReturn: loginSuccess(), | ||
LoginReturn: loginSuccess(), | ||
CreateSessionReturn: sessionRemember(futureTime, futureTime), | ||
MethodsCalled: []string{"GetLogin", "CreateSession", "InvalidateSession", "InvalidateRememberMe"}, | ||
MethodsCalled: []string{"Login", "CreateSession", "InvalidateSession", "InvalidateRememberMe"}, | ||
}, | ||
} | ||
|
||
func TestAuthLogin(t *testing.T) { | ||
for i, test := range loginTests { | ||
backend := &mockBackend{GetUserLoginReturn: test.GetUserLoginReturn, ErrReturn: test.ErrReturn, CreateSessionReturn: test.CreateSessionReturn} | ||
backend := &mockBackend{LoginReturn: test.LoginReturn, ErrReturn: test.ErrReturn, CreateSessionReturn: test.CreateSessionReturn} | ||
store := getAuthStore(nil, nil, nil, false, false, nil, backend) | ||
val, err := store.login(test.Email, test.Password, test.RememberMe) | ||
methods := store.backend.(*mockBackend).MethodsCalled | ||
|
@@ -771,7 +763,7 @@ func TestLoginJson(t *testing.T) { | |
var buf bytes.Buffer | ||
buf.WriteString(`{"Email":"[email protected]", "Password":"password", "RememberMe":true}`) | ||
r := &http.Request{Body: ioutil.NopCloser(&buf)} | ||
backend := &mockBackend{GetUserLoginReturn: loginErr()} | ||
backend := &mockBackend{LoginReturn: loginErr()} | ||
store := getAuthStore(nil, nil, nil, true, false, nil, backend) | ||
store.r = r | ||
err := store.Login().(*authError).innerError | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,31 +23,34 @@ func TestNewBackendLDAPLogin(t *testing.T) { | |
t.Fatal("unable to login", err) | ||
} | ||
|
||
_, err = l.GetLogin("[email protected]", "") | ||
_, err = l.Login("[email protected]", "") | ||
if err == nil { | ||
t.Fatal("Expected no results", err) | ||
} | ||
} | ||
|
||
func TestLdapGetLogin(t *testing.T) { | ||
func TestLdapLogin(t *testing.T) { | ||
// success | ||
data := ldapData{UserPassword: []string{"password"}} | ||
data := ldapData{UID: "email", DbUserId: "1234"} | ||
m := onedb.NewMock(nil, nil, data) | ||
l := backendLDAPLogin{db: m, userLoginFilter: "%s"} | ||
login, err := l.GetLogin("email", "provider") | ||
if err != nil || login.ProviderKey != "password" { | ||
t.Error("expected to find data", login) | ||
login, err := l.Login("email", "password") | ||
if err != nil || login.Email != "email" { | ||
t.Error("expected to find data", login, err) | ||
} | ||
|
||
queries := m.QueriesRun() | ||
if _, ok := queries[0].(*ldap.SearchRequest); !ok { | ||
t.Error("expected ldap search request") | ||
if _, ok := queries[0].(*ldap.SimpleBindRequest); !ok { | ||
t.Error("expected ldap bind request first") | ||
} | ||
if _, ok := queries[1].(*ldap.SearchRequest); !ok { | ||
t.Error("expected ldap searc request next") | ||
} | ||
|
||
// error | ||
m = onedb.NewMock(nil, nil, nil) | ||
l = backendLDAPLogin{db: m, userLoginFilter: "%s"} | ||
_, err = l.GetLogin("email", "provider") | ||
_, err = l.Login("email", "password") | ||
if err == nil { | ||
t.Error("expected error") | ||
} | ||
|
Oops, something went wrong.