Skip to content

Commit d6190c2

Browse files
committed
Fix tests
Signed-off-by: Tim Olshansky <[email protected]>
1 parent ae9a9e9 commit d6190c2

File tree

4 files changed

+112
-3
lines changed

4 files changed

+112
-3
lines changed

syft/format/internal/spdxutil/helpers/originator_supplier_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func Test_OriginatorSupplier(t *testing.T) {
4040
pkg.PhpComposerInstalledEntry{},
4141
pkg.PhpPearEntry{},
4242
pkg.PhpPeclEntry{},
43+
pkg.PnpmLockEntry{},
4344
pkg.PortageEntry{},
4445
pkg.PythonPipfileLockEntry{},
4546
pkg.PythonPdmLockEntry{},

syft/pkg/cataloger/javascript/parse_yarn_lock.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,13 @@ func parseYarnV1LockFile(reader io.ReadCloser) ([]yarnPackage, error) {
113113
pkg.Version = strings.Trim(array[1], "\"")
114114
case "resolved":
115115
name, version, resolved := findResolvedPackageAndVersion(line)
116-
pkg.Name = name
117-
pkg.Version = version
118-
pkg.Resolved = resolved
116+
if name != "" && version != "" && resolved != "" {
117+
pkg.Name = name
118+
pkg.Version = version
119+
pkg.Resolved = resolved
120+
} else {
121+
pkg.Resolved = strings.Trim(array[1], "\"")
122+
}
119123
case "integrity":
120124
pkg.Integrity = strings.Trim(array[1], "\"")
121125
}

syft/pkg/cataloger/javascript/parse_yarn_lock_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,82 @@ func TestParseYarnLockWithRelationships(t *testing.T) {
528528
adapter := newGenericYarnLockAdapter(CatalogerConfig{})
529529
pkgtest.TestFileParser(t, fixture, adapter.parseYarnLock, expectedPkgs, expectedRelationships)
530530
}
531+
func TestParseYarnLockWithDuplicates(t *testing.T) {
532+
var expectedRelationships []artifact.Relationship
533+
fixture := "test-fixtures/yarn-dups/yarn.lock"
534+
locations := file.NewLocationSet(file.NewLocation(fixture))
535+
536+
expectedPkgs := []pkg.Package{
537+
{
538+
Name: "async",
539+
Version: "0.9.2",
540+
Locations: locations,
541+
PURL: "pkg:npm/[email protected]",
542+
Language: pkg.JavaScript,
543+
Type: pkg.NpmPkg,
544+
Metadata: pkg.YarnLockEntry{
545+
Resolved: "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d",
546+
Integrity: "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=",
547+
Dependencies: map[string]string{},
548+
},
549+
},
550+
{
551+
Name: "async",
552+
Version: "3.2.3",
553+
Locations: locations,
554+
PURL: "pkg:npm/[email protected]",
555+
Language: pkg.JavaScript,
556+
Type: pkg.NpmPkg,
557+
Metadata: pkg.YarnLockEntry{
558+
Resolved: "https://registry.yarnpkg.com/async/-/async-3.2.3.tgz#ac53dafd3f4720ee9e8a160628f18ea91df196c9",
559+
Integrity: "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==",
560+
Dependencies: map[string]string{},
561+
},
562+
},
563+
{
564+
Name: "merge-objects",
565+
Version: "1.0.5",
566+
Locations: locations,
567+
PURL: "pkg:npm/[email protected]",
568+
Language: pkg.JavaScript,
569+
Type: pkg.NpmPkg,
570+
Metadata: pkg.YarnLockEntry{
571+
Resolved: "https://registry.yarnpkg.com/merge-objects/-/merge-objects-1.0.5.tgz#ad923ff3910091acc1438f53eb75b8f37d862a86",
572+
Integrity: "sha1-rZI/85EAkazBQ49T63W4832GKoY=",
573+
Dependencies: map[string]string{},
574+
},
575+
},
576+
{
577+
Name: "@4lolo/resize-observer-polyfill",
578+
Version: "1.5.2",
579+
Locations: locations,
580+
PURL: "pkg:npm/%404lolo/[email protected]",
581+
Language: pkg.JavaScript,
582+
Type: pkg.NpmPkg,
583+
Metadata: pkg.YarnLockEntry{
584+
Resolved: "https://registry.yarnpkg.com/@4lolo/resize-observer-polyfill/-/resize-observer-polyfill-1.5.2.tgz#58868fc7224506236b5550d0c68357f0a874b84b",
585+
Integrity: "sha512-HY4JYLITsWBOdeqCF/x3q7Aa2PVl/BmfkPv4H/Qzplc4Lrn9cKmWz6jHyAREH9tFuD0xELjJVgX3JaEmdcXu3g==",
586+
Dependencies: map[string]string{},
587+
},
588+
},
589+
{
590+
Name: "should-type",
591+
Version: "1.3.0",
592+
Locations: locations,
593+
PURL: "pkg:npm/[email protected]",
594+
Language: pkg.JavaScript,
595+
Type: pkg.NpmPkg,
596+
Metadata: pkg.YarnLockEntry{
597+
Resolved: "https://github.com/shouldjs/type.git#31d26945cb3b4ad21d2308776e4442c461666390",
598+
Integrity: "",
599+
Dependencies: map[string]string{},
600+
},
601+
},
602+
}
603+
604+
adapter := newGenericYarnLockAdapter(CatalogerConfig{})
605+
pkgtest.TestFileParser(t, fixture, adapter.parseYarnLock, expectedPkgs, expectedRelationships)
606+
}
531607

532608
type handlerPath struct {
533609
path string
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
6+
version "0.9.2"
7+
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
8+
integrity sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=
9+
10+
async@^3.2.3:
11+
version "3.2.3"
12+
resolved "https://registry.yarnpkg.com/async/-/async-3.2.3.tgz#ac53dafd3f4720ee9e8a160628f18ea91df196c9"
13+
integrity sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==
14+
15+
merge-objects@^1.0.5:
16+
version "1.0.5"
17+
resolved "https://registry.yarnpkg.com/merge-objects/-/merge-objects-1.0.5.tgz#ad923ff3910091acc1438f53eb75b8f37d862a86"
18+
integrity sha1-rZI/85EAkazBQ49T63W4832GKoY=
19+
20+
resize-observer-polyfill@^1.5.1:
21+
name "resize-observer-polyfill"
22+
version "1.5.2"
23+
resolved "https://registry.yarnpkg.com/@4lolo/resize-observer-polyfill/-/resize-observer-polyfill-1.5.2.tgz#58868fc7224506236b5550d0c68357f0a874b84b"
24+
integrity sha512-HY4JYLITsWBOdeqCF/x3q7Aa2PVl/BmfkPv4H/Qzplc4Lrn9cKmWz6jHyAREH9tFuD0xELjJVgX3JaEmdcXu3g==
25+
26+
"should-type@https://github.com/shouldjs/type.git#1.3.0":
27+
version "1.3.0"
28+
resolved "https://github.com/shouldjs/type.git#31d26945cb3b4ad21d2308776e4442c461666390"

0 commit comments

Comments
 (0)