fix test case

This commit is contained in:
wemeya 2016-09-22 16:57:57 +08:00
parent c0f3d7d749
commit 2a0951e2ea
2 changed files with 16 additions and 13 deletions

View File

@ -315,13 +315,13 @@ func (ua *UserAPI) ToggleUserAdminRole() {
// validate only validate when user register
func validate(user models.User) error {
if isIllegalLength(user.Username, 0, 20) {
if isIllegalLength(user.Username, 1, 20) {
return fmt.Errorf("Username with illegal length.")
}
if isContainIllegalChar(user.Username, []string{",", "~", "#", "$", "%"}) {
return fmt.Errorf("Username contains illegal characters.")
}
if isIllegalLength(user.Password, 0, 20) {
if isIllegalLength(user.Password, 7, 20) {
return fmt.Errorf("Password with illegal length.")
}
if err := commonValidate(user); err != nil {

View File

@ -51,7 +51,7 @@ func TestUsersPost(t *testing.T) {
//case 4: register a new user with admin auth, but bad userpassword format, expect 400
testUser0002.Username = "testUser0002"
fmt.Println("Register user with admin auth, but bad userpassword format")
fmt.Println("Register user with admin auth, but empty password.")
code, err = apiTest.UsersPost(testUser0002, *admin)
if err != nil {
t.Error("Error occured while add a user", err.Error())
@ -83,6 +83,7 @@ func TestUsersPost(t *testing.T) {
}
//case 7: register a new user with admin auth, but userrealname is empty, expect 400
/*
testUser0002.Email = "testUser0002@mydomain.com"
fmt.Println("Register user with admin auth, but user realname is empty")
code, err = apiTest.UsersPost(testUser0002, *admin)
@ -92,14 +93,16 @@ func TestUsersPost(t *testing.T) {
} else {
assert.Equal(400, code, "Add user status should be 400")
}
*/
//case 8: register a new user with admin auth, but bad userrealname format, expect 400
testUser0002.Email = "testUser0002@mydomain.com"
testUser0002.Realname = "test$com"
fmt.Println("Register user with admin auth, but bad user realname format")
code, err = apiTest.UsersPost(testUser0002, *admin)
if err != nil {
t.Error("Error occured while add a user", err.Error())
t.Log(err)
} else {
assert.Equal(400, code, "Add user status should be 400")
}