Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pkg/process/processors/github_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package processors

import (
"io"
"strings"

"github.com/anchore/grype-db/internal/log"
"github.com/anchore/grype-db/pkg/data"
Expand Down Expand Up @@ -65,15 +64,15 @@ func (p githubProcessor) Process(reader io.Reader, state provider.State) ([]data
}

func (p githubProcessor) IsSupported(schemaURL string) bool {
matchesSchemaType := strings.Contains(schemaURL, "https://raw.githubusercontent.com/anchore/vunnel/main/schema/vulnerability/github-security-advisory/schema-")
if !matchesSchemaType {
if !hasSchemaSegment(schemaURL, "github-security-advisory") {
return false
}

if !strings.HasSuffix(schemaURL, "schema-1.0.0.json") && !strings.HasSuffix(schemaURL, "schema-1.0.1.json") {
log.WithFields("schema", schemaURL).Trace("unsupported GHSA schema version")
parsedVersion, err := parseVersion(schemaURL)
if err != nil {
log.WithFields("schema", schemaURL, "error", err).Error("failed to parse GHSA schema version")
return false
}

return true
return parsedVersion.Major == 1
}
42 changes: 42 additions & 0 deletions pkg/process/processors/github_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ func TestGitHubProcessor_Process(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, entries, 3)
}

func TestGithubProcessor_IsSupported(t *testing.T) {
tc := []struct {
name string
schemaURL string
expected bool
}{
{
name: "valid schema URL with version 1.0.0",
schemaURL: "https://example.com/vunnel/path/vulnerability/github-security-advisory/schema-1.0.0.json",
expected: true,
},
{
name: "valid schema URL with version 1.2.3",
schemaURL: "https://example.com/vunnel/path/vulnerability/github-security-advisory/schema-1.2.3.json",
expected: true,
},
{
name: "invalid schema URL with unsupported version",
schemaURL: "https://example.com/vunnel/path/vulnerability/github-security-advisory/schema-2.0.0.json",
expected: false,
},
{
name: "invalid schema URL with missing version",
schemaURL: "https://example.com/vunnel/path/vulnerability/github-security-advisory/schema.json",
expected: false,
},
{
name: "completely invalid URL",
schemaURL: "https://example.com/invalid/schema/url",
expected: false,
},
}

p := githubProcessor{}

for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, p.IsSupported(tt.schemaURL))
})
}
}
11 changes: 5 additions & 6 deletions pkg/process/processors/match_exclusion_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package processors

import (
"io"
"strings"

"github.com/anchore/grype-db/internal/log"
"github.com/anchore/grype-db/pkg/data"
Expand Down Expand Up @@ -47,15 +46,15 @@ func (p matchExclusionProcessor) Process(reader io.Reader, _ provider.State) ([]
}

func (p matchExclusionProcessor) IsSupported(schemaURL string) bool {
matchesSchemaType := strings.Contains(schemaURL, "https://raw.githubusercontent.com/anchore/vunnel/main/schema/match-exclusion/schema-")
if !matchesSchemaType {
if !hasSchemaSegment(schemaURL, "match-exclusion") {
return false
}

if !strings.HasSuffix(schemaURL, "schema-1.0.0.json") {
log.WithFields("schema", schemaURL).Trace("unsupported match-exclusion schema version")
parsedVersion, err := parseVersion(schemaURL)
if err != nil {
log.WithFields("schema", schemaURL, "error", err).Error("failed to parse match-exclusion schema version")
return false
}

return true
return parsedVersion.Major == 1
}
42 changes: 42 additions & 0 deletions pkg/process/processors/match_exclusion_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ func TestMatchExclusionProcessor_Process(t *testing.T) {
require.NoError(t, err)
assert.Len(t, entries, 3)
}

func TestMatchExclusionProcessor_IsSupported(t *testing.T) {
tc := []struct {
name string
schemaURL string
expected bool
}{
{
name: "valid schema URL with version 1.0.0",
schemaURL: "https://example.com/vunnel/path/match-exclusion/schema-1.0.0.json",
expected: true,
},
{
name: "valid schema URL with version 1.3.4",
schemaURL: "https://example.com/vunnel/path/match-exclusion/schema-1.3.4.json",
expected: true,
},
{
name: "invalid schema URL with unsupported version",
schemaURL: "https://example.com/vunnel/path/match-exclusion/schema-2.0.0.json",
expected: false,
},
{
name: "invalid schema URL with missing version",
schemaURL: "https://example.com/vunnel/path/match-exclusion/schema.json",
expected: false,
},
{
name: "completely invalid URL",
schemaURL: "https://example.com/invalid/schema/url",
expected: false,
},
}

p := matchExclusionProcessor{}

for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, p.IsSupported(tt.schemaURL))
})
}
}
13 changes: 6 additions & 7 deletions pkg/process/processors/msrc_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package processors

