mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-24 13:43:43 +09:00
fix(repo): commit page fails to render unsigned commits with a different committer (#39381)
Since #39229 the commit page header dereferences `.Verification.CommittingUser` when the committer is not the author. `Verification` is `nil` for unsigned commits (see `repo.Diff`), so opening such a commit — a rebased or cherry-picked one, for example — logs a template error and the page comes out truncated: ``` Render failed: failed to render template: repo/commit_page, error: template error: builtin(bindata):repo/commit_page:138:22 : executing "repo/commit_page" at <.Verification.CommittingUser>: nil pointer evaluating interface {}.CommittingUser ``` This guards the access and adds an integration test that creates a commit with distinct author and committer identities and checks the page renders completely (the status stays 200 on a mid-render failure, so the test looks at the body). _The fix was worked out with help from an AI assistant; I reviewed and tested it myself._ --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"gitea.dev/modules/web"
|
||||
"gitea.dev/modules/web/middleware"
|
||||
"gitea.dev/routers"
|
||||
"gitea.dev/routers/common"
|
||||
gitea_context "gitea.dev/services/context"
|
||||
"gitea.dev/tests"
|
||||
|
||||
@@ -289,6 +290,9 @@ func MakeRequest(t testing.TB, rw *RequestWrapper, expectedStatus int) *httptest
|
||||
// don't use "require" which exits the test case and makes "wait group" wait forever
|
||||
assert.Equal(t, expectedStatus, recorder.Code, "Request: %s %s", req.Method, req.URL.String())
|
||||
}
|
||||
if expectedStatus != http.StatusInternalServerError {
|
||||
assert.NotContains(t, recorder.Body.String(), common.PageInternalServerErrorMark, "Request: %s %s, response should not contain internal server error", req.Method, req.URL.String())
|
||||
}
|
||||
}
|
||||
return recorder
|
||||
}
|
||||
|
||||
@@ -14,7 +14,10 @@ import (
|
||||
auth_model "gitea.dev/models/auth"
|
||||
"gitea.dev/models/db"
|
||||
git_model "gitea.dev/models/git"
|
||||
repo_model "gitea.dev/models/repo"
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/commitstatus"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/json"
|
||||
"gitea.dev/modules/setting"
|
||||
api "gitea.dev/modules/structs"
|
||||
@@ -77,7 +80,6 @@ func TestRepoCommits(t *testing.T) {
|
||||
const (
|
||||
commitID = "5099b81332712fe655e34e8dd63574f503f61811"
|
||||
expectedCommitterTime = "2017-08-06T19:56:13+02:00"
|
||||
authorTime = "2017-08-06T19:55:01+02:00"
|
||||
)
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
|
||||
@@ -104,6 +106,24 @@ func TestRepoCommits(t *testing.T) {
|
||||
authorElem := doc.doc.Find(".latest-commit .avatar-stack-names")
|
||||
assert.Equal(t, "6543", strings.TrimSpace(authorElem.Text()))
|
||||
})
|
||||
|
||||
t.Run("CommitterIsNotAuthor", func(t *testing.T) {
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
err := git.ForceFastImport(t.Context(), repo1, []git.FastImportCommit{
|
||||
{
|
||||
Ref: "refs/heads/test-branch-committer",
|
||||
Files: []git.FastImportFile{{Path: "dummy-file.txt", Content: "dummy-content"}},
|
||||
Author: &git.Signature{Name: "real-commit-author", Email: "dummy-email1@example.com"},
|
||||
Committer: &git.Signature{Name: "non-author-committer", Email: "dummy-email2@example.com"},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
commitID, err := git.GetBranchCommitID(t.Context(), repo1, "test-branch-committer")
|
||||
require.NoError(t, err)
|
||||
req := NewRequest(t, "GET", "/user2/repo1/commit/"+commitID)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
assert.Contains(t, resp.Body.String(), "non-author-committer")
|
||||
})
|
||||
}
|
||||
|
||||
func TestRepoCommitsWithStatus(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user