From e063471c6608b9f7492820aa47d5de8acbf9ffef Mon Sep 17 00:00:00 2001 From: witchcraze <67056980+witchcraze@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:50:01 +0900 Subject: [PATCH] feat: add apache httpd binary classifier (#1448) Signed-off-by: witchcraze --- syft/pkg/cataloger/binary/cataloger_test.go | 13 +++++++++++++ .../cataloger/binary/default_classifiers.go | 9 +++++++++ .../classifiers/positive/httpd-2.4.54/httpd | 18 ++++++++++++++++++ test/integration/package_deduplication_test.go | 10 ++++++---- 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54/httpd diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 58df64219..2e86ba2ab 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -18,6 +18,19 @@ func TestClassifierCataloger_DefaultClassifiers_PositiveCases(t *testing.T) { expected pkg.Package }{ { + name: "positive-httpd-2.4.54", + fixtureDir: "test-fixtures/classifiers/positive/httpd-2.4.54", + expected: pkg.Package{ + Name: "httpd", + Version: "2.4.54", + Type: "binary", + PURL: "pkg:generic/httpd@2.4.54", + Locations: singleLocation("httpd"), + Metadata: pkg.BinaryMetadata{ + Classifier: "httpd-binary", + }, + }, + }, { name: "positive-php-cli-8.2.1", fixtureDir: "test-fixtures/classifiers/positive/php-cli-8.2.1", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index 986faebaf..87c836fd6 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -132,4 +132,13 @@ var defaultClassifiers = []classifier{ PURL: mustPURL("pkg:generic/php@version"), CPEs: singleCPE("cpe:2.3:a:php:php:*:*:*:*:*:*:*:*"), }, + { + Class: "httpd-binary", + FileGlob: "**/httpd", + EvidenceMatcher: fileContentsVersionMatcher( + `(?m)Apache\/(?P[0-9]+\.[0-9]+\.[0-9]+)`), + Package: "httpd", + PURL: mustPURL("pkg:generic/httpd@version"), + CPEs: singleCPE("cpe:2.3:a:apache:http_server:*:*:*:*:*:*:*:*"), + }, } diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54/httpd b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54/httpd new file mode 100644 index 000000000..441662ab1 --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54/httpd @@ -0,0 +1,18 @@ +