Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53146a8

Browse files
committed
fix test
1 parent838b984 commit53146a8

File tree

5 files changed

+60
-96
lines changed

5 files changed

+60
-96
lines changed

‎models/user/user.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,12 +1189,14 @@ func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, erro
11891189

11901190
needCheckEmails:=make(container.Set[string])
11911191
needCheckUserNames:=make(container.Set[string])
1192+
noReplyAddressSuffix:="@"+strings.ToLower(setting.Service.NoReplyAddress)
11921193
for_,email:=rangeemails {
1193-
ifstrings.HasSuffix(email,"@"+setting.Service.NoReplyAddress) {
1194-
username:=strings.TrimSuffix(email,"@"+setting.Service.NoReplyAddress)
1195-
needCheckUserNames.Add(strings.ToLower(username))
1194+
emailLower:=strings.ToLower(email)
1195+
ifnoReplyUserNameLower,ok:=strings.CutSuffix(emailLower,noReplyAddressSuffix);ok {
1196+
needCheckUserNames.Add(noReplyUserNameLower)
1197+
needCheckEmails.Add(emailLower)
11961198
}else {
1197-
needCheckEmails.Add(strings.ToLower(email))
1199+
needCheckEmails.Add(emailLower)
11981200
}
11991201
}
12001202

‎models/user/user_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func TestUserEmails(t *testing.T) {
8585
testGetUserByEmail(t,c.Email,c.UID)
8686
})
8787
}
88+
89+
t.Run("NoReplyConflict",func(t*testing.T) {
90+
setting.Service.NoReplyAddress="example.com"
91+
testGetUserByEmail(t,"user1-2@example.COM",1)
92+
})
8893
})
8994
}
9095

‎modules/git/commit.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
typeCommitstruct {
2323
Tree// FIXME: bad design, this field can be nil if the commit is from "last commit cache"
2424

25-
IDObjectID// The ID of this commit object
25+
IDObjectID
2626
Author*Signature// never nil
2727
Committer*Signature// never nil
2828
CommitMessagestring

‎services/asymkey/commit.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *asymkey_model
3636
}
3737

