github.com/khulnasoft-lab/tunnel-db@v0.0.0-20231117205118-74e1113bd007/pkg/vulnsrc/composer/composer_test.go (about) 1 package composer 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/khulnasoft-lab/tunnel-db/pkg/types" 8 "github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrc/vulnerability" 9 "github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrctest" 10 ) 11 12 func TestVulnSrc_Update(t *testing.T) { 13 tests := []struct { 14 name string 15 dir string 16 wantValues []vulnsrctest.WantValues 17 wantErr string 18 }{ 19 { 20 name: "happy path", 21 dir: filepath.Join("testdata", "happy"), 22 wantValues: []vulnsrctest.WantValues{ 23 { 24 Key: []string{"data-source", "composer::PHP Security Advisories Database"}, 25 Value: types.DataSource{ 26 ID: vulnerability.PhpSecurityAdvisories, 27 Name: "PHP Security Advisories Database", 28 URL: "https://github.com/FriendsOfPHP/security-advisories", 29 }, 30 }, 31 { 32 Key: []string{"advisory-detail", "CVE-2015-5723", "composer::PHP Security Advisories Database", "aws/aws-sdk-php"}, 33 Value: types.Advisory{ 34 VulnerableVersions: []string{"\u003e=3.0.0, \u003c3.2.1"}, 35 }, 36 }, 37 { 38 Key: []string{"vulnerability-detail", "CVE-2015-5723", "php-security-advisories"}, 39 Value: types.VulnerabilityDetail{ 40 ID: "CVE-2015-5723", 41 Title: "Security Misconfiguration Vulnerability in the AWS SDK for PHP", 42 References: []string{ 43 "https://github.com/aws/aws-sdk-php/releases/tag/3.2.1", 44 }, 45 }, 46 }, 47 { 48 Key: []string{"vulnerability-id", "CVE-2015-5723"}, 49 Value: map[string]interface{}{}, 50 }, 51 }, 52 }, 53 { 54 name: "sad path (dir doesn't exist)", 55 dir: filepath.Join("testdata", "badPath"), 56 wantErr: "no such file or directory", 57 }, 58 { 59 name: "sad path (failed to decode)", 60 dir: filepath.Join("testdata", "sad"), 61 wantErr: "failed to unmarshal YAML", 62 }, 63 } 64 for _, tt := range tests { 65 t.Run(tt.name, func(t *testing.T) { 66 vs := NewVulnSrc() 67 vulnsrctest.TestUpdate(t, vs, vulnsrctest.TestUpdateArgs{ 68 Dir: tt.dir, 69 WantValues: tt.wantValues, 70 WantErr: tt.wantErr, 71 }) 72 }) 73 } 74 }