From b713c5ba1217b7d6b60b923993faab5ad23e7344 Mon Sep 17 00:00:00 2001 From: Piotr Radkowski Date: Mon, 7 Oct 2024 14:12:45 +0200 Subject: [PATCH] test: parse 'package.json' files with non-standard fields in author section Signed-off-by: Piotr Radkowski --- .../javascript/parse_package_json_test.go | 21 +++++++++++++++++++ .../pkg-json/package-author-non-standard.json | 16 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 syft/pkg/cataloger/javascript/test-fixtures/pkg-json/package-author-non-standard.json diff --git a/syft/pkg/cataloger/javascript/parse_package_json_test.go b/syft/pkg/cataloger/javascript/parse_package_json_test.go index 5c544580a893..5d6ebaf4a7e0 100644 --- a/syft/pkg/cataloger/javascript/parse_package_json_test.go +++ b/syft/pkg/cataloger/javascript/parse_package_json_test.go @@ -179,6 +179,27 @@ func TestParsePackageJSON(t *testing.T) { }, }, }, + { + Fixture: "test-fixtures/pkg-json/package-author-non-standard.json", + ExpectedPkg: pkg.Package{ + Name: "npm", + Version: "6.14.6", + PURL: "pkg:npm/npm@6.14.6", + Type: pkg.NpmPkg, + Licenses: pkg.NewLicenseSet( + pkg.NewLicenseFromLocations("Artistic-2.0", file.NewLocation("test-fixtures/pkg-json/package-author-non-standard.json")), + ), + Language: pkg.JavaScript, + Metadata: pkg.NpmPackage{ + Name: "npm", + Version: "6.14.6", + Author: "npm Inc. (https://www.npmjs.com/)", + Homepage: "https://docs.npmjs.com/", + URL: "https://github.com/npm/cli", + Description: "a package manager for JavaScript", + }, + }, + }, } for _, test := range tests { diff --git a/syft/pkg/cataloger/javascript/test-fixtures/pkg-json/package-author-non-standard.json b/syft/pkg/cataloger/javascript/test-fixtures/pkg-json/package-author-non-standard.json new file mode 100644 index 000000000000..a71cf820a4d3 --- /dev/null +++ b/syft/pkg/cataloger/javascript/test-fixtures/pkg-json/package-author-non-standard.json @@ -0,0 +1,16 @@ +{ + "version": "6.14.6", + "name": "npm", + "description": "a package manager for JavaScript", + "homepage": "https://docs.npmjs.com/", + "author": { + "name": "npm Inc.", + "url": "https://www.npmjs.com/", + "organization": true + }, + "repository": { + "type": "git", + "url": "https://github.com/npm/cli" + }, + "license": "Artistic-2.0" +} \ No newline at end of file