@@ -5,13 +5,18 @@ package integration
55
66import (
77 "encoding/base64"
8+ "net/http"
89 "net/url"
910 "testing"
1011
1112 actions_model "code.gitea.io/gitea/models/actions"
13+ auth_model "code.gitea.io/gitea/models/auth"
14+ "code.gitea.io/gitea/models/db"
1215 "code.gitea.io/gitea/models/unittest"
1316 "code.gitea.io/gitea/modules/structs"
17+ api "code.gitea.io/gitea/modules/structs"
1418
19+ "github.com/stretchr/testify/assert"
1520 "github.com/stretchr/testify/require"
1621)
1722
@@ -72,3 +77,44 @@ func testActionsJobTokenAccess(u *url.URL, isFork bool) func(t *testing.T) {
7277 }))
7378 }
7479}
80+
81+ func TestActionsJobTokenAccessLFS (t * testing.T ) {
82+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
83+ httpContext := NewAPITestContext (t , "user2" , "repo-lfs-test" , auth_model .AccessTokenScopeWriteUser , auth_model .AccessTokenScopeWriteRepository )
84+ t .Run ("Create Repository" , doAPICreateRepository (httpContext , false , func (t * testing.T , repository api.Repository ) {
85+
86+ task := & actions_model.ActionTask {}
87+ require .NoError (t , task .GenerateToken ())
88+ task .Status = actions_model .StatusRunning
89+ task .IsForkPullRequest = false
90+ task .RepoID = repository .ID
91+ err := db .Insert (t .Context (), task )
92+ require .NoError (t , err )
93+ session := emptyTestSession (t )
94+ httpContext := APITestContext {
95+ Session : session ,
96+ Token : task .Token ,
97+ Username : "user2" ,
98+ Reponame : "repo-lfs-test" ,
99+ }
100+
101+ u .Path = httpContext .GitPath ()
102+ dstPath := t .TempDir ()
103+
104+ u .Path = httpContext .GitPath ()
105+ u .User = url .UserPassword ("gitea-actions" , task .Token )
106+
107+ t .Run ("Clone" , doGitClone (dstPath , u ))
108+
109+ dstPath2 := t .TempDir ()
110+
111+ t .Run ("Partial Clone" , doPartialGitClone (dstPath2 , u ))
112+
113+ lfs := lfsCommitAndPushTest (t , dstPath , testFileSizeSmall )[0 ]
114+
115+ reqLFS := NewRequest (t , "GET" , "/api/v1/repos/user2/repo-lfs-test/media/" + lfs ).AddTokenAuth (task .Token )
116+ respLFS := MakeRequestNilResponseRecorder (t , reqLFS , http .StatusOK )
117+ assert .Equal (t , testFileSizeSmall , respLFS .Length )
118+ }))
119+ })
120+ }
0 commit comments