From 284814153d311a5577724e33cfe770716bc23762 Mon Sep 17 00:00:00 2001 From: witchcraze <67056980+witchcraze@users.noreply.github.com> Date: Thu, 9 Feb 2023 04:31:17 +0900 Subject: [PATCH] feat: add postgresql classifier (#1536) * add postgresql classifier Signed-off-by: witchcraze * revert package dedup test upgrade Signed-off-by: Alex Goodman --------- Signed-off-by: Alex Goodman Co-authored-by: Alex Goodman --- syft/pkg/cataloger/binary/cataloger_test.go | 56 ++++++++++++++++++ .../cataloger/binary/default_classifiers.go | 12 ++++ .../positive/postgresql-15.1/postgres | Bin 0 -> 16 bytes .../positive/postgresql-15beta4/postgres | Bin 0 -> 19 bytes .../positive/postgresql-9.5alpha1/postgres | 5 ++ .../positive/postgresql-9.6.24/postgres | Bin 0 -> 18 bytes 6 files changed, 73 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-15.1/postgres create mode 100755 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-15beta4/postgres create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-9.5alpha1/postgres create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-9.6.24/postgres diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 46c4d40e385..ab70b4c26fb 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -19,6 +19,62 @@ func TestClassifierCataloger_DefaultClassifiers_PositiveCases(t *testing.T) { fixtureDir string expected pkg.Package }{ + { + name: "positive-postgresql-15beta4", + fixtureDir: "test-fixtures/classifiers/positive/postgresql-15beta4", + expected: pkg.Package{ + Name: "postgresql", + Version: "15beta4", + Type: "binary", + PURL: "pkg:generic/postgresql@15beta4", + Locations: singleLocation("postgres"), + Metadata: pkg.BinaryMetadata{ + Classifier: "postgresql-binary", + }, + }, + }, + { + name: "positive-postgresql-15.1", + fixtureDir: "test-fixtures/classifiers/positive/postgresql-15.1", + expected: pkg.Package{ + Name: "postgresql", + Version: "15.1", + Type: "binary", + PURL: "pkg:generic/postgresql@15.1", + Locations: singleLocation("postgres"), + Metadata: pkg.BinaryMetadata{ + Classifier: "postgresql-binary", + }, + }, + }, + { + name: "positive-postgresql-9.6.24", + fixtureDir: "test-fixtures/classifiers/positive/postgresql-9.6.24", + expected: pkg.Package{ + Name: "postgresql", + Version: "9.6.24", + Type: "binary", + PURL: "pkg:generic/postgresql@9.6.24", + Locations: singleLocation("postgres"), + Metadata: pkg.BinaryMetadata{ + Classifier: "postgresql-binary", + }, + }, + }, + { + name: "positive-postgresql-9.5alpha1", + fixtureDir: "test-fixtures/classifiers/positive/postgresql-9.5alpha1", + expected: pkg.Package{ + Name: "postgresql", + Version: "9.5alpha1", + Type: "binary", + PURL: "pkg:generic/postgresql@9.5alpha1", + Locations: singleLocation("postgres"), + Metadata: pkg.BinaryMetadata{ + Classifier: "postgresql-binary", + }, + }, + }, { name: "positive-traefik-2.9.6", fixtureDir: "test-fixtures/classifiers/positive/traefik-2.9.6", diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index f9d3334386a..77e048d9b40 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -175,4 +175,16 @@ var defaultClassifiers = []classifier{ Package: "traefik", PURL: mustPURL("pkg:generic/traefik@version"), }, + { + Class: "postgresql-binary", + FileGlob: "**/postgres", + EvidenceMatcher: fileContentsVersionMatcher( + // [NUL]PostgreSQL 15beta4 + // [NUL]PostgreSQL 15.1 + // [NUL]PostgreSQL 9.6.24 + // ?PostgreSQL 9.5alpha1 + `(?m)(\x00|\?)PostgreSQL (?P[0-9]+(\.[0-9]+)?(\.[0-9]+)?(alpha[0-9]|beta[0-9]|rc[0-9])?)`), + Package: "postgresql", + PURL: mustPURL("pkg:generic/postgresql@version"), + }, } diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-15.1/postgres b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-15.1/postgres new file mode 100644 index 0000000000000000000000000000000000000000..149da9050f13a0ddbb309a5ab4285b06ccaea3e7 GIT binary patch literal 16 XcmZPw$S*EQFG>v#^ieQ0)iVSDE3O2( literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-15beta4/postgres b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-15beta4/postgres new file mode 100755 index 0000000000000000000000000000000000000000..50f6b3d2dd49b7a9273e0918214e3c2921a32acd GIT binary patch literal 19 acmZPw$S*EQFG>v#^ieQ0O-e0EGywoU0tPDp literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-9.5alpha1/postgres b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-9.5alpha1/postgres new file mode 100644 index 00000000000..1188fb403f4 --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-9.5alpha1/postgres @@ -0,0 +1,5 @@ +byteaout +byteain +?PostgreSQL 9.5alpha1 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit +/tmp/buildd/postgresql-9.5-9.5~alpha1/build/../src/backend/utils/adt/windowfuncs.c +argument of ntile must be greater than zero diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-9.6.24/postgres b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/postgresql-9.6.24/postgres new file mode 100644 index 0000000000000000000000000000000000000000..cc29b7ae893cf0e7a87dca37dc126988c11a79ee GIT binary patch literal 18 ZcmZPw$S*EQFG>v#^ii