mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-05 01:45:41 +01:00
fix test
This commit is contained in:
parent
838b984029
commit
53146a8ca7
@ -1189,12 +1189,14 @@ func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, erro
|
|||||||
|
|
||||||
needCheckEmails := make(container.Set[string])
|
needCheckEmails := make(container.Set[string])
|
||||||
needCheckUserNames := make(container.Set[string])
|
needCheckUserNames := make(container.Set[string])
|
||||||
|
noReplyAddressSuffix := "@" + strings.ToLower(setting.Service.NoReplyAddress)
|
||||||
for _, email := range emails {
|
for _, email := range emails {
|
||||||
if strings.HasSuffix(email, "@"+setting.Service.NoReplyAddress) {
|
emailLower := strings.ToLower(email)
|
||||||
username := strings.TrimSuffix(email, "@"+setting.Service.NoReplyAddress)
|
if noReplyUserNameLower, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix); ok {
|
||||||
needCheckUserNames.Add(strings.ToLower(username))
|
needCheckUserNames.Add(noReplyUserNameLower)
|
||||||
|
needCheckEmails.Add(emailLower)
|
||||||
} else {
|
} else {
|
||||||
needCheckEmails.Add(strings.ToLower(email))
|
needCheckEmails.Add(emailLower)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,6 +85,11 @@ func TestUserEmails(t *testing.T) {
|
|||||||
testGetUserByEmail(t, c.Email, c.UID)
|
testGetUserByEmail(t, c.Email, c.UID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("NoReplyConflict", func(t *testing.T) {
|
||||||
|
setting.Service.NoReplyAddress = "example.com"
|
||||||
|
testGetUserByEmail(t, "user1-2@example.COM", 1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import (
|
|||||||
type Commit struct {
|
type Commit struct {
|
||||||
Tree // FIXME: bad design, this field can be nil if the commit is from "last commit cache"
|
Tree // FIXME: bad design, this field can be nil if the commit is from "last commit cache"
|
||||||
|
|
||||||
ID ObjectID // The ID of this commit object
|
ID ObjectID
|
||||||
Author *Signature // never nil
|
Author *Signature // never nil
|
||||||
Committer *Signature // never nil
|
Committer *Signature // never nil
|
||||||
CommitMessage string
|
CommitMessage string
|
||||||
|
|||||||
@ -36,7 +36,8 @@ func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *asymkey_model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseCommitWithSignatureCommitter parses a commit's GPG or SSH signature.
|
// ParseCommitWithSignatureCommitter parses a commit's GPG or SSH signature.
|
||||||
// If the commit is singed by an instance key, then committer is nil.
|
// If the commit is singed by an instance key, then committer can be nil.
|
||||||
|
// If the signature exists, even if committer is nil, the returned CommittingUser will be a non-nil fake user.
|
||||||
func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, committer *user_model.User) *asymkey_model.CommitVerification {
|
func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, committer *user_model.User) *asymkey_model.CommitVerification {
|
||||||
// If no signature, just report the committer
|
// If no signature, just report the committer
|
||||||
if c.Signature == nil {
|
if c.Signature == nil {
|
||||||
@ -91,7 +92,7 @@ func parseCommitWithGPGSignature(ctx context.Context, c *git.Commit, committer *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now try to associate the signature with the committer, if present
|
// Now try to associate the signature with the committer, if present
|
||||||
if committer != nil && committer.ID != 0 {
|
if committer.ID != 0 {
|
||||||
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
|
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
|
||||||
OwnerID: committer.ID,
|
OwnerID: committer.ID,
|
||||||
})
|
})
|
||||||
@ -373,7 +374,7 @@ func verifySSHCommitVerificationByInstanceKey(c *git.Commit, committerUser, sign
|
|||||||
// parseCommitWithSSHSignature check if signature is good against keystore.
|
// parseCommitWithSSHSignature check if signature is good against keystore.
|
||||||
func parseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committerUser *user_model.User) *asymkey_model.CommitVerification {
|
func parseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committerUser *user_model.User) *asymkey_model.CommitVerification {
|
||||||
// Now try to associate the signature with the committer, if present
|
// Now try to associate the signature with the committer, if present
|
||||||
if committerUser != nil && committerUser.ID != 0 {
|
if committerUser.ID != 0 {
|
||||||
keys, err := db.Find[asymkey_model.PublicKey](ctx, asymkey_model.FindPublicKeyOptions{
|
keys, err := db.Find[asymkey_model.PublicKey](ctx, asymkey_model.FindPublicKeyOptions{
|
||||||
OwnerID: committerUser.ID,
|
OwnerID: committerUser.ID,
|
||||||
NotKeytype: asymkey_model.KeyTypePrincipal,
|
NotKeytype: asymkey_model.KeyTypePrincipal,
|
||||||
|
|||||||
@ -24,103 +24,59 @@ import (
|
|||||||
|
|
||||||
func TestRepoCommits(t *testing.T) {
|
func TestRepoCommits(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
|
|
||||||
// Request repository commits page
|
t.Run("CommitList", func(t *testing.T) {
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
|
||||||
commitURL, exists := doc.doc.Find("#commits-table .commit-id-short").Attr("href")
|
|
||||||
assert.True(t, exists)
|
|
||||||
assert.NotEmpty(t, commitURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_ReposGitCommitListNotMaster(t *testing.T) {
|
|
||||||
defer tests.PrepareTestEnv(t)()
|
|
||||||
session := loginUser(t, "user2")
|
|
||||||
req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
|
req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
var commits, userHrefs []string
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
var commits []string
|
|
||||||
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
|
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
|
||||||
commitURL, _ := s.Attr("href")
|
commits = append(commits, path.Base(s.AttrOr("href", "")))
|
||||||
commits = append(commits, path.Base(commitURL))
|
})
|
||||||
|
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
|
||||||
|
userHrefs = append(userHrefs, s.AttrOr("href", ""))
|
||||||
})
|
})
|
||||||
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324", "27566bd5738fc8b4e3fef3c5e72cce608537bd95", "5099b81332712fe655e34e8dd63574f503f61811"}, commits)
|
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324", "27566bd5738fc8b4e3fef3c5e72cce608537bd95", "5099b81332712fe655e34e8dd63574f503f61811"}, commits)
|
||||||
|
|
||||||
var userHrefs []string
|
|
||||||
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
|
|
||||||
userHref, _ := s.Attr("href")
|
|
||||||
userHrefs = append(userHrefs, userHref)
|
|
||||||
})
|
|
||||||
assert.Equal(t, []string{"/user2", "/user21", "/user2"}, userHrefs)
|
assert.Equal(t, []string{"/user2", "/user21", "/user2"}, userHrefs)
|
||||||
|
|
||||||
// check last commit author wrapper
|
|
||||||
req = NewRequest(t, "GET", "/user2/repo16")
|
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
||||||
|
|
||||||
doc = NewHTMLParser(t, resp.Body)
|
|
||||||
commits = []string{}
|
|
||||||
doc.doc.Find(".latest-commit .commit-id-short").Each(func(i int, s *goquery.Selection) {
|
|
||||||
commitURL, _ := s.Attr("href")
|
|
||||||
commits = append(commits, path.Base(commitURL))
|
|
||||||
})
|
})
|
||||||
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324"}, commits)
|
|
||||||
|
|
||||||
userHrefs = []string{}
|
t.Run("LastCommit", func(t *testing.T) {
|
||||||
doc.doc.Find(".latest-commit .author-wrapper").Each(func(i int, s *goquery.Selection) {
|
req := NewRequest(t, "GET", "/user2/repo16")
|
||||||
userHref, _ := s.Attr("href")
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
userHrefs = append(userHrefs, userHref)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
|
commitHref := doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href", "")
|
||||||
|
authorHref := doc.doc.Find(".latest-commit .author-wrapper").AttrOr("href", "")
|
||||||
|
assert.Equal(t, "/user2/repo16/commit/69554a64c1e6030f051e5c3f94bfbd773cd6a324", commitHref)
|
||||||
|
assert.Equal(t, "/user2", authorHref)
|
||||||
})
|
})
|
||||||
assert.Equal(t, []string{"/user2"}, userHrefs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_ReposGitCommitListNoGiteaUser(t *testing.T) {
|
t.Run("CommitListNonExistingCommiter", func(t *testing.T) {
|
||||||
// Commits list with Gitea User has been tested in Test_ReposGitCommitListNotMaster
|
// check the commit list for a repository with no gitea user
|
||||||
defer tests.PrepareTestEnv(t)()
|
// * commit 985f0301dba5e7b34be866819cd15ad3d8f508ee (branch2)
|
||||||
session := loginUser(t, "user2")
|
// * Author: 6543 <6543@obermui.de>
|
||||||
|
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/branch2")
|
||||||
// check commits list for a repository with no gitea user
|
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
var commits []string
|
commitHref := doc.doc.Find("#commits-table tr:first-child .commit-id-short").AttrOr("href", "")
|
||||||
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
|
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
|
||||||
commitURL, _ := s.Attr("href")
|
authorElem := doc.doc.Find("#commits-table tr:first-child .author-wrapper")
|
||||||
commits = append(commits, path.Base(commitURL))
|
assert.Equal(t, "6543", authorElem.Text())
|
||||||
|
assert.Equal(t, "span", authorElem.Nodes[0].Data)
|
||||||
})
|
})
|
||||||
assert.Equal(t, []string{"65f1bf27bc3bf70f64657658635e66094edbcb4d"}, commits)
|
|
||||||
|
|
||||||
var gitUsers []string
|
t.Run("LastCommitNonExistingCommiter", func(t *testing.T) {
|
||||||
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
|
req := NewRequest(t, "GET", "/user2/repo1/src/branch/branch2")
|
||||||
assert.Equal(t, "span", goquery.NodeName(s))
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
gitUser := s.Text()
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
gitUsers = append(gitUsers, gitUser)
|
commitHref := doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href", "")
|
||||||
|
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
|
||||||
|
authorElem := doc.doc.Find(".latest-commit .author-wrapper")
|
||||||
|
assert.Equal(t, "6543", authorElem.Text())
|
||||||
|
assert.Equal(t, "span", authorElem.Nodes[0].Data)
|
||||||
})
|
})
|
||||||
assert.Equal(t, []string{"user1"}, gitUsers)
|
|
||||||
|
|
||||||
// check last commit author wrapper
|
|
||||||
req = NewRequest(t, "GET", "/user2/repo1")
|
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
||||||
|
|
||||||
doc = NewHTMLParser(t, resp.Body)
|
|
||||||
commits = []string{}
|
|
||||||
doc.doc.Find(".latest-commit .commit-id-short").Each(func(i int, s *goquery.Selection) {
|
|
||||||
commitURL, _ := s.Attr("href")
|
|
||||||
commits = append(commits, path.Base(commitURL))
|
|
||||||
})
|
|
||||||
assert.Equal(t, []string{"65f1bf27bc3bf70f64657658635e66094edbcb4d"}, commits)
|
|
||||||
|
|
||||||
gitUsers = []string{}
|
|
||||||
doc.doc.Find(".latest-commit .author-wrapper").Each(func(i int, s *goquery.Selection) {
|
|
||||||
assert.Equal(t, "span", goquery.NodeName(s))
|
|
||||||
gitUsers = append(gitUsers, s.Text())
|
|
||||||
})
|
|
||||||
assert.Equal(t, []string{"user1"}, gitUsers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user