mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-10-31 22:38:58 +00:00
8ad87d215f
- When someone gets blocked, remove all pending repository transfers from the blocked user to the doer. - Do not allow to start transferring repositories to the doer as blocked user. - Added unit testing. - Added integration testing. (cherry picked from commit8a3caac330
) (cherry picked from commita92b4cfeb6
) (cherry picked from commitacaaaf07d9
) (cherry picked from commit735818863c
) (cherry picked from commitf50fa43b32
) (cherry picked from commite166836433
) (cherry picked from commit82a0e4a381
) (cherry picked from commitff233c19c4
)
80 lines
2.7 KiB
Go
80 lines
2.7 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/models/organization"
|
|
access_model "code.gitea.io/gitea/models/perm/access"
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/util"
|
|
"code.gitea.io/gitea/services/feed"
|
|
notify_service "code.gitea.io/gitea/services/notify"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var notifySync sync.Once
|
|
|
|
func registerNotifier() {
|
|
notifySync.Do(func() {
|
|
notify_service.RegisterNotifier(feed.NewNotifier())
|
|
})
|
|
}
|
|
|
|
func TestTransferOwnership(t *testing.T) {
|
|
registerNotifier()
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
|
repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
assert.NoError(t, TransferOwnership(db.DefaultContext, doer, doer, repo, nil))
|
|
|
|
transferredRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
|
assert.EqualValues(t, 2, transferredRepo.OwnerID)
|
|
|
|
exist, err := util.IsExist(repo_model.RepoPath("org3", "repo3"))
|
|
assert.NoError(t, err)
|
|
assert.False(t, exist)
|
|
exist, err = util.IsExist(repo_model.RepoPath("user2", "repo3"))
|
|
assert.NoError(t, err)
|
|
assert.True(t, exist)
|
|
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
|
|
OpType: activities_model.ActionTransferRepo,
|
|
ActUserID: 2,
|
|
RepoID: 3,
|
|
Content: "org3/repo3",
|
|
})
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{}, &user_model.User{}, &organization.Team{})
|
|
}
|
|
|
|
func TestStartRepositoryTransferSetPermission(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
|
recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5})
|
|
repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
|
|
hasAccess, err := access_model.HasAccess(db.DefaultContext, recipient.ID, repo)
|
|
assert.NoError(t, err)
|
|
assert.False(t, hasAccess)
|
|
|
|
assert.NoError(t, StartRepositoryTransfer(db.DefaultContext, doer, recipient, repo, nil))
|
|
|
|
hasAccess, err = access_model.HasAccess(db.DefaultContext, recipient.ID, repo)
|
|
assert.NoError(t, err)
|
|
assert.True(t, hasAccess)
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{}, &user_model.User{}, &organization.Team{})
|
|
}
|