diff --git a/api/user.go b/api/user.go index 0355deff9..70b0796e9 100644 --- a/api/user.go +++ b/api/user.go @@ -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 { diff --git a/api/user_test.go b/api/user_test.go index 4943b9949..7ea546990 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -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,23 +83,26 @@ 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) - 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") - } - + /* + testUser0002.Email = "testUser0002@mydomain.com" + fmt.Println("Register user with admin auth, but user realname is empty") + 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") + } + */ //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") }