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.
62 lines
2.2 KiB
62 lines
2.2 KiB
8 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package integration
|
||
8 years ago
|
|
||
|
import (
|
||
7 years ago
|
"fmt"
|
||
8 years ago
|
"net/http"
|
||
|
"testing"
|
||
|
|
||
2 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
"code.gitea.io/gitea/models/organization"
|
||
3 years ago
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
2 years ago
|
"code.gitea.io/gitea/tests"
|
||
8 years ago
|
)
|
||
|
|
||
7 years ago
|
func assertUserDeleted(t *testing.T, userID int64) {
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &user_model.User{ID: userID})
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: userID})
|
||
|
unittest.AssertNotExistsBean(t, &user_model.Follow{FollowID: userID})
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &repo_model.Repository{OwnerID: userID})
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &access_model.Access{UserID: userID})
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &organization.OrgUser{UID: userID})
|
||
2 years ago
|
unittest.AssertNotExistsBean(t, &issues_model.IssueUser{UID: userID})
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &organization.TeamUser{UID: userID})
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &repo_model.Star{UID: userID})
|
||
7 years ago
|
}
|
||
|
|
||
|
func TestUserDeleteAccount(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
7 years ago
|
|
||
|
session := loginUser(t, "user8")
|
||
7 years ago
|
csrf := GetCSRF(t, session, "/user/settings/account")
|
||
|
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
|
||
7 years ago
|
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
||
|
"_csrf": csrf,
|
||
|
})
|
||
3 years ago
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
||
7 years ago
|
|
||
|
assertUserDeleted(t, 8)
|
||
3 years ago
|
unittest.CheckConsistencyFor(t, &user_model.User{})
|
||
7 years ago
|
}
|
||
|
|
||
|
func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
7 years ago
|
|
||
|
session := loginUser(t, "user2")
|
||
7 years ago
|
csrf := GetCSRF(t, session, "/user/settings/account")
|
||
|
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
|
||
7 years ago
|
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
||
|
"_csrf": csrf,
|
||
|
})
|
||
3 years ago
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
||
7 years ago
|
|
||
|
// user should not have been deleted, because the user still owns repos
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||
7 years ago
|
}
|