summaryrefslogtreecommitdiffstats
path: root/services/repository/fork_test.go
diff options
context:
space:
mode:
authorXinyu Zhou <i@sourcehut.net>2022-12-28 05:21:14 +0800
committerGitHub <noreply@github.com>2022-12-27 15:21:14 -0600
commit7cc7db73b922143a1288d26b39eee9e8e59f7106 (patch)
treeda812b01e5953781a820f05edee52c93efef4bec /services/repository/fork_test.go
parent22a6e9759739af05a862fb5098aec0659aed2e84 (diff)
downloadgitea-7cc7db73b922143a1288d26b39eee9e8e59f7106.tar.gz
gitea-7cc7db73b922143a1288d26b39eee9e8e59f7106.zip
Add option to prohibit fork if user reached maximum limit of repositories (#21848)
If user has reached the maximum limit of repositories: - Before - disallow create - allow fork without limit - This patch: - disallow create - disallow fork - Add option `ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT` (Default **true**) : enable this allow user fork repositories without maximum number limit fixed https://github.com/go-gitea/gitea/issues/21847 Signed-off-by: Xinyu Zhou <i@sourcehut.net>
Diffstat (limited to 'services/repository/fork_test.go')
-rw-r--r--services/repository/fork_test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/services/repository/fork_test.go b/services/repository/fork_test.go
index c809ed4529..452798b25b 100644
--- a/services/repository/fork_test.go
+++ b/services/repository/fork_test.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
@@ -29,4 +30,19 @@ func TestForkRepository(t *testing.T) {
assert.Nil(t, fork)
assert.Error(t, err)
assert.True(t, IsErrForkAlreadyExist(err))
+
+ // user not reached maximum limit of repositories
+ assert.False(t, repo_model.IsErrReachLimitOfRepo(err))
+
+ // change AllowForkWithoutMaximumLimit to false for the test
+ setting.Repository.AllowForkWithoutMaximumLimit = false
+ // user has reached maximum limit of repositories
+ user.MaxRepoCreation = 0
+ fork2, err := ForkRepository(git.DefaultContext, user, user, ForkRepoOptions{
+ BaseRepo: repo,
+ Name: "test",
+ Description: "test",
+ })
+ assert.Nil(t, fork2)
+ assert.True(t, repo_model.IsErrReachLimitOfRepo(err))
}