Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stange behavior of DownloadPullDiffOrPatch in incorect index #17223

Merged
merged 3 commits into from
Oct 5, 2021

Conversation

pricly-yellow
Copy link
Contributor

Close #17105

* validate index

Signed-off-by: Danila Kryukov <pricly_yellow@dismail.de>
@codecov-commenter
Copy link

Codecov Report

Merging #17223 (4c65a51) into main (f2e7d54) will decrease coverage by 0.06%.
The diff coverage is 49.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17223      +/-   ##
==========================================
- Coverage   45.31%   45.25%   -0.07%     
==========================================
  Files         773      779       +6     
  Lines       86873    87287     +414     
==========================================
+ Hits        39366    39501     +135     
- Misses      41151    41369     +218     
- Partials     6356     6417      +61     
Impacted Files Coverage Δ
cmd/admin.go 0.00% <0.00%> (ø)
models/action.go 48.86% <0.00%> (ø)
models/avatar.go 35.38% <0.00%> (ø)
models/error.go 39.83% <ø> (+0.29%) ⬆️
models/fixture_generation.go 70.00% <0.00%> (ø)
models/gpg_key_verify.go 13.46% <0.00%> (ø)
models/helper.go 52.94% <0.00%> (ø)
models/issue_lock.go 0.00% <0.00%> (ø)
models/migrate.go 0.00% <0.00%> (ø)
models/pull_sign.go 37.64% <0.00%> (ø)
... and 216 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4ea6cc...4c65a51. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 5, 2021
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 5, 2021
@a1012112796
Copy link
Member

suggest update test code:

diff --git a/models/pull_test.go b/models/pull_test.go
index 2b7ef2f66..173977aaf 100644
--- a/models/pull_test.go
+++ b/models/pull_test.go
@@ -134,6 +134,10 @@ func TestGetPullRequestByIndex(t *testing.T) {
 	_, err = GetPullRequestByIndex(9223372036854775807, 9223372036854775807)
 	assert.Error(t, err)
 	assert.True(t, IsErrPullRequestNotExist(err))
+
+	_, err = GetPullRequestByIndex(1, 0)
+	assert.Error(t, err)
+	assert.True(t, IsErrPullRequestNotExist(err))
 }
 
 func TestGetPullRequestByID(t *testing.T) {

Co-authored-by: a1012112796 <1012112796@qq.com>
@pricly-yellow
Copy link
Contributor Author

Good idea, push it now

Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from this question: LGTM.

models/pull.go Show resolved Hide resolved
models/pull_test.go Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 5, 2021
@6543 6543 added the type/bug label Oct 5, 2021
@6543 6543 added this to the 1.16.0 milestone Oct 5, 2021
@6543
Copy link
Member

6543 commented Oct 5, 2021

the (xorm) Get will ignore fields with "default init values" and match with set one

var value int64
fmt.Println(value)

That's why Get is mostly used with the ".ID()" function witch we can not use since index is a normal field for xorm (we do use it ID'like for each repo)

So either check with if if it is 0 and return 404 or add a explisit Where("index=?", pr.index). In this case an if is more elegant since 0 is not an valide index

@delvh (:point_up:)

@6543 6543 merged commit 20eaca6 into go-gitea:main Oct 5, 2021
@6543
Copy link
Member

6543 commented Oct 5, 2021

@pricly-yellow thanks for the pull, can you cherry-pick squash-commit to release branch 1.15 and make a pull?

if you need help just tell

@6543 6543 added the backport/done All backports for this PR have been created label Oct 5, 2021
@6543
Copy link
Member

6543 commented Oct 5, 2021

-> #17227

6543 pushed a commit that referenced this pull request Oct 5, 2021
) (#17227)

Fix GetPullRequestByIndex by validate index > 1

Signed-off-by: Danila Kryukov <pricly_yellow@dismail.de>
Co-authored-by: a1012112796 <1012112796@qq.com>
Chianina pushed a commit to Chianina/gitea that referenced this pull request Oct 15, 2021
…gitea#17223)

Fix GetPullRequestByIndex by validate index > 1

Signed-off-by: Danila Kryukov <pricly_yellow@dismail.de>

Co-authored-by: a1012112796 <1012112796@qq.com>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
6 participants