loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'fix: hook post-receive for sha256 repos' (#3652) from oliverpool/forgejo:hook_post_receive_error into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3652
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+195 -151
+6 -8
cmd/hook.go
··· 316 316 return nil 317 317 } 318 318 319 - // Deletion of the ref means that the new commit ID is only composed of '0'. 320 - if strings.ContainsFunc(newCommitID, func(e rune) bool { return e != '0' }) { 321 - return nil 319 + // Empty new commit ID means deletion. 320 + if git.IsEmptyCommitID(newCommitID, nil) { 321 + return fail(ctx, fmt.Sprintf("The deletion of %s is skipped as it's an internal reference.", refFullName), "") 322 322 } 323 323 324 - return fail(ctx, fmt.Sprintf("The deletion of %s is skipped as it's an internal reference.", refFullName), "") 324 + return nil 325 325 } 326 326 327 327 func runHookPostReceive(c *cli.Context) error { ··· 405 405 newCommitIDs[count] = string(fields[1]) 406 406 refFullNames[count] = git.RefName(fields[2]) 407 407 408 - commitID, _ := git.NewIDFromString(newCommitIDs[count]) 409 - if refFullNames[count] == git.BranchPrefix+"master" && !commitID.IsZero() && count == total { 408 + if refFullNames[count] == git.BranchPrefix+"master" && !git.IsEmptyCommitID(newCommitIDs[count], nil) && count == total { 410 409 masterPushed = true 411 410 } 412 411 count++ ··· 697 696 if err != nil { 698 697 return err 699 698 } 700 - commitID, _ := git.NewIDFromString(rs.OldOID) 701 - if !commitID.IsZero() { 699 + if !git.IsEmptyCommitID(rs.OldOID, nil) { 702 700 err = writeDataPktLine(ctx, os.Stdout, []byte("option old-oid "+rs.OldOID)) 703 701 if err != nil { 704 702 return err
+1 -1
models/repo/repo.go
··· 329 329 // CommitLink make link to by commit full ID 330 330 // note: won't check whether it's an right id 331 331 func (repo *Repository) CommitLink(commitID string) (result string) { 332 - if git.IsEmptyCommitID(commitID) { 332 + if git.IsEmptyCommitID(commitID, nil) { 333 333 result = "" 334 334 } else { 335 335 result = repo.Link() + "/commit/" + url.PathEscape(commitID)
+1
modules/git/object_format.go
··· 122 122 var ( 123 123 Sha1ObjectFormat ObjectFormat = Sha1ObjectFormatImpl{} 124 124 Sha256ObjectFormat ObjectFormat = Sha256ObjectFormatImpl{} 125 + // any addition must be reflected in IsEmptyCommitID 125 126 ) 126 127 127 128 var SupportedObjectFormats = []ObjectFormat{
+14 -6
modules/git/object_id.go
··· 79 79 return theObjectFormat.MustID(b), nil 80 80 } 81 81 82 - func IsEmptyCommitID(commitID string) bool { 82 + // IsEmptyCommitID checks if an hexadecimal string represents an empty commit according to git (only '0'). 83 + // If objectFormat is not nil, the length will be checked as well (otherwise the lenght must match the sha1 or sha256 length). 84 + func IsEmptyCommitID(commitID string, objectFormat ObjectFormat) bool { 83 85 if commitID == "" { 84 86 return true 85 87 } 86 - 87 - id, err := NewIDFromString(commitID) 88 - if err != nil { 88 + if objectFormat == nil { 89 + if Sha1ObjectFormat.FullLength() != len(commitID) && Sha256ObjectFormat.FullLength() != len(commitID) { 90 + return false 91 + } 92 + } else if objectFormat.FullLength() != len(commitID) { 89 93 return false 90 94 } 91 - 92 - return id.IsZero() 95 + for _, c := range commitID { 96 + if c != '0' { 97 + return false 98 + } 99 + } 100 + return true 93 101 } 94 102 95 103 // ComputeBlobHash compute the hash for a given blob content
+24
modules/git/object_id_test.go
··· 23 23 assert.Equal(t, "d5c6407415d85df49592672aa421aed39b9db5e3", ComputeBlobHash(Sha1ObjectFormat, []byte("same length blob")).String()) 24 24 assert.Equal(t, "df0b5174ed06ae65aea40d43316bcbc21d82c9e3158ce2661df2ad28d7931dd6", ComputeBlobHash(Sha256ObjectFormat, []byte("some random blob")).String()) 25 25 } 26 + 27 + func TestIsEmptyCommitID(t *testing.T) { 28 + assert.True(t, IsEmptyCommitID("", nil)) 29 + assert.True(t, IsEmptyCommitID("", Sha1ObjectFormat)) 30 + assert.True(t, IsEmptyCommitID("", Sha256ObjectFormat)) 31 + 32 + assert.False(t, IsEmptyCommitID("79ee38a6416c1ede423ec7ee0a8639ceea4aad20", Sha1ObjectFormat)) 33 + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000", nil)) 34 + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000", Sha1ObjectFormat)) 35 + assert.False(t, IsEmptyCommitID("0000000000000000000000000000000000000000", Sha256ObjectFormat)) 36 + 37 + assert.False(t, IsEmptyCommitID("00000000000000000000000000000000000000000", nil)) 38 + 39 + assert.False(t, IsEmptyCommitID("0f0b5174ed06ae65aea40d43316bcbc21d82c9e3158ce2661df2ad28d7931dd6", nil)) 40 + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", nil)) 41 + assert.False(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", Sha1ObjectFormat)) 42 + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", Sha256ObjectFormat)) 43 + 44 + assert.False(t, IsEmptyCommitID("1", nil)) 45 + assert.False(t, IsEmptyCommitID("0", nil)) 46 + 47 + assert.False(t, IsEmptyCommitID("010", nil)) 48 + assert.False(t, IsEmptyCommitID("0 0", nil)) 49 + }
+2 -4
modules/repository/push.go
··· 21 21 22 22 // IsNewRef return true if it's a first-time push to a branch, tag or etc. 23 23 func (opts *PushUpdateOptions) IsNewRef() bool { 24 - commitID, err := git.NewIDFromString(opts.OldCommitID) 25 - return err == nil && commitID.IsZero() 24 + return git.IsEmptyCommitID(opts.OldCommitID, nil) 26 25 } 27 26 28 27 // IsDelRef return true if it's a deletion to a branch or tag 29 28 func (opts *PushUpdateOptions) IsDelRef() bool { 30 - commitID, err := git.NewIDFromString(opts.NewCommitID) 31 - return err == nil && commitID.IsZero() 29 + return git.IsEmptyCommitID(opts.NewCommitID, nil) 32 30 } 33 31 34 32 // IsUpdateRef return true if it's an update operation
+1 -1
routers/private/hook_post_receive.go
··· 239 239 } 240 240 241 241 // If we've pushed a branch (and not deleted it) 242 - if !git.IsEmptyCommitID(newCommitID) && refFullName.IsBranch() { 242 + if !git.IsEmptyCommitID(newCommitID, nil) && refFullName.IsBranch() { 243 243 // First ensure we have the repository loaded, we're allowed pulls requests and we can get the base repo 244 244 if repo == nil { 245 245 repo = loadRepository(ctx, ownerName, repoName)
+1 -2
services/actions/notifier.go
··· 515 515 } 516 516 517 517 func (n *actionsNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { 518 - commitID, _ := git.NewIDFromString(opts.NewCommitID) 519 - if commitID.IsZero() { 518 + if git.IsEmptyCommitID(opts.NewCommitID, nil) { 520 519 log.Trace("new commitID is empty") 521 520 return 522 521 }
+3 -2
tests/integration/git_helper_for_declarative_test.go
··· 117 117 } 118 118 } 119 119 120 - func doGitInitTestRepository(dstPath string) func(*testing.T) { 120 + func doGitInitTestRepository(dstPath string, objectFormat git.ObjectFormat) func(*testing.T) { 121 121 return func(t *testing.T) { 122 122 // Init repository in dstPath 123 - assert.NoError(t, git.InitRepository(git.DefaultContext, dstPath, false, git.Sha1ObjectFormat.Name())) 123 + assert.NoError(t, git.InitRepository(git.DefaultContext, dstPath, false, objectFormat.Name())) 124 124 // forcibly set default branch to master 125 125 _, _, err := git.NewCommand(git.DefaultContext, "symbolic-ref", "HEAD", git.BranchPrefix+"master").RunStdString(&git.RunOpts{Dir: dstPath}) 126 126 assert.NoError(t, err) ··· 148 148 149 149 func doGitPushTestRepository(dstPath string, args ...string) func(*testing.T) { 150 150 return func(t *testing.T) { 151 + t.Helper() 151 152 _, _, err := git.NewCommand(git.DefaultContext, "push", "-u").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(&git.RunOpts{Dir: dstPath}) 152 153 assert.NoError(t, err) 153 154 }
+140 -125
tests/integration/git_push_test.go
··· 24 24 "github.com/stretchr/testify/require" 25 25 ) 26 26 27 + func forEachObjectFormat(t *testing.T, f func(t *testing.T, objectFormat git.ObjectFormat)) { 28 + for _, objectFormat := range []git.ObjectFormat{git.Sha256ObjectFormat, git.Sha1ObjectFormat} { 29 + t.Run(objectFormat.Name(), func(t *testing.T) { 30 + f(t, objectFormat) 31 + }) 32 + } 33 + } 34 + 27 35 func TestGitPush(t *testing.T) { 28 36 onGiteaRun(t, testGitPush) 29 37 } 30 38 31 39 func testGitPush(t *testing.T, u *url.URL) { 32 - t.Run("Push branches at once", func(t *testing.T) { 33 - runTestGitPush(t, u, func(t *testing.T, gitPath string) (pushed, deleted []string) { 34 - for i := 0; i < 100; i++ { 35 - branchName := fmt.Sprintf("branch-%d", i) 36 - pushed = append(pushed, branchName) 37 - doGitCreateBranch(gitPath, branchName)(t) 38 - } 39 - pushed = append(pushed, "master") 40 - doGitPushTestRepository(gitPath, "origin", "--all")(t) 41 - return pushed, deleted 40 + forEachObjectFormat(t, func(t *testing.T, objectFormat git.ObjectFormat) { 41 + t.Run("Push branches at once", func(t *testing.T) { 42 + runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) { 43 + for i := 0; i < 100; i++ { 44 + branchName := fmt.Sprintf("branch-%d", i) 45 + pushed = append(pushed, branchName) 46 + doGitCreateBranch(gitPath, branchName)(t) 47 + } 48 + pushed = append(pushed, "master") 49 + doGitPushTestRepository(gitPath, "origin", "--all")(t) 50 + return pushed, deleted 51 + }) 42 52 }) 43 - }) 44 53 45 - t.Run("Push branches one by one", func(t *testing.T) { 46 - runTestGitPush(t, u, func(t *testing.T, gitPath string) (pushed, deleted []string) { 47 - for i := 0; i < 100; i++ { 48 - branchName := fmt.Sprintf("branch-%d", i) 49 - doGitCreateBranch(gitPath, branchName)(t) 50 - doGitPushTestRepository(gitPath, "origin", branchName)(t) 51 - pushed = append(pushed, branchName) 52 - } 53 - return pushed, deleted 54 + t.Run("Push branches one by one", func(t *testing.T) { 55 + runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) { 56 + for i := 0; i < 100; i++ { 57 + branchName := fmt.Sprintf("branch-%d", i) 58 + doGitCreateBranch(gitPath, branchName)(t) 59 + doGitPushTestRepository(gitPath, "origin", branchName)(t) 60 + pushed = append(pushed, branchName) 61 + } 62 + return pushed, deleted 63 + }) 54 64 }) 55 - }) 56 65 57 - t.Run("Delete branches", func(t *testing.T) { 58 - runTestGitPush(t, u, func(t *testing.T, gitPath string) (pushed, deleted []string) { 59 - doGitPushTestRepository(gitPath, "origin", "master")(t) // make sure master is the default branch instead of a branch we are going to delete 60 - pushed = append(pushed, "master") 66 + t.Run("Delete branches", func(t *testing.T) { 67 + runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) { 68 + doGitPushTestRepository(gitPath, "origin", "master")(t) // make sure master is the default branch instead of a branch we are going to delete 69 + pushed = append(pushed, "master") 61 70 62 - for i := 0; i < 100; i++ { 63 - branchName := fmt.Sprintf("branch-%d", i) 64 - pushed = append(pushed, branchName) 65 - doGitCreateBranch(gitPath, branchName)(t) 66 - } 67 - doGitPushTestRepository(gitPath, "origin", "--all")(t) 71 + for i := 0; i < 100; i++ { 72 + branchName := fmt.Sprintf("branch-%d", i) 73 + pushed = append(pushed, branchName) 74 + doGitCreateBranch(gitPath, branchName)(t) 75 + } 76 + doGitPushTestRepository(gitPath, "origin", "--all")(t) 68 77 69 - for i := 0; i < 10; i++ { 70 - branchName := fmt.Sprintf("branch-%d", i) 71 - doGitPushTestRepository(gitPath, "origin", "--delete", branchName)(t) 72 - deleted = append(deleted, branchName) 73 - } 74 - return pushed, deleted 78 + for i := 0; i < 10; i++ { 79 + branchName := fmt.Sprintf("branch-%d", i) 80 + doGitPushTestRepository(gitPath, "origin", "--delete", branchName)(t) 81 + deleted = append(deleted, branchName) 82 + } 83 + return pushed, deleted 84 + }) 75 85 }) 76 - }) 77 86 78 - t.Run("Push to deleted branch", func(t *testing.T) { 79 - runTestGitPush(t, u, func(t *testing.T, gitPath string) (pushed, deleted []string) { 80 - doGitPushTestRepository(gitPath, "origin", "master")(t) // make sure master is the default branch instead of a branch we are going to delete 81 - pushed = append(pushed, "master") 87 + t.Run("Push to deleted branch", func(t *testing.T) { 88 + runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) { 89 + doGitPushTestRepository(gitPath, "origin", "master")(t) // make sure master is the default branch instead of a branch we are going to delete 90 + pushed = append(pushed, "master") 82 91 83 - doGitCreateBranch(gitPath, "branch-1")(t) 84 - doGitPushTestRepository(gitPath, "origin", "branch-1")(t) 85 - pushed = append(pushed, "branch-1") 92 + doGitCreateBranch(gitPath, "branch-1")(t) 93 + doGitPushTestRepository(gitPath, "origin", "branch-1")(t) 94 + pushed = append(pushed, "branch-1") 86 95 87 - // delete and restore 88 - doGitPushTestRepository(gitPath, "origin", "--delete", "branch-1")(t) 89 - doGitPushTestRepository(gitPath, "origin", "branch-1")(t) 96 + // delete and restore 97 + doGitPushTestRepository(gitPath, "origin", "--delete", "branch-1")(t) 98 + doGitPushTestRepository(gitPath, "origin", "branch-1")(t) 90 99 91 - return pushed, deleted 100 + return pushed, deleted 101 + }) 92 102 }) 93 103 }) 94 104 } 95 105 96 - func runTestGitPush(t *testing.T, u *url.URL, gitOperation func(t *testing.T, gitPath string) (pushed, deleted []string)) { 106 + func runTestGitPush(t *testing.T, u *url.URL, objectFormat git.ObjectFormat, gitOperation func(t *testing.T, gitPath string) (pushed, deleted []string)) { 97 107 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 98 108 repo, err := repo_service.CreateRepository(db.DefaultContext, user, user, repo_service.CreateRepoOptions{ 99 - Name: "repo-to-push", 100 - Description: "test git push", 101 - AutoInit: false, 102 - DefaultBranch: "main", 103 - IsPrivate: false, 109 + Name: "repo-to-push", 110 + Description: "test git push", 111 + AutoInit: false, 112 + DefaultBranch: "main", 113 + IsPrivate: false, 114 + ObjectFormatName: objectFormat.Name(), 104 115 }) 105 116 require.NoError(t, err) 106 117 require.NotEmpty(t, repo) 107 118 108 119 gitPath := t.TempDir() 109 120 110 - doGitInitTestRepository(gitPath)(t) 121 + doGitInitTestRepository(gitPath, objectFormat)(t) 111 122 112 123 oldPath := u.Path 113 124 oldUser := u.User ··· 158 169 159 170 func testOptionsGitPush(t *testing.T, u *url.URL) { 160 171 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 161 - repo, err := repo_service.CreateRepository(db.DefaultContext, user, user, repo_service.CreateRepoOptions{ 162 - Name: "repo-to-push", 163 - Description: "test git push", 164 - AutoInit: false, 165 - DefaultBranch: "main", 166 - IsPrivate: false, 167 - }) 168 - require.NoError(t, err) 169 - require.NotEmpty(t, repo) 172 + 173 + forEachObjectFormat(t, func(t *testing.T, objectFormat git.ObjectFormat) { 174 + repo, err := repo_service.CreateRepository(db.DefaultContext, user, user, repo_service.CreateRepoOptions{ 175 + Name: "repo-to-push", 176 + Description: "test git push", 177 + AutoInit: false, 178 + DefaultBranch: "main", 179 + IsPrivate: false, 180 + ObjectFormatName: objectFormat.Name(), 181 + }) 182 + require.NoError(t, err) 183 + require.NotEmpty(t, repo) 170 184 171 - gitPath := t.TempDir() 185 + gitPath := t.TempDir() 172 186 173 - doGitInitTestRepository(gitPath)(t) 187 + doGitInitTestRepository(gitPath, objectFormat)(t) 174 188 175 - u.Path = repo.FullName() + ".git" 176 - u.User = url.UserPassword(user.LowerName, userPassword) 177 - doGitAddRemote(gitPath, "origin", u)(t) 189 + u.Path = repo.FullName() + ".git" 190 + u.User = url.UserPassword(user.LowerName, userPassword) 191 + doGitAddRemote(gitPath, "origin", u)(t) 178 192 179 - t.Run("Unknown push options are rejected", func(t *testing.T) { 180 - logChecker, cleanup := test.NewLogChecker(log.DEFAULT, log.TRACE) 181 - logChecker.Filter("unknown option").StopMark("Git push options validation") 182 - defer cleanup() 183 - branchName := "branch0" 184 - doGitCreateBranch(gitPath, branchName)(t) 185 - doGitPushTestRepositoryFail(gitPath, "origin", branchName, "-o", "repo.template=false", "-o", "uknownoption=randomvalue")(t) 186 - logFiltered, logStopped := logChecker.Check(5 * time.Second) 187 - assert.True(t, logStopped) 188 - assert.True(t, logFiltered[0]) 189 - }) 193 + t.Run("Unknown push options are rejected", func(t *testing.T) { 194 + logChecker, cleanup := test.NewLogChecker(log.DEFAULT, log.TRACE) 195 + logChecker.Filter("unknown option").StopMark("Git push options validation") 196 + defer cleanup() 197 + branchName := "branch0" 198 + doGitCreateBranch(gitPath, branchName)(t) 199 + doGitPushTestRepositoryFail(gitPath, "origin", branchName, "-o", "repo.template=false", "-o", "uknownoption=randomvalue")(t) 200 + logFiltered, logStopped := logChecker.Check(5 * time.Second) 201 + assert.True(t, logStopped) 202 + assert.True(t, logFiltered[0]) 203 + }) 190 204 191 - t.Run("Owner sets private & template to true via push options", func(t *testing.T) { 192 - branchName := "branch1" 193 - doGitCreateBranch(gitPath, branchName)(t) 194 - doGitPushTestRepository(gitPath, "origin", branchName, "-o", "repo.private=true", "-o", "repo.template=true")(t) 195 - repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, user.Name, "repo-to-push") 196 - require.NoError(t, err) 197 - require.True(t, repo.IsPrivate) 198 - require.True(t, repo.IsTemplate) 199 - }) 205 + t.Run("Owner sets private & template to true via push options", func(t *testing.T) { 206 + branchName := "branch1" 207 + doGitCreateBranch(gitPath, branchName)(t) 208 + doGitPushTestRepository(gitPath, "origin", branchName, "-o", "repo.private=true", "-o", "repo.template=true")(t) 209 + repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, user.Name, "repo-to-push") 210 + require.NoError(t, err) 211 + require.True(t, repo.IsPrivate) 212 + require.True(t, repo.IsTemplate) 213 + }) 200 214 201 - t.Run("Owner sets private & template to false via push options", func(t *testing.T) { 202 - branchName := "branch2" 203 - doGitCreateBranch(gitPath, branchName)(t) 204 - doGitPushTestRepository(gitPath, "origin", branchName, "-o", "repo.private=false", "-o", "repo.template=false")(t) 205 - repo, err = repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, user.Name, "repo-to-push") 206 - require.NoError(t, err) 207 - require.False(t, repo.IsPrivate) 208 - require.False(t, repo.IsTemplate) 209 - }) 215 + t.Run("Owner sets private & template to false via push options", func(t *testing.T) { 216 + branchName := "branch2" 217 + doGitCreateBranch(gitPath, branchName)(t) 218 + doGitPushTestRepository(gitPath, "origin", branchName, "-o", "repo.private=false", "-o", "repo.template=false")(t) 219 + repo, err = repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, user.Name, "repo-to-push") 220 + require.NoError(t, err) 221 + require.False(t, repo.IsPrivate) 222 + require.False(t, repo.IsTemplate) 223 + }) 210 224 211 - // create a collaborator with write access 212 - collaborator := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) 213 - u.User = url.UserPassword(collaborator.LowerName, userPassword) 214 - doGitAddRemote(gitPath, "collaborator", u)(t) 215 - repo_module.AddCollaborator(db.DefaultContext, repo, collaborator) 225 + // create a collaborator with write access 226 + collaborator := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) 227 + u.User = url.UserPassword(collaborator.LowerName, userPassword) 228 + doGitAddRemote(gitPath, "collaborator", u)(t) 229 + repo_module.AddCollaborator(db.DefaultContext, repo, collaborator) 216 230 217 - t.Run("Collaborator with write access is allowed to push", func(t *testing.T) { 218 - branchName := "branch3" 219 - doGitCreateBranch(gitPath, branchName)(t) 220 - doGitPushTestRepository(gitPath, "collaborator", branchName)(t) 221 - }) 231 + t.Run("Collaborator with write access is allowed to push", func(t *testing.T) { 232 + branchName := "branch3" 233 + doGitCreateBranch(gitPath, branchName)(t) 234 + doGitPushTestRepository(gitPath, "collaborator", branchName)(t) 235 + }) 222 236 223 - t.Run("Collaborator with write access fails to change private & template via push options", func(t *testing.T) { 224 - logChecker, cleanup := test.NewLogChecker(log.DEFAULT, log.TRACE) 225 - logChecker.Filter("permission denied for changing repo settings").StopMark("Git push options validation") 226 - defer cleanup() 227 - branchName := "branch4" 228 - doGitCreateBranch(gitPath, branchName)(t) 229 - doGitPushTestRepositoryFail(gitPath, "collaborator", branchName, "-o", "repo.private=true", "-o", "repo.template=true")(t) 230 - repo, err = repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, user.Name, "repo-to-push") 231 - require.NoError(t, err) 232 - require.False(t, repo.IsPrivate) 233 - require.False(t, repo.IsTemplate) 234 - logFiltered, logStopped := logChecker.Check(5 * time.Second) 235 - assert.True(t, logStopped) 236 - assert.True(t, logFiltered[0]) 237 + t.Run("Collaborator with write access fails to change private & template via push options", func(t *testing.T) { 238 + logChecker, cleanup := test.NewLogChecker(log.DEFAULT, log.TRACE) 239 + logChecker.Filter("permission denied for changing repo settings").StopMark("Git push options validation") 240 + defer cleanup() 241 + branchName := "branch4" 242 + doGitCreateBranch(gitPath, branchName)(t) 243 + doGitPushTestRepositoryFail(gitPath, "collaborator", branchName, "-o", "repo.private=true", "-o", "repo.template=true")(t) 244 + repo, err = repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, user.Name, "repo-to-push") 245 + require.NoError(t, err) 246 + require.False(t, repo.IsPrivate) 247 + require.False(t, repo.IsTemplate) 248 + logFiltered, logStopped := logChecker.Check(5 * time.Second) 249 + assert.True(t, logStopped) 250 + assert.True(t, logFiltered[0]) 251 + }) 252 + 253 + require.NoError(t, repo_service.DeleteRepositoryDirectly(db.DefaultContext, user, repo.ID)) 237 254 }) 238 - 239 - require.NoError(t, repo_service.DeleteRepositoryDirectly(db.DefaultContext, user, repo.ID)) 240 255 }
+1 -1
tests/integration/git_test.go
··· 598 598 tmpDir := t.TempDir() 599 599 600 600 // Now create local repository to push as our test and set its origin 601 - t.Run("InitTestRepository", doGitInitTestRepository(tmpDir)) 601 + t.Run("InitTestRepository", doGitInitTestRepository(tmpDir, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat 602 602 t.Run("AddRemote", doGitAddRemote(tmpDir, "origin", u)) 603 603 604 604 // Disable "Push To Create" and attempt to push
+1 -1
tests/integration/ssh_key_test.go
··· 64 64 // Setup the testing repository 65 65 dstPath := t.TempDir() 66 66 67 - t.Run("InitTestRepository", doGitInitTestRepository(dstPath)) 67 + t.Run("InitTestRepository", doGitInitTestRepository(dstPath, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat 68 68 69 69 // Setup remote link 70 70 sshURL := createSSHUrl(ctx.GitPath(), u)