@@ -11,6 +11,7 @@ import (
11
11
"net/http/httptest"
12
12
"testing"
13
13
14
+ "code.gitea.io/gitea/models/auth"
14
15
"code.gitea.io/gitea/models/db"
15
16
git_model "code.gitea.io/gitea/models/git"
16
17
repo_model "code.gitea.io/gitea/models/repo"
@@ -40,6 +41,31 @@ func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string
40
41
return pointer .Oid
41
42
}
42
43
44
+ func storeAndGetLfsToken (t * testing.T , ts auth.AccessTokenScope , content * []byte , extraHeader * http.Header , expectedStatus int ) * httptest.ResponseRecorder {
45
+ repo , err := repo_model .GetRepositoryByOwnerAndName (db .DefaultContext , "user2" , "repo1" )
46
+ assert .NoError (t , err )
47
+ oid := storeObjectInRepo (t , repo .ID , content )
48
+ defer git_model .RemoveLFSMetaObjectByOid (db .DefaultContext , repo .ID , oid )
49
+
50
+ token := getUserToken (t , "user2" , ts )
51
+
52
+ // Request OID
53
+ req := NewRequest (t , "GET" , "/user2/repo1.git/info/lfs/objects/" + oid + "/test" )
54
+ req .Header .Set ("Accept-Encoding" , "gzip" )
55
+ req .SetBasicAuth ("user2" , token )
56
+ if extraHeader != nil {
57
+ for key , values := range * extraHeader {
58
+ for _ , value := range values {
59
+ req .Header .Add (key , value )
60
+ }
61
+ }
62
+ }
63
+
64
+ resp := MakeRequest (t , req , expectedStatus )
65
+
66
+ return resp
67
+ }
68
+
43
69
func storeAndGetLfs (t * testing.T , content * []byte , extraHeader * http.Header , expectedStatus int ) * httptest.ResponseRecorder {
44
70
repo , err := repo_model .GetRepositoryByOwnerAndName (db .DefaultContext , "user2" , "repo1" )
45
71
assert .NoError (t , err )
@@ -89,6 +115,21 @@ func TestGetLFSSmall(t *testing.T) {
89
115
checkResponseTestContentEncoding (t , & content , resp , false )
90
116
}
91
117
118
+ func TestGetLFSSmallToken (t * testing.T ) {
119
+ defer tests .PrepareTestEnv (t )()
120
+ content := []byte ("A very small file\n " )
121
+
122
+ resp := storeAndGetLfsToken (t , auth .AccessTokenScopePublicRepo , & content , nil , http .StatusOK )
123
+ checkResponseTestContentEncoding (t , & content , resp , false )
124
+ }
125
+
126
+ func TestGetLFSSmallTokenFail (t * testing.T ) {
127
+ defer tests .PrepareTestEnv (t )()
128
+ content := []byte ("A very small file\n " )
129
+
130
+ storeAndGetLfsToken (t , auth .AccessTokenScopeNotification , & content , nil , http .StatusForbidden )
131
+ }
132
+
92
133
func TestGetLFSLarge (t * testing.T ) {
93
134
defer tests .PrepareTestEnv (t )()
94
135
content := make ([]byte , web .GzipMinSize * 10 )
0 commit comments