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

Allow get release download files and lfs files with oauth2 token format #26430

Merged
merged 29 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ae55d69
Allow get release download files and lfs files with oauth2 token format
lunny Aug 10, 2023
85c5c78
Merge branch 'main' into lunny/fix_download_token
lunny Aug 10, 2023
f91dd42
Add a test to download a release attachment from a private repository
lunny Aug 10, 2023
15f05cd
Merge branch 'lunny/fix_download_token' of github.com:lunny/gitea int…
lunny Aug 10, 2023
a464e18
Merge branch 'main' into lunny/fix_download_token
lunny Aug 11, 2023
494834e
Fix test fixture
lunny Aug 11, 2023
e4a1776
Merge branch 'main' into lunny/fix_download_token
lunny Aug 11, 2023
e21c5a2
Merge branch 'main' into lunny/fix_download_token
lunny Aug 24, 2023
07ff2e1
Merge branch 'main' into lunny/fix_download_token
lunny Sep 8, 2023
af2e12e
Merge branch 'main' into lunny/fix_download_token
lunny Sep 11, 2023
5ce2395
narraw the change scope
lunny Sep 11, 2023
26a107a
Merge branch 'main' into lunny/fix_download_token
lunny Sep 20, 2023
27d0ffe
Merge branch 'main' into lunny/fix_download_token
lunny Sep 27, 2023
5104af1
Fix test
lunny Sep 28, 2023
3672f26
Merge branch 'main' into lunny/fix_download_token
lunny Sep 28, 2023
3bc8a02
Add comment
lunny Sep 28, 2023
dba042c
Fix test for postgres which using minio
lunny Sep 28, 2023
6a08547
Fix test
lunny Sep 28, 2023
d9eea50
Merge branch 'main' into lunny/fix_download_token
lunny Sep 28, 2023
ea6b3f2
Fix test
lunny Sep 29, 2023
153dca2
Merge branch 'main' into lunny/fix_download_token
lunny Sep 29, 2023
4d930a2
Make code simple
lunny Sep 29, 2023
76dfd42
Merge branch 'main' into lunny/fix_download_token
lunny Sep 29, 2023
180a0f8
Use common function
lunny Oct 1, 2023
0ffcf83
Merge branch 'main' into lunny/fix_download_token
lunny Oct 1, 2023
a9cf69c
do the attachment directories copy only for the related tests
lunny Oct 1, 2023
95d6c26
Fix test
lunny Oct 1, 2023
86d4460
Merge branch 'main' into lunny/fix_download_token
lunny Oct 1, 2023
9a8a6c7
Merge branch 'main' into lunny/fix_download_token
6543 Oct 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions models/fixtures/attachment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,16 @@
download_count: 0
size: 0
created_unix: 946684800

-
id: 12
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a22
repo_id: 40
issue_id: 0
release_id: 11
uploader_id: 2
comment_id: 0
name: README.md
download_count: 0
size: 0
created_unix: 946684800
14 changes: 14 additions & 0 deletions models/fixtures/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,17 @@
is_prerelease: false
is_tag: false
created_unix: 946684803

- id: 11
repo_id: 2
publisher_id: 2
tag_name: "v1.1"
lower_tag_name: "v1.1"
target: ""
title: "v1.1"
sha1: "205ac761f3326a7ebe416e8673760016450b5cec"
num_commits: 2
is_draft: false
is_prerelease: false
is_tag: false
created_unix: 946684803
3 changes: 2 additions & 1 deletion services/auth/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func (o *OAuth2) userIDFromToken(tokenSHA string, store DataStore) int64 {
// If verification is successful returns an existing user object.
// Returns nil if verification fails.
func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isAuthenticatedTokenRequest(req) {
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isAuthenticatedTokenRequest(req) &&
lunny marked this conversation as resolved.
Show resolved Hide resolved
!isGitRawReleaseOrLFSPath(req) {
return nil, nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1032bbf17fbc0d9c95bb5418dabe8f8c99278700
14 changes: 14 additions & 0 deletions tests/integration/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,17 @@ func TestViewTagsList(t *testing.T) {

assert.EqualValues(t, []string{"v1.0", "delete-tag", "v1.1"}, tagNames)
}

func TestDownloadReleaseAttachment(t *testing.T) {
defer tests.PrepareTestEnv(t)()

repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})

url := repo.Link() + "/releases/download/v1.1/README.md"

req := NewRequest(t, "GET", url)
MakeRequest(t, req, http.StatusNotFound)

session := loginUser(t, "user2")
session.MakeRequest(t, req, http.StatusOK)
}