You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

delete_user_test.go 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "fmt"
  7. "net/http"
  8. "testing"
  9. "code.gitea.io/gitea/models"
  10. )
  11. func assertUserDeleted(t *testing.T, userID int64) {
  12. models.AssertNotExistsBean(t, &models.User{ID: userID})
  13. models.AssertNotExistsBean(t, &models.Follow{UserID: userID})
  14. models.AssertNotExistsBean(t, &models.Follow{FollowID: userID})
  15. models.AssertNotExistsBean(t, &models.Repository{OwnerID: userID})
  16. models.AssertNotExistsBean(t, &models.Access{UserID: userID})
  17. models.AssertNotExistsBean(t, &models.OrgUser{UID: userID})
  18. models.AssertNotExistsBean(t, &models.IssueUser{UID: userID})
  19. models.AssertNotExistsBean(t, &models.TeamUser{UID: userID})
  20. models.AssertNotExistsBean(t, &models.Star{UID: userID})
  21. }
  22. func TestUserDeleteAccount(t *testing.T) {
  23. defer prepareTestEnv(t)()
  24. session := loginUser(t, "user8")
  25. csrf := GetCSRF(t, session, "/user/settings/account")
  26. urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
  27. req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
  28. "_csrf": csrf,
  29. })
  30. session.MakeRequest(t, req, http.StatusFound)
  31. assertUserDeleted(t, 8)
  32. models.CheckConsistencyFor(t, &models.User{})
  33. }
  34. func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
  35. defer prepareTestEnv(t)()
  36. session := loginUser(t, "user2")
  37. csrf := GetCSRF(t, session, "/user/settings/account")
  38. urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
  39. req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
  40. "_csrf": csrf,
  41. })
  42. session.MakeRequest(t, req, http.StatusFound)
  43. // user should not have been deleted, because the user still owns repos
  44. models.AssertExistsAndLoadBean(t, &models.User{ID: 2})
  45. }