Merge pull request #389 from anchore/issue-381

Support msrc types
This commit is contained in:
Alfredo Deza
2021-04-29 14:59:04 -04:00
committed by GitHub
6 changed files with 26 additions and 4 deletions
+7 -4
View File
@@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/anchore/syft/internal" "github.com/anchore/syft/internal"
"github.com/stretchr/testify/assert"
"github.com/anchore/syft/syft/source" "github.com/anchore/syft/syft/source"
) )
@@ -88,10 +89,15 @@ func TestIdentifyDistro(t *testing.T) {
observedDistros := internal.NewStringSet() observedDistros := internal.NewStringSet()
definedDistros := internal.NewStringSet() definedDistros := internal.NewStringSet()
for _, distroType := range All { for _, distroType := range All {
definedDistros.Add(string(distroType)) definedDistros.Add(string(distroType))
} }
// Somewhat cheating with Windows. There is no support for detecting/parsing a Windows OS, so it is not
// possible to comply with this test unless it is added manually to the "observed distros"
definedDistros.Remove(string(Windows))
for _, test := range tests { for _, test := range tests {
t.Run(test.fixture, func(t *testing.T) { t.Run(test.fixture, func(t *testing.T) {
s, err := source.NewFromDirectory(test.fixture) s, err := source.NewFromDirectory(test.fixture)
@@ -129,9 +135,7 @@ func TestIdentifyDistro(t *testing.T) {
return return
} }
if d.Version.String() != test.Version { assert.Equal(t, d.Version.String(), test.Version)
t.Errorf("expected distro version doesn't match: %v != %v", d.Version.String(), test.Version)
}
}) })
} }
@@ -145,7 +149,6 @@ func TestIdentifyDistro(t *testing.T) {
} }
t.Errorf("distro coverage incomplete (defined=%d, coverage=%d)", len(definedDistros), len(observedDistros)) t.Errorf("distro coverage incomplete (defined=%d, coverage=%d)", len(definedDistros), len(observedDistros))
} }
} }
func TestParseOsRelease(t *testing.T) { func TestParseOsRelease(t *testing.T) {
+3
View File
@@ -18,6 +18,7 @@ const (
ArchLinux Type = "archlinux" ArchLinux Type = "archlinux"
OpenSuseLeap Type = "opensuseleap" OpenSuseLeap Type = "opensuseleap"
Photon Type = "photon" Photon Type = "photon"
Windows Type = "windows"
) )
// All contains all Linux distribution options // All contains all Linux distribution options
@@ -34,6 +35,7 @@ var All = []Type{
ArchLinux, ArchLinux,
OpenSuseLeap, OpenSuseLeap,
Photon, Photon,
Windows,
} }
// IDMapping connects a distro ID like "ubuntu" to a Distro type // IDMapping connects a distro ID like "ubuntu" to a Distro type
@@ -50,6 +52,7 @@ var IDMapping = map[string]Type{
"arch": ArchLinux, "arch": ArchLinux,
"opensuse-leap": OpenSuseLeap, "opensuse-leap": OpenSuseLeap,
"photon": Photon, "photon": Photon,
"windows": Windows,
} }
// String returns the string representation of the given Linux distribution. // String returns the string representation of the given Linux distribution.
+11
View File
@@ -0,0 +1,11 @@
package pkg
// KbPackageMetadata is slightly odd in how it is expected to map onto data.
// This is critical to grasp because there is no MSRC cataloger. The `ProductID`
// field is expected to be the MSRC Product ID, for example:
// "Windows 10 Version 1703 for 32-bit Systems".
// `Kb` is expected to be the actual KB number, for example "5001028"
type KbPackageMetadata struct {
ProductID string `toml:"product_id" json:"product_id"`
Kb string `toml:"kb" json:"kb"`
}
+1
View File
@@ -14,4 +14,5 @@ const (
RpmdbMetadataType MetadataType = "RpmdbMetadata" RpmdbMetadataType MetadataType = "RpmdbMetadata"
PythonPackageMetadataType MetadataType = "PythonPackageMetadata" PythonPackageMetadataType MetadataType = "PythonPackageMetadata"
RustCargoPackageMetadataType MetadataType = "RustCargoPackageMetadata" RustCargoPackageMetadataType MetadataType = "RustCargoPackageMetadata"
KbPackageMetadataType MetadataType = "KbPackageMetadata"
) )
+2
View File
@@ -18,6 +18,7 @@ const (
JenkinsPluginPkg Type = "jenkins-plugin" JenkinsPluginPkg Type = "jenkins-plugin"
GoModulePkg Type = "go-module" GoModulePkg Type = "go-module"
RustPkg Type = "rust-crate" RustPkg Type = "rust-crate"
KbPkg Type = "msrc-kb"
) )
// AllPkgs represents all supported package types // AllPkgs represents all supported package types
@@ -32,6 +33,7 @@ var AllPkgs = []Type{
JenkinsPluginPkg, JenkinsPluginPkg,
GoModulePkg, GoModulePkg,
RustPkg, RustPkg,
KbPkg,
} }
// PackageURLType returns the PURL package type for the current package. // PackageURLType returns the PURL package type for the current package.
@@ -63,6 +63,7 @@ func TestPkgCoverageImage(t *testing.T) {
for _, p := range pkg.AllPkgs { for _, p := range pkg.AllPkgs {
definedPkgs.Add(string(p)) definedPkgs.Add(string(p))
} }
definedPkgs.Remove(string(pkg.KbPkg))
var cases []testCase var cases []testCase
cases = append(cases, commonTestCases...) cases = append(cases, commonTestCases...)
@@ -189,6 +190,7 @@ func TestPkgCoverageDirectory(t *testing.T) {
definedLanguages.Remove(pkg.UnknownLanguage.String()) definedLanguages.Remove(pkg.UnknownLanguage.String())
observedPkgs.Remove(string(pkg.UnknownPkg)) observedPkgs.Remove(string(pkg.UnknownPkg))
definedPkgs.Remove(string(pkg.UnknownPkg)) definedPkgs.Remove(string(pkg.UnknownPkg))
definedPkgs.Remove(string(pkg.KbPkg))
// ensure that integration test commonTestCases stay in sync with the available catalogers // ensure that integration test commonTestCases stay in sync with the available catalogers
if len(observedLanguages) < len(definedLanguages) { if len(observedLanguages) < len(definedLanguages) {