Skip to content

Commit

Permalink
fix(fetcher/cwe): support all v4 series (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n authored Jul 8, 2024
1 parent db7e01a commit 4198383
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion fetcher/cwe/cwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"encoding/xml"
"fmt"
"strings"

"github.com/inconshreveable/log15"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -37,7 +38,8 @@ func parse(res []byte) (map[string][]string, error) {

cweIDtoCapecIDs := map[string][]string{}
for _, file := range reader.File {
if file.Name != "cwec_v4.6.xml" {
if !strings.HasPrefix(file.Name, "cwec_v4") {
log15.Warn("Skip CWE parsing since only CWE v4 is supported", "file", file.Name)
continue
}

Expand Down
12 changes: 11 additions & 1 deletion fetcher/cwe/cwe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ func TestParse(t *testing.T) {
expected map[string][]string
}{
{
in: "testdata/cwec.xml.zip",
in: "testdata/v4.6/cwec.xml.zip",
expected: map[string][]string{
"CWE-1021": {"CAPEC-103", "CAPEC-181", "CAPEC-222", "CAPEC-504", "CAPEC-506", "CAPEC-654"},
},
},
{
in: "testdata/v4.14/cwec_latest.xml.zip",
expected: map[string][]string{
"CWE-1021": {"CAPEC-103", "CAPEC-181", "CAPEC-222", "CAPEC-504", "CAPEC-506", "CAPEC-587", "CAPEC-654"},
},
},
{
in: "testdata/v5.0/cwec_latest.xml.zip",
expected: map[string][]string{},
},
}

for i, tt := range tests {
Expand Down
Binary file added fetcher/cwe/testdata/v4.14/cwec_latest.xml.zip
Binary file not shown.
File renamed without changes.
Binary file added fetcher/cwe/testdata/v5.0/cwec_latest.xml.zip
Binary file not shown.

0 comments on commit 4198383

Please sign in to comment.