mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 08:34:30 +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])
 | 
			
		||||
	needCheckUserNames := make(container.Set[string])
 | 
			
		||||
	noReplyAddressSuffix := "@" + strings.ToLower(setting.Service.NoReplyAddress)
 | 
			
		||||
	for _, email := range emails {
 | 
			
		||||
		if strings.HasSuffix(email, "@"+setting.Service.NoReplyAddress) {
 | 
			
		||||
			username := strings.TrimSuffix(email, "@"+setting.Service.NoReplyAddress)
 | 
			
		||||
			needCheckUserNames.Add(strings.ToLower(username))
 | 
			
		||||
		emailLower := strings.ToLower(email)
 | 
			
		||||
		if noReplyUserNameLower, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix); ok {
 | 
			
		||||
			needCheckUserNames.Add(noReplyUserNameLower)
 | 
			
		||||
			needCheckEmails.Add(emailLower)
 | 
			
		||||
		} else {
 | 
			
		||||
			needCheckEmails.Add(strings.ToLower(email))
 | 
			
		||||
			needCheckEmails.Add(emailLower)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -85,6 +85,11 @@ func TestUserEmails(t *testing.T) {
 | 
			
		||||
				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 {
 | 
			
		||||
	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
 | 
			
		||||
	Committer     *Signature // never nil
 | 
			
		||||
	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.
 | 
			
		||||
// 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 {
 | 
			
		||||
	// If no signature, just report the committer
 | 
			
		||||
	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
 | 
			
		||||
	if committer != nil && committer.ID != 0 {
 | 
			
		||||
	if committer.ID != 0 {
 | 
			
		||||
		keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
 | 
			
		||||
			OwnerID: committer.ID,
 | 
			
		||||
		})
 | 
			
		||||
@ -373,7 +374,7 @@ func verifySSHCommitVerificationByInstanceKey(c *git.Commit, committerUser, sign
 | 
			
		||||
// parseCommitWithSSHSignature check if signature is good against keystore.
 | 
			
		||||
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
 | 
			
		||||
	if committerUser != nil && committerUser.ID != 0 {
 | 
			
		||||
	if committerUser.ID != 0 {
 | 
			
		||||
		keys, err := db.Find[asymkey_model.PublicKey](ctx, asymkey_model.FindPublicKeyOptions{
 | 
			
		||||
			OwnerID:    committerUser.ID,
 | 
			
		||||
			NotKeytype: asymkey_model.KeyTypePrincipal,
 | 
			
		||||
 | 
			
		||||
@ -24,103 +24,59 @@ import (
 | 
			
		||||
 | 
			
		||||
func TestRepoCommits(t *testing.T) {
 | 
			
		||||
	defer tests.PrepareTestEnv(t)()
 | 
			
		||||
 | 
			
		||||
	session := loginUser(t, "user2")
 | 
			
		||||
 | 
			
		||||
	// Request repository commits page
 | 
			
		||||
	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")
 | 
			
		||||
	t.Run("CommitList", func(t *testing.T) {
 | 
			
		||||
		req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
 | 
			
		||||
		resp := session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
 | 
			
		||||
		var commits, userHrefs []string
 | 
			
		||||
		doc := NewHTMLParser(t, resp.Body)
 | 
			
		||||
	var commits []string
 | 
			
		||||
		doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
 | 
			
		||||
		commitURL, _ := s.Attr("href")
 | 
			
		||||
		commits = append(commits, path.Base(commitURL))
 | 
			
		||||
			commits = append(commits, path.Base(s.AttrOr("href", "")))
 | 
			
		||||
		})
 | 
			
		||||
		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)
 | 
			
		||||
 | 
			
		||||
	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)
 | 
			
		||||
 | 
			
		||||
	// 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{}
 | 
			
		||||
	doc.doc.Find(".latest-commit .author-wrapper").Each(func(i int, s *goquery.Selection) {
 | 
			
		||||
		userHref, _ := s.Attr("href")
 | 
			
		||||
		userHrefs = append(userHrefs, userHref)
 | 
			
		||||
	t.Run("LastCommit", func(t *testing.T) {
 | 
			
		||||
		req := NewRequest(t, "GET", "/user2/repo16")
 | 
			
		||||
		resp := session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
		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) {
 | 
			
		||||
	// Commits list with Gitea User has been tested in Test_ReposGitCommitListNotMaster
 | 
			
		||||
	defer tests.PrepareTestEnv(t)()
 | 
			
		||||
	session := loginUser(t, "user2")
 | 
			
		||||
 | 
			
		||||
	// check commits list for a repository with no gitea user
 | 
			
		||||
	req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
 | 
			
		||||
	t.Run("CommitListNonExistingCommiter", func(t *testing.T) {
 | 
			
		||||
		// check the commit list for a repository with no gitea user
 | 
			
		||||
		// * commit 985f0301dba5e7b34be866819cd15ad3d8f508ee (branch2)
 | 
			
		||||
		// * Author: 6543 <6543@obermui.de>
 | 
			
		||||
		req := NewRequest(t, "GET", "/user2/repo1/commits/branch/branch2")
 | 
			
		||||
		resp := session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
 | 
			
		||||
		doc := NewHTMLParser(t, resp.Body)
 | 
			
		||||
	var commits []string
 | 
			
		||||
	doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
 | 
			
		||||
		commitURL, _ := s.Attr("href")
 | 
			
		||||
		commits = append(commits, path.Base(commitURL))
 | 
			
		||||
		commitHref := doc.doc.Find("#commits-table tr:first-child .commit-id-short").AttrOr("href", "")
 | 
			
		||||
		assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
 | 
			
		||||
		authorElem := doc.doc.Find("#commits-table tr:first-child .author-wrapper")
 | 
			
		||||
		assert.Equal(t, "6543", authorElem.Text())
 | 
			
		||||
		assert.Equal(t, "span", authorElem.Nodes[0].Data)
 | 
			
		||||
	})
 | 
			
		||||
	assert.Equal(t, []string{"65f1bf27bc3bf70f64657658635e66094edbcb4d"}, commits)
 | 
			
		||||
 | 
			
		||||
	var gitUsers []string
 | 
			
		||||
	doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
 | 
			
		||||
		assert.Equal(t, "span", goquery.NodeName(s))
 | 
			
		||||
		gitUser := s.Text()
 | 
			
		||||
		gitUsers = append(gitUsers, gitUser)
 | 
			
		||||
	t.Run("LastCommitNonExistingCommiter", func(t *testing.T) {
 | 
			
		||||
		req := NewRequest(t, "GET", "/user2/repo1/src/branch/branch2")
 | 
			
		||||
		resp := session.MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
		doc := NewHTMLParser(t, resp.Body)
 | 
			
		||||
		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) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user