Merge pull request #2116 from ywk253100/170424_ldap_fix

Return error when got more than one users in GetUser method
This commit is contained in:
Wenkai Yin 2017-04-26 16:16:15 +08:00 committed by GitHub
commit ee93627391
2 changed files with 9 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import (
"github.com/astaxie/beego/orm"
//"github.com/vmware/harbor/src/common/config"
"github.com/stretchr/testify/assert"
"github.com/vmware/harbor/src/common/models"
"github.com/vmware/harbor/src/common/utils"
"github.com/vmware/harbor/src/common/utils/log"
@ -402,6 +403,10 @@ func TestGetUser(t *testing.T) {
if currentUser.Email != "tester01@vmware.com" {
t.Errorf("the user's email does not match, expected: tester01@vmware.com, actual: %s", currentUser.Email)
}
queryUser = models.User{}
_, err = GetUser(queryUser)
assert.NotNil(t, err)
}
func TestListUsers(t *testing.T) {

View File

@ -60,6 +60,10 @@ func GetUser(query models.User) (*models.User, error) {
return nil, nil
}
if n > 1 {
return nil, fmt.Errorf("got more than one user when executing: %s param: %v", sql, queryParam)
}
return &u[0], nil
}