import (
"io"
"strings"

"github.com/anchore/grype-db/internal/log"
"github.com/anchore/grype-db/pkg/data"
Expand All @@ -22,7 +21,7 @@ func NewMSRCProcessor(transformer data.MSRCTransformer) data.Processor {
}
}

// Parse reads all entries in all metadata matching the supported schema and produces vulnerabilities and their corresponding metadata
// Process reads all entries in all metadata matching the supported schema and produces vulnerabilities and their corresponding metadata
func (p msrcProcessor) Process(reader io.Reader, _ provider.State) ([]data.Entry, error) {
var results []data.Entry

Expand All @@ -49,15 +48,15 @@ func (p msrcProcessor) Process(reader io.Reader, _ provider.State) ([]data.Entry
}

func (p msrcProcessor) IsSupported(schemaURL string) bool {
matchesSchemaType := strings.Contains(schemaURL, "https://raw.githubusercontent.com/anchore/vunnel/main/schema/vulnerability/msrc/schema-")
if !matchesSchemaType {
if !hasSchemaSegment(schemaURL, "msrc") {
return false
}

if !strings.HasSuffix(schemaURL, "schema-1.0.0.json") {
log.WithFields("schema", schemaURL).Trace("unsupported MSRC schema version")
parsedVersion, err := parseVersion(schemaURL)
if err != nil {
log.WithFields("schema", schemaURL, "error", err).Error("failed to parse MSRC schema version")
return false
}

return true
return parsedVersion.Major == 1
}
42 changes: 42 additions & 0 deletions pkg/process/processors/msrc_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ func TestMSRCProcessor_Process(t *testing.T) {
require.NoError(t, err)
assert.Len(t, entries, 2)
}

func TestMsrcProcessor_IsSupported(t *testing.T) {
tc := []struct {
name string
schemaURL string
expected bool
}{
{
name: "valid schema URL with version 1.0.0",
schemaURL: "https://example.com/vunnel/path/vulnerability/msrc/schema-1.0.0.json",
expected: true,
},
{
name: "valid schema URL with version 1.2.3",
schemaURL: "https://example.com/vunnel/path/vulnerability/msrc/schema-1.2.3.json",
expected: true,
},
{
name: "invalid schema URL with unsupported version",
schemaURL: "https://example.com/vunnel/path/vulnerability/msrc/schema-2.0.0.json",
expected: false,
},
{
name: "invalid schema URL with missing version",
schemaURL: "https://example.com/vunnel/path/vulnerability/msrc/schema.json",
expected: false,
},
{
name: "completely invalid URL",
schemaURL: "https://example.com/invalid/schema/url",
expected: false,
},
}

p := msrcProcessor{}

for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, p.IsSupported(tt.schemaURL))
})
}
}
11 changes: 5 additions & 6 deletions pkg/process/processors/nvd_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package processors

