-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor Signed-off-by: jolheiser <[email protected]> * Add push-create to SSH serv Signed-off-by: jolheiser <[email protected]> * Cannot push for another user unless admin Signed-off-by: jolheiser <[email protected]> * Get owner in case admin pushes for another user Signed-off-by: jolheiser <[email protected]> * Set new repo ID in result Signed-off-by: jolheiser <[email protected]> * Update to service and use new org perms Signed-off-by: jolheiser <[email protected]> * Move pushCreateRepo to services Signed-off-by: jolheiser <[email protected]> * Fix import order Signed-off-by: jolheiser <[email protected]> * Changes for @guillep2k * Check owner (not user) in SSH * Add basic tests for created repos (private, not empty) Signed-off-by: jolheiser <[email protected]>
- Loading branch information
Showing
7 changed files
with
218 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: "[email protected]", | ||
Name: "User Two", | ||
When: time.Now(), | ||
}, | ||
Author: &git.Signature{ | ||
Email: "[email protected]", | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.