@ -12,6 +12,7 @@ import (
"io"
"io"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"strings"
"testing"
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/db"
@ -20,6 +21,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
user_model "code.gitea.io/gitea/models/user"
rpm_module "code.gitea.io/gitea/modules/packages/rpm"
rpm_module "code.gitea.io/gitea/modules/packages/rpm"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/tests"
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
@ -73,346 +75,362 @@ Mu0UFYgZ/bYnuvn/vz4wtCz8qMwsHUvP0PX3tbYFUctAPdrY6tiiDtcCddDECahx7SuVNP5dpmb5
rootURL := fmt . Sprintf ( "/api/packages/%s/rpm" , user . Name )
rootURL := fmt . Sprintf ( "/api/packages/%s/rpm" , user . Name )
t . Run ( "RepositoryConfig" , func ( t * testing . T ) {
for _ , group := range [ ] string { "" , "el9" , "el9/stable" } {
defer tests . PrintCurrentTest ( t ) ( )
t . Run ( fmt . Sprintf ( "[Group:%s]" , group ) , func ( t * testing . T ) {
var groupParts [ ] string
if group != "" {
groupParts = strings . Split ( group , "/" )
}
groupURL := strings . Join ( append ( [ ] string { rootURL } , groupParts ... ) , "/" )
t . Run ( "RepositoryConfig" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "GET" , rootURL + "/el9/stable.repo" )
req := NewRequest ( t , "GET" , group URL+ ".repo" )
resp := MakeRequest ( t , req , http . StatusOK )
resp := MakeRequest ( t , req , http . StatusOK )
expected := fmt . Sprintf ( ` [ gitea - % s - el9 - stable ]
expected := fmt . Sprintf ( ` [ gitea - % s ]
name = % s - % s - el9 - stable
name = % s
baseurl = % sapi / packages / % s / rpm / el9 / stable /
baseurl = % s
enabled = 1
enabled = 1
gpgcheck = 1
gpgcheck = 1
gpgkey = % sapi / packages / % s / rpm / repository . key ` , user . Name , user . Name , setting . AppName , setting . AppURL , user . Name , setting . AppURL , user . Name )
gpgkey = % sapi / packages / % s / rpm / repository . key ` ,
strings . Join ( append ( [ ] string { user . LowerName } , groupParts ... ) , "-" ) ,
assert . Equal ( t , expected , resp . Body . String ( ) )
strings . Join ( append ( [ ] string { user . Name , setting . AppName } , groupParts ... ) , " - " ) ,
} )
util . URLJoin ( setting . AppURL , groupURL ) ,
setting . AppURL ,
t . Run ( "RepositoryKey" , func ( t * testing . T ) {
user . Name ,
defer tests . PrintCurrentTest ( t ) ( )
)
req := NewRequest ( t , "GET" , rootURL + "/repository.key" )
assert . Equal ( t , expected , resp . Body . String ( ) )
resp := MakeRequest ( t , req , http . StatusOK )
} )
assert . Equal ( t , "application/pgp-keys" , resp . Header ( ) . Get ( "Content-Type" ) )
t . Run ( "RepositoryKey" , func ( t * testing . T ) {
assert . Contains ( t , resp . Body . String ( ) , "-----BEGIN PGP PUBLIC KEY BLOCK-----" )
defer tests . PrintCurrentTest ( t ) ( )
} )
req := NewRequest ( t , "GET" , rootURL + "/repository.key" )
t . Run ( "Upload" , func ( t * testing . T ) {
resp := MakeRequest ( t , req , http . StatusOK )
url := rootURL + "/el9/stable/upload"
assert . Equal ( t , "application/pgp-keys" , resp . Header ( ) . Get ( "Content-Type" ) )
req := NewRequestWithBody ( t , "PUT" , url , bytes . NewReader ( content ) )
assert . Contains ( t , resp . Body . String ( ) , "-----BEGIN PGP PUBLIC KEY BLOCK-----" )
MakeRequest ( t , req , http . StatusUnauthorized )
} )
req = NewRequestWithBody ( t , "PUT" , url , bytes . NewReader ( content ) ) .
t . Run ( "Upload" , func ( t * testing . T ) {
AddBasicAuth ( user . Name )
url := groupURL + "/upload"
MakeRequest ( t , req , http . StatusCreated )
req := NewRequestWithBody ( t , "PUT" , url , bytes . NewReader ( content ) )
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRpm )
MakeRequest ( t , req , http . StatusUnauthorized )
assert . NoError ( t , err )
assert . Len ( t , pvs , 1 )
req = NewRequestWithBody ( t , "PUT" , url , bytes . NewReader ( content ) ) .
AddBasicAuth ( user . Name )
pd , err := packages . GetPackageDescriptor ( db . DefaultContext , pvs [ 0 ] )
MakeRequest ( t , req , http . StatusCreated )
assert . NoError ( t , err )
assert . Nil ( t , pd . SemVer )
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRpm )
assert . IsType ( t , & rpm_module . VersionMetadata { } , pd . Metadata )
assert . NoError ( t , err )
assert . Equal ( t , packageName , pd . Package . Name )
assert . Len ( t , pvs , 1 )
assert . Equal ( t , fmt . Sprintf ( "el9/stable/%s" , packageVersion ) , pd . Version . Version )
pd , err := packages . GetPackageDescriptor ( db . DefaultContext , pvs [ 0 ] )
pfs , err := packages . GetFilesByVersionID ( db . DefaultContext , pvs [ 0 ] . ID )
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . Nil ( t , pd . SemVer )
assert . Len ( t , pfs , 1 )
assert . IsType ( t , & rpm_module . VersionMetadata { } , pd . Metadata )
assert . Equal ( t , fmt . Sprintf ( "%s-%s.%s.rpm" , packageName , packageVersion , packageArchitecture ) , pfs [ 0 ] . Name )
assert . Equal ( t , packageName , pd . Package . Name )
assert . True ( t , pfs [ 0 ] . IsLead )
assert . Equal ( t , packageVersion , pd . Version . Version )
pb , err := packages . GetBlobByID ( db . DefaultContext , pfs [ 0 ] . BlobID )
pfs , err := packages . GetFilesByVersionID ( db . DefaultContext , pvs [ 0 ] . ID )
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . Equal ( t , int64 ( len ( content ) ) , pb . Size )
assert . Len ( t , pfs , 1 )
assert . Equal ( t , fmt . Sprintf ( "%s-%s.%s.rpm" , packageName , packageVersion , packageArchitecture ) , pfs [ 0 ] . Name )
req = NewRequestWithBody ( t , "PUT" , url , bytes . NewReader ( content ) ) .
assert . True ( t , pfs [ 0 ] . IsLead )
AddBasicAuth ( user . Name )
MakeRequest ( t , req , http . StatusConflict )
pb , err := packages . GetBlobByID ( db . DefaultContext , pfs [ 0 ] . BlobID )
} )
assert . NoError ( t , err )
assert . Equal ( t , int64 ( len ( content ) ) , pb . Size )
t . Run ( "Download" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequestWithBody ( t , "PUT" , url , bytes . NewReader ( content ) ) .
AddBasicAuth ( user . Name )
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/el9/stable/package/%s/%s/%s" , rootURL , packageName , packageVersion , packageArchitecture ) )
MakeRequest ( t , req , http . StatusConflict )
resp := MakeRequest ( t , req , http . StatusOK )
} )
assert . Equal ( t , content , resp . Body . Bytes ( ) )
t . Run ( "Download" , func ( t * testing . T ) {
} )
defer tests . PrintCurrentTest ( t ) ( )
t . Run ( "Repository" , func ( t * testing . T ) {
req := NewRequest ( t , "GET" , fmt . Sprintf ( "%s/package/%s/%s/%s" , groupURL , packageName , packageVersion , packageArchitecture ) )
defer tests . PrintCurrentTest ( t ) ( )
resp := MakeRequest ( t , req , http . StatusOK )
url := rootURL + "/el9/stable/repodata"
assert . Equal ( t , content , resp . Body . Bytes ( ) )
} )
req := NewRequest ( t , "HEAD" , url + "/dummy.xml" )
MakeRequest ( t , req , http . StatusNotFound )
t . Run ( "Repository" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/dummy.xml" )
MakeRequest ( t , req , http . StatusNotFound )
url := groupURL + "/repodata"
t . Run ( "repomd.xml" , func ( t * testing . T ) {
req := NewRequest ( t , "HEAD" , url + "/dummy.xml" )
defer tests . PrintCurrentTest ( t ) ( )
MakeRequest ( t , req , http . StatusNotFound )
req = NewRequest ( t , "HEAD" , url + "/repomd.xml" )
req = NewRequest ( t , "GET" , url + "/dummy.xml" )
MakeRequest ( t , req , http . StatusOK )
MakeRequest ( t , req , http . StatusNotFound )
req = NewRequest ( t , "GET" , url + "/repomd.xml" )
t . Run ( "repomd.xml" , func ( t * testing . T ) {
resp := MakeRequest ( t , req , http . StatusOK )
defer tests . PrintCurrentTest ( t ) ( )
type Repomd struct {
req = NewRequest ( t , "HEAD" , url + "/repomd.xml" )
XMLName xml . Name ` xml:"repomd" `
MakeRequest ( t , req , http . StatusOK )
Xmlns string ` xml:"xmlns,attr" `
XmlnsRpm string ` xml:"xmlns:rpm,attr" `
req = NewRequest ( t , "GET" , url + "/repomd.xml" )
Data [ ] struct {
resp := MakeRequest ( t , req , http . StatusOK )
Type string ` xml:"type,attr" `
Checksum struct {
type Repomd struct {
Value string ` xml:",chardata" `
XMLName xml . Name ` xml:"repomd" `
Type string ` xml:"type,attr" `
Xmlns string ` xml:"xmlns,attr" `
} ` xml:"checksum" `
XmlnsRpm string ` xml:"xmlns:rpm,attr" `
OpenChecksum struct {
Data [ ] struct {
Value string ` xml:",chardata" `
Type string ` xml:"type,attr" `
Type string ` xml:"type,attr" `
Checksum struct {
} ` xml:"open-checksum" `
Value string ` xml:",chardata" `
Location struct {
Type string ` xml:"type,attr" `
Href string ` xml:"href,attr" `
} ` xml:"checksum" `
} ` xml:"location" `
OpenChecksum struct {
Timestamp int64 ` xml:"timestamp" `
Value string ` xml:",chardata" `
Size int64 ` xml:"size" `
Type string ` xml:"type,attr" `
OpenSize int64 ` xml:"open-size" `
} ` xml:"open-checksum" `
} ` xml:"data" `
Location struct {
}
Href string ` xml:"href,attr" `
} ` xml:"location" `
var result Repomd
Timestamp int64 ` xml:"timestamp" `
decodeXML ( t , resp , & result )
Size int64 ` xml:"size" `
OpenSize int64 ` xml:"open-size" `
assert . Len ( t , result . Data , 3 )
} ` xml:"data" `
for _ , d := range result . Data {
}
assert . Equal ( t , "sha256" , d . Checksum . Type )
assert . NotEmpty ( t , d . Checksum . Value )
var result Repomd
assert . Equal ( t , "sha256" , d . OpenChecksum . Type )
decodeXML ( t , resp , & result )
assert . NotEmpty ( t , d . OpenChecksum . Value )
assert . NotEqual ( t , d . Checksum . Value , d . OpenChecksum . Value )
assert . Len ( t , result . Data , 3 )
assert . Greater ( t , d . OpenSize , d . Size )
for _ , d := range result . Data {
assert . Equal ( t , "sha256" , d . Checksum . Type )
switch d . Type {
assert . NotEmpty ( t , d . Checksum . Value )
case "primary" :
assert . Equal ( t , "sha256" , d . OpenChecksum . Type )
assert . EqualValues ( t , 722 , d . Size )
assert . NotEmpty ( t , d . OpenChecksum . Value )
assert . EqualValues ( t , 1759 , d . OpenSize )
assert . NotEqual ( t , d . Checksum . Value , d . OpenChecksum . Value )
assert . Equal ( t , "repodata/primary.xml.gz" , d . Location . Href )
assert . Greater ( t , d . OpenSize , d . Size )
case "filelists" :
assert . EqualValues ( t , 257 , d . Size )
switch d . Type {
assert . EqualValues ( t , 326 , d . OpenSize )
case "primary" :
assert . Equal ( t , "repodata/filelists.xml.gz" , d . Location . Href )
assert . EqualValues ( t , 722 , d . Size )
case "other" :
assert . EqualValues ( t , 1759 , d . OpenSize )
assert . EqualValues ( t , 306 , d . Size )
assert . Equal ( t , "repodata/primary.xml.gz" , d . Location . Href )
assert . EqualValues ( t , 394 , d . OpenSize )
case "filelists" :
assert . Equal ( t , "repodata/other.xml.gz" , d . Location . Href )
assert . EqualValues ( t , 257 , d . Size )
assert . EqualValues ( t , 326 , d . OpenSize )
assert . Equal ( t , "repodata/filelists.xml.gz" , d . Location . Href )
case "other" :
assert . EqualValues ( t , 306 , d . Size )
assert . EqualValues ( t , 394 , d . OpenSize )
assert . Equal ( t , "repodata/other.xml.gz" , d . Location . Href )
}
}
} )
t . Run ( "repomd.xml.asc" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/repomd.xml.asc" )
resp := MakeRequest ( t , req , http . StatusOK )
assert . Contains ( t , resp . Body . String ( ) , "-----BEGIN PGP SIGNATURE-----" )
} )
decodeGzipXML := func ( t testing . TB , resp * httptest . ResponseRecorder , v any ) {
t . Helper ( )
zr , err := gzip . NewReader ( resp . Body )
assert . NoError ( t , err )
assert . NoError ( t , xml . NewDecoder ( zr ) . Decode ( v ) )
}
}
}
} )
t . Run ( "repomd.xml.asc" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/repomd.xml.asc" )
resp := MakeRequest ( t , req , http . StatusOK )
assert . Contains ( t , resp . Body . String ( ) , "-----BEGIN PGP SIGNATURE-----" )
t . Run ( "primary.xml.gz" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/primary.xml.gz" )
resp := MakeRequest ( t , req , http . StatusOK )
type EntryList struct {
Entries [ ] * rpm_module . Entry ` xml:"entry" `
}
type Metadata struct {
XMLName xml . Name ` xml:"metadata" `
Xmlns string ` xml:"xmlns,attr" `
XmlnsRpm string ` xml:"xmlns:rpm,attr" `
PackageCount int ` xml:"packages,attr" `
Packages [ ] struct {
XMLName xml . Name ` xml:"package" `
Type string ` xml:"type,attr" `
Name string ` xml:"name" `
Architecture string ` xml:"arch" `
Version struct {
Epoch string ` xml:"epoch,attr" `
Version string ` xml:"ver,attr" `
Release string ` xml:"rel,attr" `
} ` xml:"version" `
Checksum struct {
Checksum string ` xml:",chardata" `
Type string ` xml:"type,attr" `
Pkgid string ` xml:"pkgid,attr" `
} ` xml:"checksum" `
Summary string ` xml:"summary" `
Description string ` xml:"description" `
Packager string ` xml:"packager" `
URL string ` xml:"url" `
Time struct {
File uint64 ` xml:"file,attr" `
Build uint64 ` xml:"build,attr" `
} ` xml:"time" `
Size struct {
Package int64 ` xml:"package,attr" `
Installed uint64 ` xml:"installed,attr" `
Archive uint64 ` xml:"archive,attr" `
} ` xml:"size" `
Location struct {
Href string ` xml:"href,attr" `
} ` xml:"location" `
Format struct {
License string ` xml:"license" `
Vendor string ` xml:"vendor" `
Group string ` xml:"group" `
Buildhost string ` xml:"buildhost" `
Sourcerpm string ` xml:"sourcerpm" `
Provides EntryList ` xml:"provides" `
Requires EntryList ` xml:"requires" `
Conflicts EntryList ` xml:"conflicts" `
Obsoletes EntryList ` xml:"obsoletes" `
Files [ ] * rpm_module . File ` xml:"file" `
} ` xml:"format" `
} ` xml:"package" `
}
var result Metadata
decodeGzipXML ( t , resp , & result )
assert . EqualValues ( t , 1 , result . PackageCount )
assert . Len ( t , result . Packages , 1 )
p := result . Packages [ 0 ]
assert . Equal ( t , "rpm" , p . Type )
assert . Equal ( t , packageName , p . Name )
assert . Equal ( t , packageArchitecture , p . Architecture )
assert . Equal ( t , "YES" , p . Checksum . Pkgid )
assert . Equal ( t , "sha256" , p . Checksum . Type )
assert . Equal ( t , "f1d5d2ffcbe4a7568e98b864f40d923ecca084e9b9bcd5977ed6521c46d3fa4c" , p . Checksum . Checksum )
assert . Equal ( t , "https://gitea.io" , p . URL )
assert . EqualValues ( t , len ( content ) , p . Size . Package )
assert . EqualValues ( t , 13 , p . Size . Installed )
assert . EqualValues ( t , 272 , p . Size . Archive )
assert . Equal ( t , fmt . Sprintf ( "package/%s/%s/%s/%s" , packageName , packageVersion , packageArchitecture , fmt . Sprintf ( "%s-%s.%s.rpm" , packageName , packageVersion , packageArchitecture ) ) , p . Location . Href )
f := p . Format
assert . Equal ( t , "MIT" , f . License )
assert . Len ( t , f . Provides . Entries , 2 )
assert . Len ( t , f . Requires . Entries , 7 )
assert . Empty ( t , f . Conflicts . Entries )
assert . Empty ( t , f . Obsoletes . Entries )
assert . Len ( t , f . Files , 1 )
} )
t . Run ( "filelists.xml.gz" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/filelists.xml.gz" )
resp := MakeRequest ( t , req , http . StatusOK )
type Filelists struct {
XMLName xml . Name ` xml:"filelists" `
Xmlns string ` xml:"xmlns,attr" `
PackageCount int ` xml:"packages,attr" `
Packages [ ] struct {
Pkgid string ` xml:"pkgid,attr" `
Name string ` xml:"name,attr" `
Architecture string ` xml:"arch,attr" `
Version struct {
Epoch string ` xml:"epoch,attr" `
Version string ` xml:"ver,attr" `
Release string ` xml:"rel,attr" `
} ` xml:"version" `
Files [ ] * rpm_module . File ` xml:"file" `
} ` xml:"package" `
}
var result Filelists
decodeGzipXML ( t , resp , & result )
assert . EqualValues ( t , 1 , result . PackageCount )
assert . Len ( t , result . Packages , 1 )
p := result . Packages [ 0 ]
assert . NotEmpty ( t , p . Pkgid )
assert . Equal ( t , packageName , p . Name )
assert . Equal ( t , packageArchitecture , p . Architecture )
assert . Len ( t , p . Files , 1 )
f := p . Files [ 0 ]
assert . Equal ( t , "/usr/local/bin/hello" , f . Path )
} )
t . Run ( "other.xml.gz" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/other.xml.gz" )
resp := MakeRequest ( t , req , http . StatusOK )
type Other struct {
XMLName xml . Name ` xml:"otherdata" `
Xmlns string ` xml:"xmlns,attr" `
PackageCount int ` xml:"packages,attr" `
Packages [ ] struct {
Pkgid string ` xml:"pkgid,attr" `
Name string ` xml:"name,attr" `
Architecture string ` xml:"arch,attr" `
Version struct {
Epoch string ` xml:"epoch,attr" `
Version string ` xml:"ver,attr" `
Release string ` xml:"rel,attr" `
} ` xml:"version" `
Changelogs [ ] * rpm_module . Changelog ` xml:"changelog" `
} ` xml:"package" `
}
var result Other
decodeGzipXML ( t , resp , & result )
assert . EqualValues ( t , 1 , result . PackageCount )
assert . Len ( t , result . Packages , 1 )
p := result . Packages [ 0 ]
assert . NotEmpty ( t , p . Pkgid )
assert . Equal ( t , packageName , p . Name )
assert . Equal ( t , packageArchitecture , p . Architecture )
assert . Len ( t , p . Changelogs , 1 )
c := p . Changelogs [ 0 ]
assert . Equal ( t , "KN4CK3R <dummy@gitea.io>" , c . Author )
assert . EqualValues ( t , 1678276800 , c . Date )
assert . Equal ( t , "- Changelog message." , c . Text )
} )
} )
t . Run ( "Delete" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "DELETE" , fmt . Sprintf ( "%s/package/%s/%s/%s" , groupURL , packageName , packageVersion , packageArchitecture ) )
MakeRequest ( t , req , http . StatusUnauthorized )
req = NewRequest ( t , "DELETE" , fmt . Sprintf ( "%s/package/%s/%s/%s" , groupURL , packageName , packageVersion , packageArchitecture ) ) .
AddBasicAuth ( user . Name )
MakeRequest ( t , req , http . StatusNoContent )
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRpm )
assert . NoError ( t , err )
assert . Empty ( t , pvs )
req = NewRequest ( t , "DELETE" , fmt . Sprintf ( "%s/package/%s/%s/%s" , groupURL , packageName , packageVersion , packageArchitecture ) ) .
AddBasicAuth ( user . Name )
MakeRequest ( t , req , http . StatusNotFound )
} )
} )
} )
}
decodeGzipXML := func ( t testing . TB , resp * httptest . ResponseRecorder , v any ) {
t . Helper ( )
zr , err := gzip . NewReader ( resp . Body )
assert . NoError ( t , err )
assert . NoError ( t , xml . NewDecoder ( zr ) . Decode ( v ) )
}
t . Run ( "primary.xml.gz" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/primary.xml.gz" )
resp := MakeRequest ( t , req , http . StatusOK )
type EntryList struct {
Entries [ ] * rpm_module . Entry ` xml:"entry" `
}
type Metadata struct {
XMLName xml . Name ` xml:"metadata" `
Xmlns string ` xml:"xmlns,attr" `
XmlnsRpm string ` xml:"xmlns:rpm,attr" `
PackageCount int ` xml:"packages,attr" `
Packages [ ] struct {
XMLName xml . Name ` xml:"package" `
Type string ` xml:"type,attr" `
Name string ` xml:"name" `
Architecture string ` xml:"arch" `
Version struct {
Epoch string ` xml:"epoch,attr" `
Version string ` xml:"ver,attr" `
Release string ` xml:"rel,attr" `
} ` xml:"version" `
Checksum struct {
Checksum string ` xml:",chardata" `
Type string ` xml:"type,attr" `
Pkgid string ` xml:"pkgid,attr" `
} ` xml:"checksum" `
Summary string ` xml:"summary" `
Description string ` xml:"description" `
Packager string ` xml:"packager" `
URL string ` xml:"url" `
Time struct {
File uint64 ` xml:"file,attr" `
Build uint64 ` xml:"build,attr" `
} ` xml:"time" `
Size struct {
Package int64 ` xml:"package,attr" `
Installed uint64 ` xml:"installed,attr" `
Archive uint64 ` xml:"archive,attr" `
} ` xml:"size" `
Location struct {
Href string ` xml:"href,attr" `
} ` xml:"location" `
Format struct {
License string ` xml:"license" `
Vendor string ` xml:"vendor" `
Group string ` xml:"group" `
Buildhost string ` xml:"buildhost" `
Sourcerpm string ` xml:"sourcerpm" `
Provides EntryList ` xml:"provides" `
Requires EntryList ` xml:"requires" `
Conflicts EntryList ` xml:"conflicts" `
Obsoletes EntryList ` xml:"obsoletes" `
Files [ ] * rpm_module . File ` xml:"file" `
} ` xml:"format" `
} ` xml:"package" `
}
var result Metadata
decodeGzipXML ( t , resp , & result )
assert . EqualValues ( t , 1 , result . PackageCount )
assert . Len ( t , result . Packages , 1 )
p := result . Packages [ 0 ]
assert . Equal ( t , "rpm" , p . Type )
assert . Equal ( t , packageName , p . Name )
assert . Equal ( t , packageArchitecture , p . Architecture )
assert . Equal ( t , "YES" , p . Checksum . Pkgid )
assert . Equal ( t , "sha256" , p . Checksum . Type )
assert . Equal ( t , "f1d5d2ffcbe4a7568e98b864f40d923ecca084e9b9bcd5977ed6521c46d3fa4c" , p . Checksum . Checksum )
assert . Equal ( t , "https://gitea.io" , p . URL )
assert . EqualValues ( t , len ( content ) , p . Size . Package )
assert . EqualValues ( t , 13 , p . Size . Installed )
assert . EqualValues ( t , 272 , p . Size . Archive )
assert . Equal ( t , fmt . Sprintf ( "package/%s/%s/%s/%s" , packageName , packageVersion , packageArchitecture , fmt . Sprintf ( "%s-%s.%s.rpm" , packageName , packageVersion , packageArchitecture ) ) , p . Location . Href )
f := p . Format
assert . Equal ( t , "MIT" , f . License )
assert . Len ( t , f . Provides . Entries , 2 )
assert . Len ( t , f . Requires . Entries , 7 )
assert . Empty ( t , f . Conflicts . Entries )
assert . Empty ( t , f . Obsoletes . Entries )
assert . Len ( t , f . Files , 1 )
} )
t . Run ( "filelists.xml.gz" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/filelists.xml.gz" )
resp := MakeRequest ( t , req , http . StatusOK )
type Filelists struct {
XMLName xml . Name ` xml:"filelists" `
Xmlns string ` xml:"xmlns,attr" `
PackageCount int ` xml:"packages,attr" `
Packages [ ] struct {
Pkgid string ` xml:"pkgid,attr" `
Name string ` xml:"name,attr" `
Architecture string ` xml:"arch,attr" `
Version struct {
Epoch string ` xml:"epoch,attr" `
Version string ` xml:"ver,attr" `
Release string ` xml:"rel,attr" `
} ` xml:"version" `
Files [ ] * rpm_module . File ` xml:"file" `
} ` xml:"package" `
}
var result Filelists
decodeGzipXML ( t , resp , & result )
assert . EqualValues ( t , 1 , result . PackageCount )
assert . Len ( t , result . Packages , 1 )
p := result . Packages [ 0 ]
assert . NotEmpty ( t , p . Pkgid )
assert . Equal ( t , packageName , p . Name )
assert . Equal ( t , packageArchitecture , p . Architecture )
assert . Len ( t , p . Files , 1 )
f := p . Files [ 0 ]
assert . Equal ( t , "/usr/local/bin/hello" , f . Path )
} )
t . Run ( "other.xml.gz" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req = NewRequest ( t , "GET" , url + "/other.xml.gz" )
resp := MakeRequest ( t , req , http . StatusOK )
type Other struct {
XMLName xml . Name ` xml:"otherdata" `
Xmlns string ` xml:"xmlns,attr" `
PackageCount int ` xml:"packages,attr" `
Packages [ ] struct {
Pkgid string ` xml:"pkgid,attr" `
Name string ` xml:"name,attr" `
Architecture string ` xml:"arch,attr" `
Version struct {
Epoch string ` xml:"epoch,attr" `
Version string ` xml:"ver,attr" `
Release string ` xml:"rel,attr" `
} ` xml:"version" `
Changelogs [ ] * rpm_module . Changelog ` xml:"changelog" `
} ` xml:"package" `
}
var result Other
decodeGzipXML ( t , resp , & result )
assert . EqualValues ( t , 1 , result . PackageCount )
assert . Len ( t , result . Packages , 1 )
p := result . Packages [ 0 ]
assert . NotEmpty ( t , p . Pkgid )
assert . Equal ( t , packageName , p . Name )
assert . Equal ( t , packageArchitecture , p . Architecture )
assert . Len ( t , p . Changelogs , 1 )
c := p . Changelogs [ 0 ]
assert . Equal ( t , "KN4CK3R <dummy@gitea.io>" , c . Author )
assert . EqualValues ( t , 1678276800 , c . Date )
assert . Equal ( t , "- Changelog message." , c . Text )
} )
} )
t . Run ( "Delete" , func ( t * testing . T ) {
defer tests . PrintCurrentTest ( t ) ( )
req := NewRequest ( t , "DELETE" , fmt . Sprintf ( "%s/el9/stable/package/%s/%s/%s" , rootURL , packageName , packageVersion , packageArchitecture ) )
MakeRequest ( t , req , http . StatusUnauthorized )
req = NewRequest ( t , "DELETE" , fmt . Sprintf ( "%s/el9/stable/package/%s/%s/%s" , rootURL , packageName , packageVersion , packageArchitecture ) ) .
AddBasicAuth ( user . Name )
MakeRequest ( t , req , http . StatusNoContent )
pvs , err := packages . GetVersionsByPackageType ( db . DefaultContext , user . ID , packages . TypeRpm )
assert . NoError ( t , err )
assert . Empty ( t , pvs )
req = NewRequest ( t , "DELETE" , fmt . Sprintf ( "%s/el9/stable/package/%s/%s/%s" , rootURL , packageName , packageVersion , packageArchitecture ) ) .
AddBasicAuth ( user . Name )
MakeRequest ( t , req , http . StatusNotFound )
} )
}
}