import (
"io"
"strings"

"github.com/anchore/grype-db/internal/log"
"github.com/anchore/grype-db/pkg/data"
Expand Down Expand Up @@ -64,15 +63,15 @@ func (p nvdProcessor) Process(reader io.Reader, state provider.State) ([]data.En
}

func (p nvdProcessor) IsSupported(schemaURL string) bool {
matchesSchemaType := strings.Contains(schemaURL, "https://raw.githubusercontent.com/anchore/vunnel/main/schema/vulnerability/nvd/schema-")
if !matchesSchemaType {
if !hasSchemaSegment(schemaURL, "nvd") {
return false
}

if !strings.HasSuffix(schemaURL, "schema-1.0.0.json") {
log.WithFields("schema", schemaURL).Trace("unsupported NVD schema version")
parsedVersion, err := parseVersion(schemaURL)
if err != nil {
log.WithFields("schema", schemaURL, "error", err).Error("failed to parse NVD schema version")
return false
}

return true
return parsedVersion.Major == 1
}
42 changes: 42 additions & 0 deletions pkg/process/processors/nvd_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ func TestNVDProcessor_Process(t *testing.T) {
require.NoError(t, err)
assert.Len(t, entries, 3)
}

func TestNvdProcessor_IsSupported(t *testing.T) {
tc := []struct {
name string
schemaURL string
expected bool
}{
{
name: "valid schema URL with version 1.0.0",
schemaURL: "https://example.com/vunnel/path/vulnerability/nvd/schema-1.0.0.json",
expected: true,
},
{
name: "valid schema URL with version 1.4.7",
schemaURL: "https://example.com/vunnel/path/vulnerability/nvd/schema-1.4.7.json",
expected: true,
},
{
name: "invalid schema URL with unsupported version",
schemaURL: "https://example.com/vunnel/path/vulnerability/nvd/schema-2.0.0.json",
expected: false,
},
{
name: "invalid schema URL with missing version",
schemaURL: "https://example.com/vunnel/path/vulnerability/nvd/schema.json",
expected: false,
},
{
name: "completely invalid URL",
schemaURL: "https://example.com/invalid/schema/url",
expected: false,
},
}

p := nvdProcessor{}

for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, p.IsSupported(tt.schemaURL))
})
}
}
11 changes: 5 additions & 6 deletions pkg/process/processors/os_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package processors

import (
"io"
"strings"

"github.com/anchore/grype-db/internal/log"
"github.com/anchore/grype-db/pkg/data"
Expand Down Expand Up @@ -65,15 +64,15 @@ func (p osProcessor) Process(reader io.Reader, state provider.State) ([]data.Ent
}

func (p osProcessor) IsSupported(schemaURL string) bool {
matchesSchemaType := strings.Contains(schemaURL, "https://raw.githubusercontent.com/anchore/vunnel/main/schema/vulnerability/os/schema-")
if !matchesSchemaType {
if !hasSchemaSegment(schemaURL, "os") {
return false
}

if !strings.HasSuffix(schemaURL, "schema-1.0.0.json") {
log.WithFields("schema", schemaURL).Trace("unsupported OS schema version")
parsedVersion, err := parseVersion(schemaURL)
if err != nil {
log.WithFields("schema", schemaURL, "error", err).Error("failed to parse OS schema version")
return false
}

return true
return parsedVersion.Major == 1
}
42 changes: 42 additions & 0 deletions pkg/process/processors/os_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ func TestOSProcessor_Process(t *testing.T) {
require.NoError(t, err)
assert.Len(t, entries, 4)
}

func TestOsProcessor_IsSupported(t *testing.T) {
tc := []struct {
name string
schemaURL string
expected bool
}{
{
name: "valid schema URL with version 1.0.0",
schemaURL: "https://example.com/vunnel/path/vulnerability/os/schema-1.0.0.json",
expected: true,
},
{
name: "valid schema URL with version 1.5.2",
schemaURL: "https://example.com/vunnel/path/vulnerability/os/schema-1.5.2.json",
expected: true,
},
{
name: "invalid schema URL with unsupported version",
schemaURL: "https://example.com/vunnel/path/vulnerability/os/schema-2.0.0.json",
expected: false,
},
{
name: "invalid schema URL with missing version",
schemaURL: "https://example.com/vunnel/path/vulnerability/os/schema.json",
expected: false,
},
{
name: "completely invalid URL",
schemaURL: "https://example.com/invalid/schema/url",
expected: false,
},
}

p := osProcessor{}

for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, p.IsSupported(tt.schemaURL))
})
}
}
Loading