3838
// ParseCommitWithSignatureCommitter parses a commit's GPG or SSH signature.
39-
// If the commit is singed by an instance key, then committer is nil.
39+
// If the commit is singed by an instance key, then committer can be nil.
40+
// If the signature exists, even if committer is nil, the returned CommittingUser will be a non-nil fake user.
4041
funcParseCommitWithSignatureCommitter(ctx context.Context,c*git.Commit,committer*user_model.User)*asymkey_model.CommitVerification {
4142
// If no signature, just report the committer
4243
ifc.Signature==nil {
@@ -91,7 +92,7 @@ func parseCommitWithGPGSignature(ctx context.Context, c *git.Commit, committer *
9192
}
9293

9394
// Now try to associate the signature with the committer, if present
94-
ifcommitter!=nil&&committer.ID!=0 {
95+
ifcommitter.ID!=0 {
9596
keys,err:=db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
9697
OwnerID:committer.ID,
9798
})
@@ -373,7 +374,7 @@ func verifySSHCommitVerificationByInstanceKey(c *git.Commit, committerUser, sign
373374
// parseCommitWithSSHSignature check if signature is good against keystore.
374375
funcparseCommitWithSSHSignature(ctx context.Context,c*git.Commit,committerUser*user_model.User)*asymkey_model.CommitVerification {
375376
// Now try to associate the signature with the committer, if present
376-
ifcommitterUser!=nil&&committerUser.ID!=0 {
377+
ifcommitterUser.ID!=0 {
377378
keys,err:=db.Find[asymkey_model.PublicKey](ctx, asymkey_model.FindPublicKeyOptions{
378379
OwnerID:committerUser.ID,
379380
NotKeytype:asymkey_model.KeyTypePrincipal,

‎tests/integration/repo_commits_test.go‎

Lines changed: 44 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -24,103 +24,59 @@ import (
2424

2525
funcTestRepoCommits(t*testing.T) {
2626
defertests.PrepareTestEnv(t)()
27-
28-
session:=loginUser(t,"user2")
29-
30-
// Request repository commits page
31-
req:=NewRequest(t,"GET","/user2/repo1/commits/branch/master")
32-
resp:=session.MakeRequest(t,req,http.StatusOK)
33-
34-
doc:=NewHTMLParser(t,resp.Body)
35-
commitURL,exists:=doc.doc.Find("#commits-table .commit-id-short").Attr("href")
36-
assert.True(t,exists)
37-
assert.NotEmpty(t,commitURL)
38-
}
39-
40-
funcTest_ReposGitCommitListNotMaster(t*testing.T) {
41-
defertests.PrepareTestEnv(t)()
42-
session:=loginUser(t,"user2")
43-
req:=NewRequest(t,"GET","/user2/repo16/commits/branch/master")
44-
resp:=session.MakeRequest(t,req,http.StatusOK)
45-
46-
doc:=NewHTMLParser(t,resp.Body)
47-
varcommits []string
48-
doc.doc.Find("#commits-table .commit-id-short").Each(func(iint,s*goquery.Selection) {
49-
commitURL,_:=s.Attr("href")
50-
commits=append(commits,path.Base(commitURL))
51-
})
52-
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324","27566bd5738fc8b4e3fef3c5e72cce608537bd95","5099b81332712fe655e34e8dd63574f503f61811"},commits)
53-
54-
varuserHrefs []string
55-
doc.doc.Find("#commits-table .author-wrapper").Each(func(iint,s*goquery.Selection) {
56-
userHref,_:=s.Attr("href")
57-
userHrefs=append(userHrefs,userHref)
58-
})
59-
assert.Equal(t, []string{"/user2","/user21","/user2"},userHrefs)
60-
61-
// check last commit author wrapper
62-
req=NewRequest(t,"GET","/user2/repo16")
63-
resp=session.MakeRequest(t,req,http.StatusOK)
64-
65-
doc=NewHTMLParser(t,resp.Body)
66-
commits= []string{}
67-
doc.doc.Find(".latest-commit .commit-id-short").Each(func(iint,s*goquery.Selection) {
68-
commitURL,_:=s.Attr("href")
69-
commits=append(commits,path.Base(commitURL))
70-
})
71-
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324"},commits)
72-
73-
userHrefs= []string{}
74-
doc.doc.Find(".latest-commit .author-wrapper").Each(func(iint,s*goquery.Selection) {
75-
userHref,_:=s.Attr("href")
76-
userHrefs=append(userHrefs,userHref)
77-
})
78-
assert.Equal(t, []string{"/user2"},userHrefs)
79-
}
80-
81-
funcTest_ReposGitCommitListNoGiteaUser(t*testing.T) {
82-
// Commits list with Gitea User has been tested in Test_ReposGitCommitListNotMaster
83-
defertests.PrepareTestEnv(t)()
8427
session:=loginUser(t,"user2")
8528

86-
// check commits list for a repository with no gitea user
87-
req:=NewRequest(t,"GET","/user2/repo1/commits/branch/master")
88-
resp:=session.MakeRequest(t,req,http.StatusOK)
89-
90-
doc:=NewHTMLParser(t,resp.Body)
91-
varcommits []string
92-
doc.doc.Find("#commits-table .commit-id-short").Each(func(iint,s*goquery.Selection) {
93-
commitURL,_:=s.Attr("href")
94-
commits=append(commits,path.Base(commitURL))
29+
t.Run("CommitList",func(t*testing.T) {
30+
req:=NewRequest(t,"GET","/user2/repo16/commits/branch/master")
31+
resp:=session.MakeRequest(t,req,http.StatusOK)
32+
33+
varcommits,userHrefs []string
34+
doc:=NewHTMLParser(t,resp.Body)
35+
doc.doc.Find("#commits-table .commit-id-short").Each(func(iint,s*goquery.Selection) {
36+
commits=append(commits,path.Base(s.AttrOr("href","")))
37+
})
38+
doc.doc.Find("#commits-table .author-wrapper").Each(func(iint,s*goquery.Selection) {
39+
userHrefs=append(userHrefs,s.AttrOr("href",""))
40+
})
41+
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324","27566bd5738fc8b4e3fef3c5e72cce608537bd95","5099b81332712fe655e34e8dd63574f503f61811"},commits)
42+
assert.Equal(t, []string{"/user2","/user21","/user2"},userHrefs)
9543
})
96-
assert.Equal(t, []string{"65f1bf27bc3bf70f64657658635e66094edbcb4d"},commits)
9744

98-
vargitUsers []string
99-
doc.doc.Find("#commits-table .author-wrapper").Each(func(iint,s*goquery.Selection) {
100-
assert.Equal(t,"span",goquery.NodeName(s))
101-
gitUser:=s.Text()
102-
gitUsers=append(gitUsers,gitUser)
45+
t.Run("LastCommit",func(t*testing.T) {
46+
req:=NewRequest(t,"GET","/user2/repo16")
47+
resp:=session.MakeRequest(t,req,http.StatusOK)
48+
doc:=NewHTMLParser(t,resp.Body)
49+
commitHref:=doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href","")
50+
authorHref:=doc.doc.Find(".latest-commit .author-wrapper").AttrOr("href","")
51+
assert.Equal(t,"/user2/repo16/commit/69554a64c1e6030f051e5c3f94bfbd773cd6a324",commitHref)
52+
assert.Equal(t,"/user2",authorHref)
10353
})
104-
assert.Equal(t, []string{"user1"},gitUsers)
105-
106-
// check last commit author wrapper
107-
req=NewRequest(t,"GET","/user2/repo1")
108-
resp=session.MakeRequest(t,req,http.StatusOK)
10954

110-
doc=NewHTMLParser(t,resp.Body)
111-
commits= []string{}
112-
doc.doc.Find(".latest-commit .commit-id-short").Each(func(iint,s*goquery.Selection) {
113-
commitURL,_:=s.Attr("href")
114-
commits=append(commits,path.Base(commitURL))
55+
t.Run("CommitListNonExistingCommiter",func(t*testing.T) {
56+
// check the commit list for a repository with no gitea user
57+
// * commit 985f0301dba5e7b34be866819cd15ad3d8f508ee (branch2)
58+
// * Author: 6543 <6543@obermui.de>
59+
req:=NewRequest(t,"GET","/user2/repo1/commits/branch/branch2")
60+
resp:=session.MakeRequest(t,req,http.StatusOK)
61+
62+
doc:=NewHTMLParser(t,resp.Body)
63+
commitHref:=doc.doc.Find("#commits-table tr:first-child .commit-id-short").AttrOr("href","")
64+
assert.Equal(t,"/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee",commitHref)
65+
authorElem:=doc.doc.Find("#commits-table tr:first-child .author-wrapper")
66+
assert.Equal(t,"6543",authorElem.Text())
67+
assert.Equal(t,"span",authorElem.Nodes[0].Data)
11568
})
116-
assert.Equal(t, []string{"65f1bf27bc3bf70f64657658635e66094edbcb4d"},commits)
11769

118-
gitUsers= []string{}
119-
doc.doc.Find(".latest-commit .author-wrapper").Each(func(iint,s*goquery.Selection) {
120-
assert.Equal(t,"span",goquery.NodeName(s))
121-
gitUsers=append(gitUsers,s.Text())
70+
t.Run("LastCommitNonExistingCommiter",func(t*testing.T) {
71+
req:=NewRequest(t,"GET","/user2/repo1/src/branch/branch2")
72+
resp:=session.MakeRequest(t,req,http.StatusOK)
73+
doc:=NewHTMLParser(t,resp.Body)
74+
commitHref:=doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href","")
75+
assert.Equal(t,"/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee",commitHref)
76+
authorElem:=doc.doc.Find(".latest-commit .author-wrapper")
77+
assert.Equal(t,"6543",authorElem.Text())
78+
assert.Equal(t,"span",authorElem.Nodes[0].Data)
12279
})
123-
assert.Equal(t, []string{"user1"},gitUsers)
12480
}
12581

12682
funcdoTestRepoCommitWithStatus(t*testing.T,statestring,classes...string) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp