github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/php/parse_installed_json_test.go (about) 1 package php 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/anchore/syft/syft/artifact" 8 "github.com/anchore/syft/syft/file" 9 "github.com/anchore/syft/syft/pkg" 10 "github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 11 ) 12 13 func TestParseInstalledJsonComposerV1(t *testing.T) { 14 ctx := context.TODO() 15 fixtures := []string{ 16 "test-fixtures/vendor/composer_1/installed.json", 17 "test-fixtures/vendor/composer_2/installed.json", 18 } 19 20 var expectedRelationships []artifact.Relationship 21 var expectedPkgs = []pkg.Package{ 22 { 23 Name: "asm89/stack-cors", 24 Version: "1.3.0", 25 PURL: "pkg:composer/asm89/stack-cors@1.3.0", 26 Language: pkg.PHP, 27 Type: pkg.PhpComposerPkg, 28 Licenses: pkg.NewLicenseSet( 29 pkg.NewLicenseWithContext(ctx, "MIT"), 30 ), 31 Metadata: pkg.PhpComposerInstalledEntry{ 32 Name: "asm89/stack-cors", 33 Version: "1.3.0", 34 Source: pkg.PhpComposerExternalReference{ 35 Type: "git", 36 URL: "https://github.com/asm89/stack-cors.git", 37 Reference: "b9c31def6a83f84b4d4a40d35996d375755f0e08", 38 }, 39 Dist: pkg.PhpComposerExternalReference{ 40 Type: "zip", 41 URL: "https://api.github.com/repos/asm89/stack-cors/zipball/b9c31def6a83f84b4d4a40d35996d375755f0e08", 42 Reference: "b9c31def6a83f84b4d4a40d35996d375755f0e08", 43 }, 44 Require: map[string]string{ 45 "php": ">=5.5.9", 46 "symfony/http-foundation": "~2.7|~3.0|~4.0|~5.0", 47 "symfony/http-kernel": "~2.7|~3.0|~4.0|~5.0", 48 }, 49 RequireDev: map[string]string{ 50 "phpunit/phpunit": "^5.0 || ^4.8.10", 51 "squizlabs/php_codesniffer": "^2.3", 52 }, 53 Time: "2019-12-24T22:41:47+00:00", 54 Type: "library", 55 NotificationURL: "https://packagist.org/downloads/", 56 Authors: []pkg.PhpComposerAuthors{ 57 { 58 Name: "Alexander", 59 Email: "iam.asm89@gmail.com", 60 }, 61 }, 62 63 Description: "Cross-origin resource sharing library and stack middleware", 64 Homepage: "https://github.com/asm89/stack-cors", 65 Keywords: []string{ 66 "cors", 67 "stack", 68 }, 69 }, 70 }, 71 { 72 Name: "behat/mink", 73 Version: "v1.8.1", 74 PURL: "pkg:composer/behat/mink@v1.8.1", 75 Language: pkg.PHP, 76 Type: pkg.PhpComposerPkg, 77 Licenses: pkg.NewLicenseSet( 78 pkg.NewLicenseWithContext(ctx, "MIT"), 79 ), 80 Metadata: pkg.PhpComposerInstalledEntry{ 81 Name: "behat/mink", 82 Version: "v1.8.1", 83 Source: pkg.PhpComposerExternalReference{ 84 Type: "git", 85 URL: "https://github.com/minkphp/Mink.git", 86 Reference: "07c6a9fe3fa98c2de074b25d9ed26c22904e3887", 87 }, 88 Dist: pkg.PhpComposerExternalReference{ 89 Type: "zip", 90 URL: "https://api.github.com/repos/minkphp/Mink/zipball/07c6a9fe3fa98c2de074b25d9ed26c22904e3887", 91 Reference: "07c6a9fe3fa98c2de074b25d9ed26c22904e3887", 92 }, 93 Require: map[string]string{ 94 "php": ">=5.3.1", 95 "symfony/css-selector": "^2.7|^3.0|^4.0|^5.0", 96 }, 97 RequireDev: map[string]string{ 98 "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20", 99 "symfony/debug": "^2.7|^3.0|^4.0", 100 "symfony/phpunit-bridge": "^3.4.38 || ^5.0.5", 101 }, 102 Suggest: map[string]string{ 103 "behat/mink-browserkit-driver": "extremely fast headless driver for Symfony\\Kernel-based apps (Sf2, Silex)", 104 "behat/mink-goutte-driver": "fast headless driver for any app without JS emulation", 105 "behat/mink-selenium2-driver": "slow, but JS-enabled driver for any app (requires Selenium2)", 106 "behat/mink-zombie-driver": "fast and JS-enabled headless driver for any app (requires node.js)", 107 "dmore/chrome-mink-driver": "fast and JS-enabled driver for any app (requires chromium or google chrome)", 108 }, 109 Time: "2020-03-11T15:45:53+00:00", 110 Type: "library", 111 NotificationURL: "https://packagist.org/downloads/", 112 Authors: []pkg.PhpComposerAuthors{ 113 { 114 Name: "Konstantin Kudryashov", 115 Email: "ever.zet@gmail.com", 116 Homepage: "http://everzet.com", 117 }, 118 }, 119 120 Description: "Browser controller/emulator abstraction for PHP", 121 Homepage: "http://mink.behat.org/", 122 Keywords: []string{ 123 "browser", 124 "testing", 125 "web", 126 }, 127 }, 128 }, 129 } 130 131 for _, fixture := range fixtures { 132 t.Run(fixture, func(t *testing.T) { 133 locations := file.NewLocationSet(file.NewLocation(fixture)) 134 for i := range expectedPkgs { 135 expectedPkgs[i].Locations = locations 136 locationLicenses := pkg.NewLicenseSet() 137 for _, license := range expectedPkgs[i].Licenses.ToSlice() { 138 license.Locations = locations 139 locationLicenses.Add(license) 140 } 141 expectedPkgs[i].Licenses = locationLicenses 142 } 143 pkgtest.TestFileParser(t, fixture, parseInstalledJSON, expectedPkgs, expectedRelationships) 144 }) 145 } 146 } 147 148 func Test_corruptInstalledJSON(t *testing.T) { 149 pkgtest.NewCatalogTester(). 150 FromFile(t, "test-fixtures/glob-paths/src/installed.json"). 151 WithError(). 152 TestParser(t, parseInstalledJSON) 153 }