github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/php/parse_installed_json_test.go (about)

     1  package php
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/anchore/syft/syft/artifact"
     7  	"github.com/anchore/syft/syft/file"
     8  	"github.com/anchore/syft/syft/pkg"
     9  	"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
    10  )
    11  
    12  func TestParseInstalledJsonComposerV1(t *testing.T) {
    13  	fixtures := []string{
    14  		"test-fixtures/vendor/composer_1/installed.json",
    15  		"test-fixtures/vendor/composer_2/installed.json",
    16  	}
    17  
    18  	var expectedRelationships []artifact.Relationship
    19  	var expectedPkgs = []pkg.Package{
    20  		{
    21  			Name:         "asm89/stack-cors",
    22  			Version:      "1.3.0",
    23  			PURL:         "pkg:composer/asm89/stack-cors@1.3.0",
    24  			Language:     pkg.PHP,
    25  			Type:         pkg.PhpComposerPkg,
    26  			MetadataType: pkg.PhpComposerJSONMetadataType,
    27  			Licenses: pkg.NewLicenseSet(
    28  				pkg.NewLicense("MIT"),
    29  			),
    30  			Metadata: pkg.PhpComposerJSONMetadata{
    31  				Name:    "asm89/stack-cors",
    32  				Version: "1.3.0",
    33  				Source: pkg.PhpComposerExternalReference{
    34  					Type:      "git",
    35  					URL:       "https://github.com/asm89/stack-cors.git",
    36  					Reference: "b9c31def6a83f84b4d4a40d35996d375755f0e08",
    37  				},
    38  				Dist: pkg.PhpComposerExternalReference{
    39  					Type:      "zip",
    40  					URL:       "https://api.github.com/repos/asm89/stack-cors/zipball/b9c31def6a83f84b4d4a40d35996d375755f0e08",
    41  					Reference: "b9c31def6a83f84b4d4a40d35996d375755f0e08",
    42  				},
    43  				Require: map[string]string{
    44  					"php":                     ">=5.5.9",
    45  					"symfony/http-foundation": "~2.7|~3.0|~4.0|~5.0",
    46  					"symfony/http-kernel":     "~2.7|~3.0|~4.0|~5.0",
    47  				},
    48  				RequireDev: map[string]string{
    49  					"phpunit/phpunit":           "^5.0 || ^4.8.10",
    50  					"squizlabs/php_codesniffer": "^2.3",
    51  				},
    52  				Time:            "2019-12-24T22:41:47+00:00",
    53  				Type:            "library",
    54  				NotificationURL: "https://packagist.org/downloads/",
    55  				Authors: []pkg.PhpComposerAuthors{
    56  					{
    57  						Name:  "Alexander",
    58  						Email: "iam.asm89@gmail.com",
    59  					},
    60  				},
    61  
    62  				Description: "Cross-origin resource sharing library and stack middleware",
    63  				Homepage:    "https://github.com/asm89/stack-cors",
    64  				Keywords: []string{
    65  					"cors",
    66  					"stack",
    67  				},
    68  			},
    69  		},
    70  		{
    71  			Name:     "behat/mink",
    72  			Version:  "v1.8.1",
    73  			PURL:     "pkg:composer/behat/mink@v1.8.1",
    74  			Language: pkg.PHP,
    75  			Type:     pkg.PhpComposerPkg,
    76  			Licenses: pkg.NewLicenseSet(
    77  				pkg.NewLicense("MIT"),
    78  			),
    79  			MetadataType: pkg.PhpComposerJSONMetadataType,
    80  			Metadata: pkg.PhpComposerJSONMetadata{
    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  }