2022-03-30 11:42:47 +03:00
// Copyright 2021 The Gitea Authors. All rights reserved.
2022-11-27 21:20:29 +03:00
// SPDX-License-Identifier: MIT
2022-03-30 11:42:47 +03:00
2022-09-02 22:18:23 +03:00
package integration
2022-03-30 11:42:47 +03:00
import (
"bytes"
2024-05-20 02:30:41 +03:00
"crypto/md5"
"crypto/sha256"
2022-03-30 11:42:47 +03:00
"encoding/base64"
"fmt"
"mime/multipart"
"net/http"
2024-05-20 02:30:41 +03:00
"strings"
2022-03-30 11:42:47 +03:00
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/packages/rubygems"
2022-09-02 22:18:23 +03:00
"code.gitea.io/gitea/tests"
2022-03-30 11:42:47 +03:00
"github.com/stretchr/testify/assert"
2024-07-30 22:41:10 +03:00
"github.com/stretchr/testify/require"
2022-03-30 11:42:47 +03:00
)
func TestPackageRubyGems ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrepareTestEnv ( t ) ( )
2023-02-23 17:11:56 +03:00
2022-08-16 05:22:25 +03:00
user := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 2 } )
2022-03-30 11:42:47 +03:00
packageName := "gitea"
packageVersion := "1.0.5"
packageFilename := "gitea-1.0.5.gem"
2024-05-20 02:30:41 +03:00
packageDependency := "runtime-dep:>= 1.2.0&< 2.0"
rubyRequirements := "ruby:>= 2.3.0"
sep := "---"
2022-03-30 11:42:47 +03:00
gemContent , _ := base64 . StdEncoding . DecodeString ( ` bWV0YWRhdGEuZ3oAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAwMDA0NDQAMDAwMDAw
MAAwMDAwMDAwADAwMDAwMDAxMDQxADE0MTEwNzcyMz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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ` )
2024-05-20 02:30:41 +03:00
checksum := fmt . Sprintf ( "%x" , sha256 . Sum256 ( gemContent ) )
holaPackageName := "hola"
holaPackageVersion := "0.0.1"
// holaPackageFilename := "hola-0.0.1.gem"
holaPackageDependency := "example:~> 1.1&>= 1.1.4,zero:>= 0"
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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA == ` )
holaChecksum := fmt . Sprintf ( "%x" , sha256 . Sum256 ( holaGemContent ) )
2022-03-30 11:42:47 +03:00
root := fmt . Sprintf ( "/api/packages/%s/rubygems" , user . Name )
2024-05-20 02:30:41 +03:00
uploadFile := func ( t * testing . T , content [ ] byte , expectedStatus int ) {
req := NewRequestWithBody ( t , "POST" , fmt . Sprintf ( "%s/api/v1/gems" , root ) , bytes . NewReader ( content ) ) .
2023-12-22 02:59:59 +03:00
AddBasicAuth ( user . Name )
2022-03-30 11:42:47 +03:00
MakeRequest ( t , req , expectedStatus )
}
t . Run ( "Upload" , func ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrintCurrentTest ( t ) ( )
2022-03-30 11:42:47 +03:00
2024-05-20 02:30:41 +03:00
uploadFile ( t , gemContent , http . StatusCreated )
2022-03-30 11:42:47 +03:00
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRubyGems )
2024-07-30 22:41:10 +03:00
require . NoError ( t , err )
2022-03-30 11:42:47 +03:00
assert . Len ( t , pvs , 1 )
pd , err := packages . GetPackageDescriptor ( db . DefaultContext , pvs [ 0 ] )
2024-07-30 22:41:10 +03:00
require . NoError ( t , err )
2022-03-30 11:42:47 +03:00
assert . NotNil ( t , pd . SemVer )
assert . IsType ( t , & rubygems . Metadata { } , pd . Metadata )
assert . Equal ( t , packageName , pd . Package . Name )
assert . Equal ( t , packageVersion , pd . Version . Version )
pfs , err := packages . GetFilesByVersionID ( db . DefaultContext , pvs [ 0 ] . ID )
2024-07-30 22:41:10 +03:00
require . NoError ( t , err )
2022-03-30 11:42:47 +03:00
assert . Len ( t , pfs , 1 )
assert . Equal ( t , packageFilename , pfs [ 0 ] . Name )
assert . True ( t , pfs [ 0 ] . IsLead )
pb , err := packages . GetBlobByID ( db . DefaultContext , pfs [ 0 ] . BlobID )
2024-07-30 22:41:10 +03:00
require . NoError ( t , err )
2022-03-30 11:42:47 +03:00
assert . Equal ( t , int64 ( 4608 ) , pb . Size )
} )
t . Run ( "UploadExists" , func ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrintCurrentTest ( t ) ( )
2022-03-30 11:42:47 +03:00
2024-05-20 02:30:41 +03:00
uploadFile ( t , gemContent , http . StatusConflict )
2022-03-30 11:42:47 +03:00
} )
t . Run ( "Download" , func ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrintCurrentTest ( t ) ( )
2022-03-30 11:42:47 +03:00
2023-12-22 02:59:59 +03:00
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/gems/%s" , root , packageFilename ) ) .
AddBasicAuth ( user . Name )
2022-03-30 11:42:47 +03:00
resp := MakeRequest ( t , req , http . StatusOK )
assert . Equal ( t , gemContent , resp . Body . Bytes ( ) )
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRubyGems )
2024-07-30 22:41:10 +03:00
require . NoError ( t , err )
2022-03-30 11:42:47 +03:00
assert . Len ( t , pvs , 1 )
assert . Equal ( t , int64 ( 1 ) , pvs [ 0 ] . DownloadCount )
} )
t . Run ( "DownloadGemspec" , func ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrintCurrentTest ( t ) ( )
2022-03-30 11:42:47 +03:00
2023-12-22 02:59:59 +03:00
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/quick/Marshal.4.8/%sspec.rz" , root , packageFilename ) ) .
AddBasicAuth ( user . Name )
2022-03-30 11:42:47 +03:00
resp := MakeRequest ( t , req , http . StatusOK )
b , _ := base64 . StdEncoding . DecodeString ( ` eJxi4Si1EndPzbWyCi5ITc5My0xOLMnMz2M8zMIRLeGpxGWsZ6RnzGbF5hqSyempxJWeWZKayGbN
EBJqJQjWFZZaVJyZnxfN5qnEZahnoGcKkjTwVBJyB6lUKEhMzk5MTwULGngqcRaVJlWCONEMBp5K
DGAWSKc7zFhPJamg0qRK99TcYphehZLU4hKInFhGSUlBsZW + PtgZepn5 + iDxECRzDUDGcfh6hoA4
gAAAAP //MS06Gw==`)
assert . Equal ( t , b , resp . Body . Bytes ( ) )
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRubyGems )
2024-07-30 22:41:10 +03:00
require . NoError ( t , err )
2022-03-30 11:42:47 +03:00
assert . Len ( t , pvs , 1 )
assert . Equal ( t , int64 ( 1 ) , pvs [ 0 ] . DownloadCount )
} )
t . Run ( "EnumeratePackages" , func ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrintCurrentTest ( t ) ( )
2022-03-30 11:42:47 +03:00
enumeratePackages := func ( t * testing . T , endpoint string , expectedContent [ ] byte ) {
2023-12-22 02:59:59 +03:00
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/%s" , root , endpoint ) ) .
AddBasicAuth ( user . Name )
2022-03-30 11:42:47 +03:00
resp := MakeRequest ( t , req , http . StatusOK )
assert . Equal ( t , expectedContent , resp . Body . Bytes ( ) )
}
b , _ := base64 . StdEncoding . DecodeString ( ` H4sICAAAAAAA/3NwZWNzLjQuOABi4Yhmi+bwVOJKzyxJTWSzYnMNCbUSdE/NtbIKSy0qzszPi2bzVOIy1DPQM2WzZgjxVOIsKk2qBDEBAQAA///xOEYKOwAAAA== ` )
enumeratePackages ( t , "specs.4.8.gz" , b )
b , _ = base64 . StdEncoding . DecodeString ( ` H4sICAAAAAAA/2xhdGVzdF9zcGVjcy40LjgAYuGIZovm8FTiSs8sSU1ks2JzDQm1EnRPzbWyCkstKs7Mz4tm81TiMtQz0DNls2YI8VTiLCpNqgQxAQEAAP//8ThGCjsAAAA= ` )
enumeratePackages ( t , "latest_specs.4.8.gz" , b )
b , _ = base64 . StdEncoding . DecodeString ( ` H4sICAAAAAAA/3ByZXJlbGVhc2Vfc3BlY3MuNC44AGLhiGYABAAA//9snXr5BAAAAA== ` )
enumeratePackages ( t , "prerelease_specs.4.8.gz" , b )
} )
2024-05-20 02:30:41 +03:00
t . Run ( "UploadHola" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
uploadFile ( t , holaGemContent , http . StatusCreated )
} )
t . Run ( "PackageInfo" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/info/%s" , root , packageName ) ) .
AddBasicAuth ( user . Name )
resp := MakeRequest ( t , req , http . StatusOK )
expected := fmt . Sprintf ( "%s\n%s %s|checksum:%s,%s\n" ,
sep , packageVersion , packageDependency , checksum , rubyRequirements )
assert . Equal ( t , expected , resp . Body . String ( ) )
} )
t . Run ( "HolaPackageInfo" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/info/%s" , root , holaPackageName ) ) .
AddBasicAuth ( user . Name )
resp := MakeRequest ( t , req , http . StatusOK )
expected := fmt . Sprintf ( "%s\n%s %s|checksum:%s,%s\n" ,
sep , holaPackageVersion , holaPackageDependency , holaChecksum , holaRubyGemsRequirements )
assert . Equal ( t , expected , resp . Body . String ( ) )
} )
t . Run ( "Versions" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
versionsReq := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/versions" , root ) ) .
AddBasicAuth ( user . Name )
versionsResp := MakeRequest ( t , versionsReq , http . StatusOK )
infoReq := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/info/%s" , root , packageName ) ) .
AddBasicAuth ( user . Name )
infoResp := MakeRequest ( t , infoReq , http . StatusOK )
holaInfoReq := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/info/%s" , root , holaPackageName ) ) .
AddBasicAuth ( user . Name )
holaInfoResp := MakeRequest ( t , holaInfoReq , http . StatusOK )
// expected := fmt.Sprintf("%s\n%s %s %x\n",
// sep, packageName, packageVersion, md5.Sum(infoResp.Body.Bytes()))
lines := versionsResp . Body . String ( )
assert . ElementsMatch ( t , strings . Split ( lines , "\n" ) , [ ] string {
sep ,
fmt . Sprintf ( "%s %s %x" , packageName , packageVersion , md5 . Sum ( infoResp . Body . Bytes ( ) ) ) ,
fmt . Sprintf ( "%s %s %x" , holaPackageName , holaPackageVersion , md5 . Sum ( holaInfoResp . Body . Bytes ( ) ) ) ,
"" ,
} )
} )
t . Run ( "DeleteHola" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
body := bytes . Buffer { }
writer := multipart . NewWriter ( & body )
writer . WriteField ( "gem_name" , holaPackageName )
writer . WriteField ( "version" , holaPackageVersion )
writer . Close ( )
req := NewRequestWithBody ( t , "DELETE" , fmt . Sprintf ( "%s/api/v1/gems/yank" , root ) , & body ) .
SetHeader ( "Content-Type" , writer . FormDataContentType ( ) ) .
AddBasicAuth ( user . Name )
MakeRequest ( t , req , http . StatusOK )
} )
2022-03-30 11:42:47 +03:00
t . Run ( "Delete" , func ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrintCurrentTest ( t ) ( )
2022-03-30 11:42:47 +03:00
body := bytes . Buffer { }
writer := multipart . NewWriter ( & body )
writer . WriteField ( "gem_name" , packageName )
writer . WriteField ( "version" , packageVersion )
writer . Close ( )
2023-12-22 02:59:59 +03:00
req := NewRequestWithBody ( t , "DELETE" , fmt . Sprintf ( "%s/api/v1/gems/yank" , root ) , & body ) .
SetHeader ( "Content-Type" , writer . FormDataContentType ( ) ) .
AddBasicAuth ( user . Name )
2022-03-30 11:42:47 +03:00
MakeRequest ( t , req , http . StatusOK )
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRubyGems )
2024-07-30 22:41:10 +03:00
require . NoError ( t , err )
2022-03-30 11:42:47 +03:00
assert . Empty ( t , pvs )
} )
2024-05-20 02:30:41 +03:00
t . Run ( "NonExistingGem" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/info/%s" , root , packageName ) ) .
AddBasicAuth ( user . Name )
_ = MakeRequest ( t , req , http . StatusNotFound )
} )
t . Run ( "EmptyVersions" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/versions" , root ) ) .
AddBasicAuth ( user . Name )
resp := MakeRequest ( t , req , http . StatusOK )
assert . Equal ( t , sep + "\n" , resp . Body . String ( ) )
} )
2022-03-30 11:42:47 +03:00
}