2019-11-15 13:36:11 +05:30
|
|
|
// Copyright 2019 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.
|
|
|
|
|
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2019-11-15 13:36:11 +05:30
|
|
|
"code.gitea.io/gitea/modules/notification"
|
|
|
|
"code.gitea.io/gitea/modules/notification/action"
|
2020-12-25 15:29:32 +05:30
|
|
|
"code.gitea.io/gitea/modules/util"
|
2019-11-15 13:36:11 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var notifySync sync.Once
|
|
|
|
|
|
|
|
func registerNotifier() {
|
|
|
|
notifySync.Do(func() {
|
|
|
|
notification.RegisterNotifier(action.NewNotifier())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTransferOwnership(t *testing.T) {
|
|
|
|
registerNotifier()
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2019-11-15 13:36:11 +05:30
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
|
|
|
repo.Owner = db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
2020-01-31 21:19:04 +05:30
|
|
|
assert.NoError(t, TransferOwnership(doer, doer, repo, nil))
|
2019-11-15 13:36:11 +05:30
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
transferredRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
2019-11-15 13:36:11 +05:30
|
|
|
assert.EqualValues(t, 2, transferredRepo.OwnerID)
|
|
|
|
|
2020-12-25 15:29:32 +05:30
|
|
|
exist, err := util.IsExist(models.RepoPath("user3", "repo3"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, exist)
|
|
|
|
exist, err = util.IsExist(models.RepoPath("user2", "repo3"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, exist)
|
2021-09-19 17:19:59 +05:30
|
|
|
db.AssertExistsAndLoadBean(t, &models.Action{
|
2019-11-15 13:36:11 +05:30
|
|
|
OpType: models.ActionTransferRepo,
|
|
|
|
ActUserID: 2,
|
|
|
|
RepoID: 3,
|
|
|
|
Content: "user3/repo3",
|
|
|
|
})
|
|
|
|
|
|
|
|
models.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
|
|
|
|
}
|
2021-06-15 00:00:35 +05:30
|
|
|
|
|
|
|
func TestStartRepositoryTransferSetPermission(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2021-06-15 00:00:35 +05:30
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
|
|
|
|
recipient := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
|
|
|
repo.Owner = db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
2021-06-15 00:00:35 +05:30
|
|
|
|
|
|
|
hasAccess, err := models.HasAccess(recipient.ID, repo)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, hasAccess)
|
|
|
|
|
|
|
|
assert.NoError(t, StartRepositoryTransfer(doer, recipient, repo, nil))
|
|
|
|
|
|
|
|
hasAccess, err = models.HasAccess(recipient.ID, repo)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, hasAccess)
|
|
|
|
|
|
|
|
models.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
|
|
|
|
}
|