mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
fix: strip publisher URL from RPM CPE vendor (#5081)
Signed-off-by: Eljees <yurytumanov.r@yandex.ru>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package cpegenerate
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
)
|
||||
|
||||
func TestCandidateVendorsForRPM(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
metadata any
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "database vendor with publisher URL",
|
||||
metadata: pkg.RpmDBEntry{
|
||||
Vendor: "SUSE LLC <https://www.suse.com/>",
|
||||
},
|
||||
expected: []string{"susellc"},
|
||||
},
|
||||
{
|
||||
name: "archive vendor with publisher URL",
|
||||
metadata: pkg.RpmArchive{
|
||||
Vendor: "SUSE LLC <https://www.suse.com/>",
|
||||
},
|
||||
expected: []string{"susellc"},
|
||||
},
|
||||
{
|
||||
name: "plain vendor",
|
||||
metadata: pkg.RpmDBEntry{
|
||||
Vendor: "Red Hat, Inc.",
|
||||
},
|
||||
expected: []string{"redhat"},
|
||||
},
|
||||
{
|
||||
name: "non-URL angle-bracket suffix",
|
||||
metadata: pkg.RpmDBEntry{
|
||||
Vendor: "Example <support@example.com>",
|
||||
},
|
||||
expected: []string{"example<support@example.com>"},
|
||||
},
|
||||
{
|
||||
name: "non-HTTP URL",
|
||||
metadata: pkg.RpmDBEntry{
|
||||
Vendor: "Example <ftp://example.com>",
|
||||
},
|
||||
expected: []string{"example<ftp://example.com>"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
p := pkg.Package{Metadata: test.metadata}
|
||||
assert.ElementsMatch(t, test.expected, candidateVendorsForRPM(p).uniqueValues())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user