Add pacman (alpm) parser support (#943)

Co-authored-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
Morten Linderud
2022-06-13 18:51:37 +00:00
committed by GitHub
co-authored by Christopher Phillips
parent f15d4a9984
commit e72d68b0c6
42 changed files with 2348 additions and 43 deletions
@@ -221,6 +221,13 @@ var dirOnlyTestCases = []testCase{
}
var commonTestCases = []testCase{
{
name: "find alpm packages",
pkgType: pkg.AlpmPkg,
pkgInfo: map[string]string{
"pacman": "6.0.1-5",
},
},
{
name: "find rpmdb packages",
pkgType: pkg.RpmPkg,
@@ -90,7 +90,6 @@ func TestPkgCoverageImage(t *testing.T) {
pkgCount := 0
for a := range sbom.Artifacts.PackageCatalog.Enumerate(c.pkgType) {
if a.Language.String() != "" {
observedLanguages.Add(a.Language.String())
}
@@ -167,7 +166,6 @@ func TestPkgCoverageDirectory(t *testing.T) {
actualPkgCount := 0
for actualPkg := range sbom.Artifacts.PackageCatalog.Enumerate(test.pkgType) {
observedLanguages.Add(actualPkg.Language.String())
observedPkgs.Add(string(actualPkg.Type))
+9 -13
View File
@@ -42,32 +42,28 @@ func TestConvertCmd(t *testing.T) {
f, err := ioutil.TempFile("", "test-convert-sbom-")
require.NoError(t, err)
defer func() {
err := f.Close()
require.NoError(t, err)
os.Remove(f.Name())
}()
err = format.Encode(f, sbom)
require.NoError(t, err)
stdr, stdw, err := os.Pipe()
require.NoError(t, err)
originalStdout := os.Stdout
os.Stdout = stdw
ctx := context.Background()
app := &config.Application{Outputs: []string{format.ID().String()}}
// stdout reduction of test noise
rescue := os.Stdout // keep backup of the real stdout
os.Stdout, _ = os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
defer func() {
os.Stdout = rescue
}()
err = convert.Run(ctx, app, []string{f.Name()})
require.NoError(t, err)
stdw.Close()
out, err := ioutil.ReadAll(stdr)
file, err := ioutil.ReadFile(f.Name())
require.NoError(t, err)
os.Stdout = originalStdout
formatFound := syft.IdentifyFormat(out)
formatFound := syft.IdentifyFormat(file)
if format.ID() == table.ID {
require.Nil(t, formatFound)
return
@@ -0,0 +1,57 @@
%NAME%
pacman
%VERSION%
6.0.1-5
%BASE%
pacman
%DESC%
A library-based package manager with dependency support
%URL%
https://www.archlinux.org/pacman/
%ARCH%
x86_64
%BUILDDATE%
1652116331
%INSTALLDATE%
1654074247
%PACKAGER%
Morten Linderud <foxboron@archlinux.org>
%SIZE%
4925474
%REASON%
1
%GROUPS%
base-devel
%LICENSE%
GPL
%VALIDATION%
pgp
%DEPENDS%
bash
glibc
libarchive
curl
gpgme
pacman-mirrorlist
archlinux-keyring
%OPTDEPENDS%
perl-locale-gettext: translation support in makepkg-template
%PROVIDES%
libalpm.so=13-64
@@ -0,0 +1,30 @@
%FILES%
etc/
etc/makepkg.conf
etc/pacman.conf
usr/
usr/bin/
usr/bin/makepkg
usr/bin/makepkg-template
usr/bin/pacman
usr/bin/pacman-conf
usr/bin/pacman-db-upgrade
usr/bin/pacman-key
usr/bin/repo-add
usr/bin/repo-elephant
usr/bin/repo-remove
usr/bin/testpkg
usr/bin/vercmp
usr/include/
usr/include/alpm.h
usr/include/alpm_list.h
usr/lib/
usr/lib/libalpm.so
usr/lib/libalpm.so.13
usr/lib/libalpm.so.13.0.1
usr/lib/pkgconfig/
usr/lib/pkgconfig/libalpm.pc
%BACKUP%
etc/pacman.conf de541390e52468165b96511c4665bff4
etc/makepkg.conf 79fce043df7dfc676ae5ecb903762d8b