github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/php/parse_composer_lock_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 TestParseComposerFileLock(t *testing.T) {
    14  	ctx := context.Background()
    15  	var expectedRelationships []artifact.Relationship
    16  	fixture := "test-fixtures/composer.lock"
    17  	locations := file.NewLocationSet(file.NewLocation(fixture))
    18  	expectedPkgs := []pkg.Package{
    19  		{
    20  			Name:      "adoy/fastcgi-client",
    21  			Version:   "1.0.2",
    22  			PURL:      "pkg:composer/adoy/fastcgi-client@1.0.2",
    23  			Locations: locations,
    24  			Licenses: pkg.NewLicenseSet(
    25  				pkg.NewLicenseFromLocationsWithContext(ctx, "MIT", file.NewLocation(fixture)),
    26  			),
    27  			Language: pkg.PHP,
    28  			Type:     pkg.PhpComposerPkg,
    29  			Metadata: pkg.PhpComposerLockEntry{
    30  				Name:    "adoy/fastcgi-client",
    31  				Version: "1.0.2",
    32  				Source: pkg.PhpComposerExternalReference{
    33  					Type:      "git",
    34  					URL:       "https://github.com/adoy/PHP-FastCGI-Client.git",
    35  					Reference: "6d9a552f0206a1db7feb442824540aa6c55e5b27",
    36  				},
    37  				Dist: pkg.PhpComposerExternalReference{
    38  					Type:      "zip",
    39  					URL:       "https://api.github.com/repos/adoy/PHP-FastCGI-Client/zipball/6d9a552f0206a1db7feb442824540aa6c55e5b27",
    40  					Reference: "6d9a552f0206a1db7feb442824540aa6c55e5b27",
    41  				},
    42  				Type:            "library",
    43  				NotificationURL: "https://packagist.org/downloads/",
    44  				Authors: []pkg.PhpComposerAuthors{
    45  					{
    46  						Name:  "Pierrick Charron",
    47  						Email: "pierrick@adoy.net",
    48  					},
    49  				},
    50  				Description: "Lightweight, single file FastCGI client for PHP.",
    51  				Keywords: []string{
    52  					"fastcgi",
    53  					"fcgi",
    54  				},
    55  				Time: "2019-12-11T13:49:21+00:00",
    56  			},
    57  		},
    58  		{
    59  			Name:      "alcaeus/mongo-php-adapter",
    60  			Version:   "1.1.11",
    61  			Locations: locations,
    62  			PURL:      "pkg:composer/alcaeus/mongo-php-adapter@1.1.11",
    63  			Language:  pkg.PHP,
    64  			Licenses: pkg.NewLicenseSet(
    65  				pkg.NewLicenseFromLocationsWithContext(ctx, "MIT", file.NewLocation(fixture)),
    66  			),
    67  			Type: pkg.PhpComposerPkg,
    68  			Metadata: pkg.PhpComposerLockEntry{
    69  				Name:    "alcaeus/mongo-php-adapter",
    70  				Version: "1.1.11",
    71  				Source: pkg.PhpComposerExternalReference{
    72  					Type:      "git",
    73  					URL:       "https://github.com/alcaeus/mongo-php-adapter.git",
    74  					Reference: "43b6add94c8b4cb9890d662cba4c0defde733dcf",
    75  				},
    76  				Dist: pkg.PhpComposerExternalReference{
    77  					Type:      "zip",
    78  					URL:       "https://api.github.com/repos/alcaeus/mongo-php-adapter/zipball/43b6add94c8b4cb9890d662cba4c0defde733dcf",
    79  					Reference: "43b6add94c8b4cb9890d662cba4c0defde733dcf",
    80  				},
    81  				Require: map[string]string{
    82  					"ext-ctype":       "*",
    83  					"ext-hash":        "*",
    84  					"ext-mongodb":     "^1.2.0",
    85  					"mongodb/mongodb": "^1.0.1",
    86  					"php":             "^5.6 || ^7.0",
    87  				},
    88  				Provide: map[string]string{
    89  					"ext-mongo": "1.6.14",
    90  				},
    91  				RequireDev: map[string]string{
    92  					"phpunit/phpunit":           "^5.7.27 || ^6.0 || ^7.0",
    93  					"squizlabs/php_codesniffer": "^3.2",
    94  				},
    95  				Type:            "library",
    96  				NotificationURL: "https://packagist.org/downloads/",
    97  				Authors: []pkg.PhpComposerAuthors{
    98  					{
    99  						Name:  "alcaeus",
   100  						Email: "alcaeus@alcaeus.org",
   101  					},
   102  					{
   103  						Name:  "Olivier Lechevalier",
   104  						Email: "olivier.lechevalier@gmail.com",
   105  					},
   106  				},
   107  				Description: "Adapter to provide ext-mongo interface on top of mongo-php-libary",
   108  				Keywords: []string{
   109  					"database",
   110  					"mongodb",
   111  				},
   112  				Time: "2019-11-11T20:47:32+00:00",
   113  			},
   114  		},
   115  	}
   116  	pkgtest.TestFileParser(t, fixture, parseComposerLock, expectedPkgs, expectedRelationships)
   117  }
   118  
   119  func Test_corruptComposerLock(t *testing.T) {
   120  	pkgtest.NewCatalogTester().
   121  		FromFile(t, "test-fixtures/glob-paths/src/composer.lock").
   122  		WithError().
   123  		TestParser(t, parseComposerLock)
   124  }