Skip to content

Commit

Permalink
test: update integration tests for alpine
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Deza <adeza@anchore.com>
  • Loading branch information
Alfredo Deza committed Aug 6, 2020
1 parent e4689c6 commit 4a81877
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/integration/db_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ type mockStore struct {
func NewMockDbStore() *mockStore {
return &mockStore{
backend: map[string]map[string][]v1.Vulnerability{
"nvd": {
"libvncserver": []v1.Vulnerability{
{
ID: "CVE-alpine-libvncserver",
VersionConstraint: "< 0.9.10",
VersionFormat: "unknown",
CPEs: []string{"cpe:2.3:a:lib_vnc_project-(server):libvncserver:*:*:*:*:*:*:*:*"},
},
},
},
"alpine:3.12": {
"libvncserver": []v1.Vulnerability{
{
ID: "CVE-alpine-libvncserver",
VersionConstraint: "< 0.9.10",
VersionFormat: "unknown",
},
},
},
"github:npm": {
"validator": []v1.Vulnerability{
{
Expand Down
31 changes: 31 additions & 0 deletions test/integration/match_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ func getPackagesByPath(t *testing.T, theScope scope.Scope, catalog *pkg.Catalog,
return catalog.PackagesByFile(refs[0])
}

func addAlpineMatches(t *testing.T, theScope scope.Scope, catalog *pkg.Catalog, theStore *mockStore, theResult *result.Result) {
packages := getPackagesByPath(t, theScope, catalog, "/lib/apk/db/installed")
if len(packages) != 1 {
t.Logf("Alpine Packages: %+v", packages)
t.Fatalf("problem with upstream syft cataloger (alpine)")
}
thePkg := packages[0]
theVuln := theStore.backend["alpine:3.12"][thePkg.Name][0]
vulnObj, err := vulnerability.NewVulnerability(theVuln)
if err != nil {
t.Fatalf("failed to create vuln obj: %+v", err)
}
theResult.Add(thePkg, match.Match{
Type: match.FuzzyMatch,
Confidence: 1.0,
Vulnerability: *vulnObj,
Package: thePkg,
SearchKey: "cpe[cpe:2.3:*:*:libvncserver:0.9.9:*:*:*:*:*:*:*] constraint[< 0.9.10 (unknown)]",
IndirectPackage: nil,
Matcher: match.ApkMatcher,
})
}

func addJavascriptMatches(t *testing.T, theScope scope.Scope, catalog *pkg.Catalog, theStore *mockStore, theResult *result.Result) {
packages := getPackagesByPath(t, theScope, catalog, "/javascript/pkg-lock/package-lock.json")
if len(packages) != 1 {
Expand Down Expand Up @@ -204,6 +227,14 @@ func TestPkgCoverageImage(t *testing.T) {
return expectedResults
},
},
{
fixtureImage: "image-alpine-match-coverage",
expectedFn: func(theScope scope.Scope, catalog *pkg.Catalog, theStore *mockStore) result.Result {
expectedResults := result.NewResult()
addAlpineMatches(t, theScope, catalog, theStore, &expectedResults)
return expectedResults
},
},
}

for _, test := range tests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM scratch
COPY . .
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.12.0
PRETTY_NAME="Alpine Linux v3.12"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"

0 comments on commit 4a81877

Please sign in to comment.