diff options
author | John Olheiser <42128690+jolheiser@users.noreply.github.com> | 2019-12-14 20:49:52 -0600 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-12-15 10:49:52 +0800 |
commit | 6715677b2bf7a065d0184ea7f2647e70ca2598d4 (patch) | |
tree | ec2ed74b0eb153391bd46a9552923b2282867be5 /integrations/git_test.go | |
parent | 47c24be293ac8b1b28310d2fb2be58b8191a5bae (diff) | |
download | gitea-6715677b2bf7a065d0184ea7f2647e70ca2598d4.tar.gz gitea-6715677b2bf7a065d0184ea7f2647e70ca2598d4.zip |
Push to create repo (#8419)
* Refactor
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Add push-create to SSH serv
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Cannot push for another user unless admin
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Get owner in case admin pushes for another user
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Set new repo ID in result
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Update to service and use new org perms
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Move pushCreateRepo to services
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Fix import order
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Changes for @guillep2k
* Check owner (not user) in SSH
* Add basic tests for created repos (private, not empty)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Diffstat (limited to 'integrations/git_test.go')
-rw-r--r-- | integrations/git_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/integrations/git_test.go b/integrations/git_test.go index b504cd7524..7d37555f06 100644 --- a/integrations/git_test.go +++ b/integrations/git_test.go @@ -75,6 +75,8 @@ func testGit(t *testing.T, u *url.URL) { rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS) mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS) }) + + t.Run("PushCreate", doPushCreate(httpContext, u)) }) t.Run("SSH", func(t *testing.T) { defer PrintCurrentTest(t)() @@ -113,6 +115,8 @@ func testGit(t *testing.T, u *url.URL) { rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS) mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS) }) + + t.Run("PushCreate", doPushCreate(sshContext, sshURL)) }) }) } @@ -408,3 +412,57 @@ func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) fun } } + +func doPushCreate(ctx APITestContext, u *url.URL) func(t *testing.T) { + return func(t *testing.T) { + defer PrintCurrentTest(t)() + ctx.Reponame = fmt.Sprintf("repo-tmp-push-create-%s", u.Scheme) + u.Path = ctx.GitPath() + + tmpDir, err := ioutil.TempDir("", ctx.Reponame) + assert.NoError(t, err) + + err = git.InitRepository(tmpDir, false) + assert.NoError(t, err) + + _, err = os.Create(filepath.Join(tmpDir, "test.txt")) + assert.NoError(t, err) + + err = git.AddChanges(tmpDir, true) + assert.NoError(t, err) + + err = git.CommitChanges(tmpDir, git.CommitChangesOptions{ + Committer: &git.Signature{ + Email: "user2@example.com", + Name: "User Two", + When: time.Now(), + }, + Author: &git.Signature{ + Email: "user2@example.com", + Name: "User Two", + When: time.Now(), + }, + Message: fmt.Sprintf("Testing push create @ %v", time.Now()), + }) + assert.NoError(t, err) + + _, err = git.NewCommand("remote", "add", "origin", u.String()).RunInDir(tmpDir) + assert.NoError(t, err) + + // Push to create disabled + setting.Repository.EnablePushCreateUser = false + _, err = git.NewCommand("push", "origin", "master").RunInDir(tmpDir) + assert.Error(t, err) + + // Push to create enabled + setting.Repository.EnablePushCreateUser = true + _, err = git.NewCommand("push", "origin", "master").RunInDir(tmpDir) + assert.NoError(t, err) + + // Fetch repo from database + repo, err := models.GetRepositoryByOwnerAndName(ctx.Username, ctx.Reponame) + assert.NoError(t, err) + assert.False(t, repo.IsEmpty) + assert.True(t, repo.IsPrivate) + } +} |