github.com/khulnasoft-lab/tunnel-db@v0.0.0-20231117205118-74e1113bd007/pkg/vulnsrc/glad/glad_test.go (about) 1 package glad_test 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/glad" 9 "github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrc/vulnerability" 10 "github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrctest" 11 ) 12 13 func TestVulnSrc_Update(t *testing.T) { 14 tests := []struct { 15 name string 16 dir string 17 wantValues []vulnsrctest.WantValues 18 wantErr string 19 }{ 20 { 21 name: "happy path", 22 dir: filepath.Join("testdata", "happy"), 23 wantValues: []vulnsrctest.WantValues{ 24 { 25 Key: []string{"data-source", "conan::GitLab Advisory Database Community"}, 26 Value: types.DataSource{ 27 ID: vulnerability.GLAD, 28 Name: "GitLab Advisory Database Community", 29 URL: "https://gitlab.com/gitlab-org/advisories-community", 30 }, 31 }, 32 { 33 Key: []string{"advisory-detail", "CVE-2020-13574", "conan::GitLab Advisory Database Community", "gsoap"}, 34 Value: types.Advisory{ 35 VulnerableVersions: []string{"=2.8.107"}, 36 }, 37 }, 38 { 39 Key: []string{"vulnerability-detail", "CVE-2020-13574", "glad"}, 40 Value: types.VulnerabilityDetail{ 41 ID: "CVE-2020-13574", 42 Title: "NULL Pointer Dereference", 43 Description: "A denial-of-service vulnerability exists in the WS-Security plugin functionality of Genivia gSOAP. A specially crafted SOAP request can lead to denial of service. An attacker can send an HTTP request to trigger this vulnerability.", 44 References: []string{"https://nvd.nist.gov/vuln/detail/CVE-2020-13574"}, 45 }, 46 }, 47 }, 48 }, 49 { 50 name: "sad path", 51 dir: filepath.Join("testdata", "sad"), 52 wantErr: "failed to decode GLAD", 53 }, 54 } 55 for _, tt := range tests { 56 t.Run(tt.name, func(t *testing.T) { 57 vs := glad.NewVulnSrc() 58 vulnsrctest.TestUpdate(t, vs, vulnsrctest.TestUpdateArgs{ 59 Dir: tt.dir, 60 WantValues: tt.wantValues, 61 WantErr: tt.wantErr, 62 }) 63 }) 64 } 65 }