github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/redhat/parse_rpm_archive_test.go (about) 1 package redhat 2 3 import ( 4 "testing" 5 6 "github.com/anchore/syft/syft/file" 7 "github.com/anchore/syft/syft/pkg" 8 "github.com/lineaje-labs/syft/syft/pkg/cataloger/internal/pkgtest" 9 ) 10 11 func TestParseRpmFiles(t *testing.T) { 12 abcRpmLocation := file.NewLocation("abc-1.01-9.hg20160905.el7.x86_64.rpm") 13 zorkRpmLocation := file.NewLocation("zork-1.0.3-1.el7.x86_64.rpm") 14 tests := []struct { 15 fixture string 16 expected []pkg.Package 17 }{ 18 { 19 fixture: "test-fixtures/rpms", 20 expected: []pkg.Package{ 21 { 22 Name: "abc", 23 Version: "0:1.01-9.hg20160905.el7", 24 PURL: "pkg:rpm/abc@1.01-9.hg20160905.el7?arch=x86_64&epoch=0&upstream=abc-1.01-9.hg20160905.el7.src.rpm", 25 Locations: file.NewLocationSet(file.NewLocation("abc-1.01-9.hg20160905.el7.x86_64.rpm")), 26 FoundBy: "rpm-archive-cataloger", 27 Type: pkg.RpmPkg, 28 Licenses: pkg.NewLicenseSet( 29 pkg.NewLicenseFromLocations("MIT", abcRpmLocation), 30 ), 31 Metadata: pkg.RpmArchive{ 32 Name: "abc", 33 Epoch: intRef(0), 34 Arch: "x86_64", 35 Release: "9.hg20160905.el7", 36 Version: "1.01", 37 SourceRpm: "abc-1.01-9.hg20160905.el7.src.rpm", 38 Size: 17396, 39 Vendor: "Fedora Project", 40 Files: []pkg.RpmFileRecord{ 41 {"/usr/bin/abc", 33261, 7120, file.Digest{"sha256", "8f8495a65c66762b60afa0c3949d81b275ca6fa0601696caba5af762f455d0b9"}, "root", "root", ""}, 42 {"/usr/share/doc/abc-1.01", 16877, 4096, file.Digest{}, "root", "root", ""}, 43 {"/usr/share/doc/abc-1.01/readme.md", 33188, 4984, file.Digest{"sha256", "808af8a28391e96ca0d91086789488dda3724fe7c8b2859efd464fb04b94b2d4"}, "root", "root", "d"}, 44 {"/usr/share/doc/abc-1.01/readmeaig", 33188, 3324, file.Digest{"sha256", "530ec6175cf7fbeb7b595cbe7a50994429c4e62cae6666fb3a1d5745f3127b19"}, "root", "root", "d"}, 45 {"/usr/share/man/man1/abc.1.gz", 33188, 1968, file.Digest{"sha256", "cf2cfe25b29087e60ffd5f31f974a0762172fc2f009704951f12ff750ea77ed6"}, "root", "root", "d"}, 46 }, 47 }, 48 }, 49 { 50 Name: "zork", 51 Version: "0:1.0.3-1.el7", 52 PURL: "pkg:rpm/zork@1.0.3-1.el7?arch=x86_64&epoch=0&upstream=zork-1.0.3-1.el7.src.rpm", 53 Locations: file.NewLocationSet(zorkRpmLocation), 54 FoundBy: "rpm-archive-cataloger", 55 Type: pkg.RpmPkg, 56 Licenses: pkg.NewLicenseSet( 57 pkg.NewLicenseFromLocations("Public Domain", zorkRpmLocation), 58 ), 59 Metadata: pkg.RpmArchive{ 60 Name: "zork", 61 Epoch: intRef(0), 62 Arch: "x86_64", 63 Release: "1.el7", 64 Version: "1.0.3", 65 SourceRpm: "zork-1.0.3-1.el7.src.rpm", 66 Size: 262367, 67 Vendor: "Fedora Project", 68 Files: []pkg.RpmFileRecord{ 69 {"/usr/bin/zork", 33261, 115440, file.Digest{"sha256", "31b2ffc20b676a8fff795a45308f584273b9c47e8f7e196b4f36220b2734b472"}, "root", "root", ""}, 70 {"/usr/share/doc/zork-1.0.3", 16877, 38, file.Digest{}, "root", "root", ""}, 71 {"/usr/share/doc/zork-1.0.3/README.md", 33188, 5123, file.Digest{"sha256", "0013d67610a80c9f62d151a952f18d520b15b4c505b3ec2af34b96ab824654a4"}, "root", "root", "d"}, 72 {"/usr/share/doc/zork-1.0.3/history", 33188, 4816, file.Digest{"sha256", "6949044a65adefca6ac0132c18cfccc4ba8fdaec948424b6ccb60afd8a6ac82f"}, "root", "root", "d"}, 73 {"/usr/share/licenses/zork-1.0.3", 16877, 24, file.Digest{}, "root", "root", ""}, 74 {"/usr/share/licenses/zork-1.0.3/readme.txt", 33188, 146, file.Digest{"sha256", "9d6f7500555a2ecc3cb289dcca1e37fb96894dab1e4ba692b4d36fd6c3bdf939"}, "root", "root", "l"}, 75 {"/usr/share/man/man6/dungeon.6.gz", 33188, 3800, file.Digest{"sha256", "9b065d6a6f65b4d2d038fcca0af47a38e8723c32008d08659739ac34abe018da"}, "root", "root", "d"}, 76 {"/usr/share/man/man6/zork.6.gz", 33188, 34, file.Digest{"sha256", "18fbcb598bc40a25befe26256e29366984d2288dd154f877b8ac5fc138dd0884"}, "root", "root", "d"}, 77 {"/usr/share/zork/dtextc.dat", 33188, 133008, file.Digest{"sha256", "25ca42857c2b32054916d9258152293ead644023d5e03bec039ea92014e2ef91"}, "root", "root", ""}, 78 }, 79 }, 80 }, 81 }, 82 }, 83 { 84 fixture: "test-fixtures/bad", 85 }, 86 } 87 88 for _, test := range tests { 89 t.Run(test.fixture, func(t *testing.T) { 90 pkgtest.NewCatalogTester(). 91 FromDirectory(t, test.fixture). 92 Expects(test.expected, nil). 93 TestCataloger(t, NewArchiveCataloger()) 94 }) 95 } 96 }