versionfmt: convert to using constant over literal

This commit is contained in:
Jimmy Zelinskie 2017-01-03 16:00:20 -05:00
parent ebd0170f5b
commit 8d29bf860d
28 changed files with 142 additions and 169 deletions

View File

@ -27,11 +27,9 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
// dpkg versioning is used to parse test packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
const ( const (
@ -51,7 +49,7 @@ func TestRaceAffects(t *testing.T) {
feature := database.Feature{ feature := database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestRaceAffectsFeatureNamespace1", Name: "TestRaceAffectsFeatureNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestRaceAffecturesFeature1", Name: "TestRaceAffecturesFeature1",
} }

View File

@ -16,7 +16,6 @@ package pgsql
import ( import (
"database/sql" "database/sql"
"fmt"
"strings" "strings"
"time" "time"
@ -66,7 +65,6 @@ func (pgSQL *pgSQL) insertFeature(feature database.Feature) (int, error) {
func (pgSQL *pgSQL) insertFeatureVersion(fv database.FeatureVersion) (id int, err error) { func (pgSQL *pgSQL) insertFeatureVersion(fv database.FeatureVersion) (id int, err error) {
err = versionfmt.Valid(fv.Feature.Namespace.VersionFormat, fv.Version) err = versionfmt.Valid(fv.Feature.Namespace.VersionFormat, fv.Version)
if err != nil { if err != nil {
fmt.Println(err)
return 0, cerrors.NewBadRequestError("could not find/insert invalid FeatureVersion") return 0, cerrors.NewBadRequestError("could not find/insert invalid FeatureVersion")
} }
@ -205,7 +203,7 @@ func linkFeatureVersionToVulnerabilities(tx *sql.Tx, featureVersion database.Fea
// TODO(Quentin-M): LIMIT // TODO(Quentin-M): LIMIT
rows, err := tx.Query(searchVulnerabilityFixedInFeature, featureVersion.Feature.ID) rows, err := tx.Query(searchVulnerabilityFixedInFeature, featureVersion.Feature.ID)
if err != nil { if err != nil {
return handleError("searchVulnerabilityFixedInFeature", err) return err
} }
defer rows.Close() defer rows.Close()

View File

@ -20,9 +20,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
// dpkg versioning is used to parse test packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
func TestInsertFeature(t *testing.T) { func TestInsertFeature(t *testing.T) {
@ -49,7 +47,7 @@ func TestInsertFeature(t *testing.T) {
feature := database.Feature{ feature := database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertFeatureNamespace1", Name: "TestInsertFeatureNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertFeature1", Name: "TestInsertFeature1",
} }
@ -76,7 +74,7 @@ func TestInsertFeature(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertFeatureNamespace2", Name: "TestInsertFeatureNamespace2",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertFeature2", Name: "TestInsertFeature2",
}, },
@ -86,7 +84,7 @@ func TestInsertFeature(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertFeatureNamespace2", Name: "TestInsertFeatureNamespace2",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertFeature2", Name: "TestInsertFeature2",
}, },
@ -103,7 +101,7 @@ func TestInsertFeature(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertFeatureNamespace1", Name: "TestInsertFeatureNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertFeature1", Name: "TestInsertFeature1",
}, },

View File

@ -21,11 +21,9 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
// dpkg versioning is used to parse test packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
func TestFindLayer(t *testing.T) { func TestFindLayer(t *testing.T) {
@ -144,7 +142,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertLayerNamespace2", Name: "TestInsertLayerNamespace2",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertLayerFeature1", Name: "TestInsertLayerFeature1",
}, },
@ -154,7 +152,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertLayerNamespace2", Name: "TestInsertLayerNamespace2",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertLayerFeature2", Name: "TestInsertLayerFeature2",
}, },
@ -164,7 +162,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertLayerNamespace2", Name: "TestInsertLayerNamespace2",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertLayerFeature3", Name: "TestInsertLayerFeature3",
}, },
@ -174,7 +172,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertLayerNamespace3", Name: "TestInsertLayerNamespace3",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertLayerFeature2", Name: "TestInsertLayerFeature2",
}, },
@ -184,7 +182,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertLayerNamespace3", Name: "TestInsertLayerNamespace3",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertLayerFeature3", Name: "TestInsertLayerFeature3",
}, },
@ -194,7 +192,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertLayerNamespace3", Name: "TestInsertLayerNamespace3",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertLayerFeature4", Name: "TestInsertLayerFeature4",
}, },
@ -210,7 +208,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Parent: &database.Layer{Name: "TestInsertLayer1"}, Parent: &database.Layer{Name: "TestInsertLayer1"},
Namespace: &database.Namespace{ Namespace: &database.Namespace{
Name: "TestInsertLayerNamespace1", Name: "TestInsertLayerNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
}, },
// This layer changes the namespace and adds Features. // This layer changes the namespace and adds Features.
@ -219,7 +217,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Parent: &database.Layer{Name: "TestInsertLayer2"}, Parent: &database.Layer{Name: "TestInsertLayer2"},
Namespace: &database.Namespace{ Namespace: &database.Namespace{
Name: "TestInsertLayerNamespace2", Name: "TestInsertLayerNamespace2",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Features: []database.FeatureVersion{f1, f2, f3}, Features: []database.FeatureVersion{f1, f2, f3},
}, },
@ -237,7 +235,7 @@ func testInsertLayerTree(t *testing.T, datastore database.Datastore) {
Parent: &database.Layer{Name: "TestInsertLayer3"}, Parent: &database.Layer{Name: "TestInsertLayer3"},
Namespace: &database.Namespace{ Namespace: &database.Namespace{
Name: "TestInsertLayerNamespace3", Name: "TestInsertLayerNamespace3",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Features: []database.FeatureVersion{ Features: []database.FeatureVersion{
// Deletes TestInsertLayerFeature1. // Deletes TestInsertLayerFeature1.
@ -295,7 +293,7 @@ func testInsertLayerUpdate(t *testing.T, datastore database.Datastore) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestInsertLayerNamespace3", Name: "TestInsertLayerNamespace3",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Name: "TestInsertLayerFeature7", Name: "TestInsertLayerFeature7",
}, },
@ -308,7 +306,7 @@ func testInsertLayerUpdate(t *testing.T, datastore database.Datastore) {
Parent: l3.Parent, Parent: l3.Parent,
Namespace: &database.Namespace{ Namespace: &database.Namespace{
Name: "TestInsertLayerNamespaceUpdated1", Name: "TestInsertLayerNamespaceUpdated1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Features: []database.FeatureVersion{f7}, Features: []database.FeatureVersion{f7},
} }

View File

@ -21,9 +21,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
// dpkg versioning is used to parse test packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
func TestInsertNamespace(t *testing.T) { func TestInsertNamespace(t *testing.T) {
@ -42,12 +40,12 @@ func TestInsertNamespace(t *testing.T) {
// Insert Namespace and ensure we can find it. // Insert Namespace and ensure we can find it.
id1, err := datastore.insertNamespace(database.Namespace{ id1, err := datastore.insertNamespace(database.Namespace{
Name: "TestInsertNamespace1", Name: "TestInsertNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}) })
assert.Nil(t, err) assert.Nil(t, err)
id2, err := datastore.insertNamespace(database.Namespace{ id2, err := datastore.insertNamespace(database.Namespace{
Name: "TestInsertNamespace1", Name: "TestInsertNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}) })
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, id1, id2) assert.Equal(t, id1, id2)

View File

@ -22,11 +22,9 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
// dpkg versioning is used to parse test packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
func TestNotification(t *testing.T) { func TestNotification(t *testing.T) {
@ -46,7 +44,7 @@ func TestNotification(t *testing.T) {
Name: "TestNotificationFeature1", Name: "TestNotificationFeature1",
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestNotificationNamespace1", Name: "TestNotificationNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
} }
@ -54,7 +52,7 @@ func TestNotification(t *testing.T) {
Name: "TestNotificationFeature2", Name: "TestNotificationFeature2",
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "TestNotificationNamespace1", Name: "TestNotificationNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
} }

View File

@ -22,11 +22,9 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
// dpkg versioning is used to parse test packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
func TestFindVulnerability(t *testing.T) { func TestFindVulnerability(t *testing.T) {
@ -49,7 +47,7 @@ func TestFindVulnerability(t *testing.T) {
Severity: types.High, Severity: types.High,
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "debian:7", Name: "debian:7",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
FixedIn: []database.FeatureVersion{ FixedIn: []database.FeatureVersion{
{ {
@ -74,7 +72,7 @@ func TestFindVulnerability(t *testing.T) {
Description: "A vulnerability affecting nothing", Description: "A vulnerability affecting nothing",
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "debian:7", Name: "debian:7",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
}, },
Severity: types.Unknown, Severity: types.Unknown,
} }
@ -118,11 +116,11 @@ func TestInsertVulnerability(t *testing.T) {
// Create some data. // Create some data.
n1 := database.Namespace{ n1 := database.Namespace{
Name: "TestInsertVulnerabilityNamespace1", Name: "TestInsertVulnerabilityNamespace1",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
} }
n2 := database.Namespace{ n2 := database.Namespace{
Name: "TestInsertVulnerabilityNamespace2", Name: "TestInsertVulnerabilityNamespace2",
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
} }
f1 := database.FeatureVersion{ f1 := database.FeatureVersion{

View File

@ -23,6 +23,9 @@ import (
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
) )
// ParserName is the name by which the dpkg parser is registered.
const ParserName = "dpkg"
type version struct { type version struct {
epoch int epoch int
version string version string
@ -278,5 +281,5 @@ func signum(a int) int {
} }
func init() { func init() {
versionfmt.RegisterParser("dpkg", parser{}) versionfmt.RegisterParser(ParserName, parser{})
} }

View File

@ -27,7 +27,7 @@ const (
// MinVersion is a special package version which is always sorted first. // MinVersion is a special package version which is always sorted first.
MinVersion = "#MINV#" MinVersion = "#MINV#"
// MaxVersion is a special package version which is always sorted last // MaxVersion is a special package version which is always sorted last.
MaxVersion = "#MAXV#" MaxVersion = "#MAXV#"
) )

View File

@ -25,6 +25,9 @@ import (
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
) )
// ParserName is the name by which the rpm parser is registered.
const ParserName = "rpm"
var ( var (
// alphanumPattern is a regular expression to match all sequences of numeric // alphanumPattern is a regular expression to match all sequences of numeric
// characters or alphanumeric characters. // characters or alphanumeric characters.
@ -273,5 +276,5 @@ func containsRune(s []rune, e rune) bool {
} }
func init() { func init() {
versionfmt.RegisterParser("rpm", parser{}) versionfmt.RegisterParser(ParserName, parser{})
} }

View File

@ -86,74 +86,62 @@ func TestParseAndCompare(t *testing.T) {
expected int expected int
v2 string v2 string
}{ }{
// Oracle Linux corner cases.
{"2.9.1-6.0.1.el7_2.3", GREATER, "2.9.1-6.el7_2.3"},
{"3.10.0-327.28.3.el7", GREATER, "3.10.0-327.el7"},
{"3.14.3-23.3.el6_8", GREATER, "3.14.3-23.el6_7"},
{"2.23.2-22.el7_1", LESS, "2.23.2-22.el7_1.1"},
// Tests imported from tests/rpmvercmp.at // Tests imported from tests/rpmvercmp.at
{"1.0", EQUAL, "1.0"}, {"1.0", EQUAL, "1.0"},
{"1.0", LESS, "2.0"}, {"1.0", LESS, "2.0"},
{"2.0", GREATER, "1.0"}, {"2.0", GREATER, "1.0"},
{"2.0.1", EQUAL, "2.0.1"}, {"2.0.1", EQUAL, "2.0.1"},
{"2.0", LESS, "2.0.1"}, {"2.0", LESS, "2.0.1"},
{"2.0.1", GREATER, "2.0"}, {"2.0.1", GREATER, "2.0"},
{"2.0.1a", EQUAL, "2.0.1a"}, {"2.0.1a", EQUAL, "2.0.1a"},
{"2.0.1a", GREATER, "2.0.1"}, {"2.0.1a", GREATER, "2.0.1"},
{"2.0.1", LESS, "2.0.1a"}, {"2.0.1", LESS, "2.0.1a"},
{"5.5p1", EQUAL, "5.5p1"}, {"5.5p1", EQUAL, "5.5p1"},
{"5.5p1", LESS, "5.5p2"}, {"5.5p1", LESS, "5.5p2"},
{"5.5p2", GREATER, "5.5p1"}, {"5.5p2", GREATER, "5.5p1"},
{"5.5p10", EQUAL, "5.5p10"}, {"5.5p10", EQUAL, "5.5p10"},
{"5.5p1", LESS, "5.5p10"}, {"5.5p1", LESS, "5.5p10"},
{"5.5p10", GREATER, "5.5p1"}, {"5.5p10", GREATER, "5.5p1"},
{"10xyz", LESS, "10.1xyz"}, {"10xyz", LESS, "10.1xyz"},
{"10.1xyz", GREATER, "10xyz"}, {"10.1xyz", GREATER, "10xyz"},
{"xyz10", EQUAL, "xyz10"}, {"xyz10", EQUAL, "xyz10"},
{"xyz10", LESS, "xyz10.1"}, {"xyz10", LESS, "xyz10.1"},
{"xyz10.1", GREATER, "xyz10"}, {"xyz10.1", GREATER, "xyz10"},
{"xyz.4", EQUAL, "xyz.4"}, {"xyz.4", EQUAL, "xyz.4"},
{"xyz.4", LESS, "8"}, {"xyz.4", LESS, "8"},
{"8", GREATER, "xyz.4"}, {"8", GREATER, "xyz.4"},
{"xyz.4", LESS, "2"}, {"xyz.4", LESS, "2"},
{"2", GREATER, "xyz.4"}, {"2", GREATER, "xyz.4"},
{"5.5p2", LESS, "5.6p1"}, {"5.5p2", LESS, "5.6p1"},
{"5.6p1", GREATER, "5.5p2"}, {"5.6p1", GREATER, "5.5p2"},
{"5.6p1", LESS, "6.5p1"}, {"5.6p1", LESS, "6.5p1"},
{"6.5p1", GREATER, "5.6p1"}, {"6.5p1", GREATER, "5.6p1"},
{"6.0.rc1", GREATER, "6.0"}, {"6.0.rc1", GREATER, "6.0"},
{"6.0", LESS, "6.0.rc1"}, {"6.0", LESS, "6.0.rc1"},
{"10b2", GREATER, "10a1"}, {"10b2", GREATER, "10a1"},
{"10a2", LESS, "10b2"}, {"10a2", LESS, "10b2"},
{"1.0aa", EQUAL, "1.0aa"}, {"1.0aa", EQUAL, "1.0aa"},
{"1.0a", LESS, "1.0aa"}, {"1.0a", LESS, "1.0aa"},
{"1.0aa", GREATER, "1.0a"}, {"1.0aa", GREATER, "1.0a"},
{"10.0001", EQUAL, "10.0001"}, {"10.0001", EQUAL, "10.0001"},
{"10.0001", EQUAL, "10.1"}, {"10.0001", EQUAL, "10.1"},
{"10.1", EQUAL, "10.0001"}, {"10.1", EQUAL, "10.0001"},
{"10.0001", LESS, "10.0039"}, {"10.0001", LESS, "10.0039"},
{"10.0039", GREATER, "10.0001"}, {"10.0039", GREATER, "10.0001"},
{"4.999.9", LESS, "5.0"}, {"4.999.9", LESS, "5.0"},
{"5.0", GREATER, "4.999.9"}, {"5.0", GREATER, "4.999.9"},
{"20101121", EQUAL, "20101121"}, {"20101121", EQUAL, "20101121"},
{"20101121", LESS, "20101122"}, {"20101121", LESS, "20101122"},
{"20101122", GREATER, "20101121"}, {"20101122", GREATER, "20101121"},
{"2_0", EQUAL, "2_0"}, {"2_0", EQUAL, "2_0"},
{"2.0", EQUAL, "2_0"}, {"2.0", EQUAL, "2_0"},
{"2_0", EQUAL, "2.0"}, {"2_0", EQUAL, "2.0"},
// RhBug:178798 case
{"a", EQUAL, "a"}, {"a", EQUAL, "a"},
{"a+", EQUAL, "a+"}, {"a+", EQUAL, "a+"},
{"a+", EQUAL, "a_"}, {"a+", EQUAL, "a_"},
@ -166,8 +154,6 @@ func TestParseAndCompare(t *testing.T) {
{"_+", EQUAL, "_+"}, {"_+", EQUAL, "_+"},
{"+", EQUAL, "_"}, {"+", EQUAL, "_"},
{"_", EQUAL, "+"}, {"_", EQUAL, "+"},
// Basic testcases for tilde sorting
{"1.0~rc1", EQUAL, "1.0~rc1"}, {"1.0~rc1", EQUAL, "1.0~rc1"},
{"1.0~rc1", LESS, "1.0"}, {"1.0~rc1", LESS, "1.0"},
{"1.0", GREATER, "1.0~rc1"}, {"1.0", GREATER, "1.0~rc1"},
@ -176,27 +162,6 @@ func TestParseAndCompare(t *testing.T) {
{"1.0~rc1~git123", EQUAL, "1.0~rc1~git123"}, {"1.0~rc1~git123", EQUAL, "1.0~rc1~git123"},
{"1.0~rc1~git123", LESS, "1.0~rc1"}, {"1.0~rc1~git123", LESS, "1.0~rc1"},
{"1.0~rc1", GREATER, "1.0~rc1~git123"}, {"1.0~rc1", GREATER, "1.0~rc1~git123"},
// These are included here to document current, arguably buggy behaviors
// for reference purposes and for easy checking against unintended
// behavior changes.
//
// AT_BANNER([RPM version comparison oddities])
// RhBug:811992 case
// {"1b.fc17", EQUAL, "1b.fc17"},
// {"1b.fc17", LESS, "1.fc17"},
// {"1.fc17", GREATER, "1b.fc17"},
// {"1g.fc17", EQUAL, "1g.fc17"},
// {"1g.fc17", GREATER, "1.fc17"},
// {"1.fc17", LESS, "1g.fc17"},
// Non-ascii characters are considered equal so these are all the same, eh...
// {"1.1.α", EQUAL, "1.1.α"},
// {"1.1.α", EQUAL, "1.1.β"},
// {"1.1.β", EQUAL, "1.1.α"},
// {"1.1.αα", EQUAL, "1.1.α"},
// {"1.1.α", EQUAL, "1.1.ββ"},
// {"1.1.ββ", EQUAL, "1.1.αα"},
} }
var ( var (

View File

@ -30,13 +30,11 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/updater" "github.com/coreos/clair/updater"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
// dpkg versioning is used to parse Alpine Linux packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
const ( const (
@ -223,7 +221,7 @@ func parse33YAML(r io.Reader) (vulns []database.Vulnerability, err error) {
for _, pack := range file.Packages { for _, pack := range file.Packages {
pkg := pack.Pkg pkg := pack.Pkg
for _, fix := range pkg.Fixes { for _, fix := range pkg.Fixes {
err = versionfmt.Valid("dpkg", pkg.Version) err = versionfmt.Valid(dpkg.ParserName, pkg.Version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", pkg.Version, err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", pkg.Version, err.Error())
continue continue
@ -236,7 +234,10 @@ func parse33YAML(r io.Reader) (vulns []database.Vulnerability, err error) {
FixedIn: []database.FeatureVersion{ FixedIn: []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "alpine:" + file.Distro}, Namespace: database.Namespace{
Name: "alpine:" + file.Distro,
VersionFormat: dpkg.ParserName,
},
Name: pkg.Name, Name: pkg.Name,
}, },
Version: pkg.Version, Version: pkg.Version,
@ -274,7 +275,7 @@ func parse34YAML(r io.Reader) (vulns []database.Vulnerability, err error) {
for _, pack := range file.Packages { for _, pack := range file.Packages {
pkg := pack.Pkg pkg := pack.Pkg
for version, vulnStrs := range pkg.Fixes { for version, vulnStrs := range pkg.Fixes {
err := versionfmt.Valid("dpkg", version) err := versionfmt.Valid(dpkg.ParserName, version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error())
continue continue
@ -288,7 +289,10 @@ func parse34YAML(r io.Reader) (vulns []database.Vulnerability, err error) {
vuln.FixedIn = []database.FeatureVersion{ vuln.FixedIn = []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "alpine:" + file.Distro}, Namespace: database.Namespace{
Name: "alpine:" + file.Distro,
VersionFormat: dpkg.ParserName,
},
Name: pkg.Name, Name: pkg.Name,
}, },
Version: version, Version: version,

View File

@ -27,12 +27,10 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/updater" "github.com/coreos/clair/updater"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
// dpkg versioning is used to parse Debian packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
const ( const (
@ -185,7 +183,7 @@ func parseDebianJSON(data *jsonData) (vulnerabilities []database.Vulnerability,
} else if releaseNode.Status == "resolved" { } else if releaseNode.Status == "resolved" {
// Resolved means that the vulnerability has been fixed in // Resolved means that the vulnerability has been fixed in
// "fixed_version" (if affected). // "fixed_version" (if affected).
err = versionfmt.Valid("dpkg", releaseNode.FixedVersion) err = versionfmt.Valid(dpkg.ParserName, releaseNode.FixedVersion)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", releaseNode.FixedVersion, err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", releaseNode.FixedVersion, err.Error())
continue continue
@ -199,6 +197,7 @@ func parseDebianJSON(data *jsonData) (vulnerabilities []database.Vulnerability,
Name: pkgName, Name: pkgName,
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "debian:" + database.DebianReleasesMapping[releaseName], Name: "debian:" + database.DebianReleasesMapping[releaseName],
VersionFormat: dpkg.ParserName,
}, },
}, },
Version: version, Version: version,

View File

@ -22,6 +22,7 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -42,15 +43,20 @@ func TestDebianParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{
Name: "debian:8",
VersionFormat: dpkg.ParserName,
},
Name: "aptdaemon", Name: "aptdaemon",
}, },
Version: versionfmt.MaxVersion, Version: versionfmt.MaxVersion,
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:unstable"}, Namespace: database.Namespace{
Name: "debian:unstable",
VersionFormat: dpkg.ParserName,
},
Name: "aptdaemon", Name: "aptdaemon",
}, },
Version: "1.1.1+bzr982-1", Version: "1.1.1+bzr982-1",
@ -68,21 +74,30 @@ func TestDebianParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{
Name: "debian:8",
VersionFormat: dpkg.ParserName,
},
Name: "aptdaemon", Name: "aptdaemon",
}, },
Version: "0.7.0", Version: "0.7.0",
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:unstable"}, Namespace: database.Namespace{
Name: "debian:unstable",
VersionFormat: dpkg.ParserName,
},
Name: "aptdaemon", Name: "aptdaemon",
}, },
Version: "0.7.0", Version: "0.7.0",
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{
Name: "debian:8",
VersionFormat: dpkg.ParserName,
},
Name: "asterisk", Name: "asterisk",
}, },
Version: "0.5.56", Version: "0.5.56",
@ -100,7 +115,10 @@ func TestDebianParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{
Name: "debian:8",
VersionFormat: dpkg.ParserName,
},
Name: "asterisk", Name: "asterisk",
}, },
Version: versionfmt.MinVersion, Version: versionfmt.MinVersion,

View File

@ -25,13 +25,11 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/updater" "github.com/coreos/clair/updater"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"
// rpm versioning is used to parse Oracle Linux packages.
_ "github.com/coreos/clair/ext/versionfmt/rpm"
) )
const ( const (
@ -286,7 +284,7 @@ func toFeatureVersions(criteria criteria) []database.FeatureVersion {
const prefixLen = len(" is earlier than ") const prefixLen = len(" is earlier than ")
featureVersion.Feature.Name = strings.TrimSpace(c.Comment[:strings.Index(c.Comment, " is earlier than ")]) featureVersion.Feature.Name = strings.TrimSpace(c.Comment[:strings.Index(c.Comment, " is earlier than ")])
version := c.Comment[strings.Index(c.Comment, " is earlier than ")+prefixLen:] version := c.Comment[strings.Index(c.Comment, " is earlier than ")+prefixLen:]
err := versionfmt.Valid("rpm", version) err := versionfmt.Valid(rpm.ParserName, version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error())
} else { } else {
@ -296,7 +294,7 @@ func toFeatureVersions(criteria criteria) []database.FeatureVersion {
} }
featureVersion.Feature.Namespace.Name = "oracle" + ":" + strconv.Itoa(osVersion) featureVersion.Feature.Namespace.Name = "oracle" + ":" + strconv.Itoa(osVersion)
featureVersion.Feature.Namespace.VersionFormat = "rpm" featureVersion.Feature.Namespace.VersionFormat = rpm.ParserName
if featureVersion.Feature.Namespace.Name != "" && featureVersion.Feature.Name != "" && featureVersion.Version != "" { if featureVersion.Feature.Namespace.Name != "" && featureVersion.Feature.Name != "" && featureVersion.Version != "" {
featureVersionParameters[featureVersion.Feature.Namespace.Name+":"+featureVersion.Feature.Name] = featureVersion featureVersionParameters[featureVersion.Feature.Namespace.Name+":"+featureVersion.Feature.Name] = featureVersion

View File

@ -21,11 +21,9 @@ import (
"testing" "testing"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
// rpm versioning is used to parse Oracle Linux packages.
_ "github.com/coreos/clair/ext/versionfmt/rpm"
) )
func TestOracleParser(t *testing.T) { func TestOracleParser(t *testing.T) {
@ -48,7 +46,7 @@ func TestOracleParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "oracle:7", Name: "oracle:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "xerces-c", Name: "xerces-c",
}, },
@ -58,7 +56,7 @@ func TestOracleParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "oracle:7", Name: "oracle:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "xerces-c-devel", Name: "xerces-c-devel",
}, },
@ -68,7 +66,7 @@ func TestOracleParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "oracle:7", Name: "oracle:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "xerces-c-doc", Name: "xerces-c-doc",
}, },
@ -95,7 +93,7 @@ func TestOracleParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "oracle:6", Name: "oracle:6",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "firefox", Name: "firefox",
}, },
@ -105,7 +103,7 @@ func TestOracleParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "oracle:7", Name: "oracle:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "firefox", Name: "firefox",
}, },

View File

@ -27,12 +27,10 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/updater" "github.com/coreos/clair/updater"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
// rpm versioning is used to parse Oracle Linux packages.
_ "github.com/coreos/clair/ext/versionfmt/rpm"
) )
const ( const (
@ -289,12 +287,12 @@ func toFeatureVersions(criteria criteria) []database.FeatureVersion {
const prefixLen = len(" is earlier than ") const prefixLen = len(" is earlier than ")
featureVersion.Feature.Name = strings.TrimSpace(c.Comment[:strings.Index(c.Comment, " is earlier than ")]) featureVersion.Feature.Name = strings.TrimSpace(c.Comment[:strings.Index(c.Comment, " is earlier than ")])
version := c.Comment[strings.Index(c.Comment, " is earlier than ")+prefixLen:] version := c.Comment[strings.Index(c.Comment, " is earlier than ")+prefixLen:]
err := versionfmt.Valid("rpm", version) err := versionfmt.Valid(rpm.ParserName, version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error())
} else { } else {
featureVersion.Version = version featureVersion.Version = version
featureVersion.Feature.Namespace.VersionFormat = "rpm" featureVersion.Feature.Namespace.VersionFormat = rpm.ParserName
} }
} }
} }

View File

@ -21,11 +21,9 @@ import (
"testing" "testing"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
// rpm versioning is used to parse RHEL packages.
_ "github.com/coreos/clair/ext/versionfmt/rpm"
) )
func TestRHELParser(t *testing.T) { func TestRHELParser(t *testing.T) {
@ -46,7 +44,7 @@ func TestRHELParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "centos:7", Name: "centos:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "xerces-c", Name: "xerces-c",
}, },
@ -56,7 +54,7 @@ func TestRHELParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "centos:7", Name: "centos:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "xerces-c-devel", Name: "xerces-c-devel",
}, },
@ -66,7 +64,7 @@ func TestRHELParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "centos:7", Name: "centos:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "xerces-c-doc", Name: "xerces-c-doc",
}, },
@ -93,7 +91,7 @@ func TestRHELParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "centos:6", Name: "centos:6",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "firefox", Name: "firefox",
}, },
@ -103,7 +101,7 @@ func TestRHELParser(t *testing.T) {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "centos:7", Name: "centos:7",
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
}, },
Name: "firefox", Name: "firefox",
}, },

View File

@ -30,6 +30,7 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/updater" "github.com/coreos/clair/updater"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
@ -350,7 +351,7 @@ func parseUbuntuCVE(fileContent io.Reader) (vulnerability database.Vulnerability
if md["status"] == "released" { if md["status"] == "released" {
if md["note"] != "" { if md["note"] != "" {
var err error var err error
err = versionfmt.Valid("dpkg", md["note"]) err = versionfmt.Valid(dpkg.ParserName, md["note"])
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", md["note"], err) log.Warningf("could not parse package version '%s': %s. skipping", md["note"], err)
} }

View File

@ -22,10 +22,8 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
// dpkg versioning is used to parse apk packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
var log = capnslog.NewPackageLogger("github.com/coreos/clair", "worker/detectors/packages") var log = capnslog.NewPackageLogger("github.com/coreos/clair", "worker/detectors/packages")
@ -60,7 +58,7 @@ func (d *detector) Detect(data map[string][]byte) ([]database.FeatureVersion, er
ipkg.Feature.Name = line[2:] ipkg.Feature.Name = line[2:]
case line[:2] == "V:": case line[:2] == "V:":
version := string(line[2:]) version := string(line[2:])
err := versionfmt.Valid("dpkg", version) err := versionfmt.Valid(dpkg.ParserName, version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", version, err.Error())
} else { } else {

View File

@ -23,10 +23,8 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
// dpkg versioning is used to parse dpkg packages.
_ "github.com/coreos/clair/ext/versionfmt/dpkg"
) )
var ( var (
@ -79,7 +77,7 @@ func (detector *DpkgFeaturesDetector) Detect(data map[string][]byte) ([]database
pkg.Feature.Name = md["name"] pkg.Feature.Name = md["name"]
if md["version"] != "" { if md["version"] != "" {
version := md["version"] version := md["version"]
err = versionfmt.Valid("dpkg", version) err = versionfmt.Valid(dpkg.ParserName, version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", string(line[1]), err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", string(line[1]), err.Error())
} else { } else {
@ -93,7 +91,7 @@ func (detector *DpkgFeaturesDetector) Detect(data map[string][]byte) ([]database
// because the Debian vulnerabilities often skips the epoch from the Version field // because the Debian vulnerabilities often skips the epoch from the Version field
// which is not present in the Source version, and because +bX revisions don't matter // which is not present in the Source version, and because +bX revisions don't matter
version := strings.TrimPrefix(line, "Version: ") version := strings.TrimPrefix(line, "Version: ")
err = versionfmt.Valid("dpkg", version) err = versionfmt.Valid(dpkg.ParserName, version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", string(line[1]), err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", string(line[1]), err.Error())
} else { } else {

View File

@ -24,12 +24,10 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
// rpm versioning is used to parse rpm packages.
_ "github.com/coreos/clair/ext/versionfmt/rpm"
) )
var log = capnslog.NewPackageLogger("github.com/coreos/clair", "rpm") var log = capnslog.NewPackageLogger("github.com/coreos/clair", "rpm")
@ -93,7 +91,7 @@ func (detector *RpmFeaturesDetector) Detect(data map[string][]byte) ([]database.
// Parse version // Parse version
version := strings.Replace(line[1], "(none):", "", -1) version := strings.Replace(line[1], "(none):", "", -1)
err := versionfmt.Valid("rpm", version) err := versionfmt.Valid(rpm.ParserName, version)
if err != nil { if err != nil {
log.Warningf("could not parse package version '%s': %s. skipping", line[1], err.Error()) log.Warningf("could not parse package version '%s': %s. skipping", line[1], err.Error())
continue continue

View File

@ -21,6 +21,7 @@ import (
"strings" "strings"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
) )
@ -50,7 +51,7 @@ func (d *detector) Detect(data map[string][]byte) *database.Namespace {
versionNumbers := strings.Split(match[0], ".") versionNumbers := strings.Split(match[0], ".")
return &database.Namespace{ return &database.Namespace{
Name: osName + ":" + "v" + versionNumbers[0] + "." + versionNumbers[1], Name: osName + ":" + "v" + versionNumbers[0] + "." + versionNumbers[1],
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
} }
} }
} }

View File

@ -19,6 +19,7 @@ import (
"strings" "strings"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
) )
@ -77,7 +78,7 @@ func (detector *AptSourcesNamespaceDetector) Detect(data map[string][]byte) *dat
if OS != "" && version != "" { if OS != "" && version != "" {
return &database.Namespace{ return &database.Namespace{
Name: OS + ":" + version, Name: OS + ":" + version,
VersionFormat: "dpkg", VersionFormat: dpkg.ParserName,
} }
} }
return nil return nil

View File

@ -20,6 +20,8 @@ import (
"strings" "strings"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
) )
@ -28,8 +30,8 @@ var (
lsbReleaseVersionRegexp = regexp.MustCompile(`^DISTRIB_RELEASE=(.*)`) lsbReleaseVersionRegexp = regexp.MustCompile(`^DISTRIB_RELEASE=(.*)`)
) )
// AptSourcesNamespaceDetector implements NamespaceDetector and detects the Namespace from the // LsbReleaseNamespaceDetector implements NamespaceDetector and detects the
// /etc/lsb-release file. // Namespace from the /etc/lsb-release file.
// //
// This detector is necessary for Ubuntu Precise. // This detector is necessary for Ubuntu Precise.
type LsbReleaseNamespaceDetector struct{} type LsbReleaseNamespaceDetector struct{}
@ -73,9 +75,9 @@ func (detector *LsbReleaseNamespaceDetector) Detect(data map[string][]byte) *dat
var versionFormat string var versionFormat string
switch OS { switch OS {
case "debian", "ubuntu": case "debian", "ubuntu":
versionFormat = "dpkg" versionFormat = dpkg.ParserName
case "centos", "rhel", "fedora", "amzn", "ol", "oracle": case "centos", "rhel", "fedora", "amzn", "ol", "oracle":
versionFormat = "rpm" versionFormat = rpm.ParserName
default: default:
return nil return nil
} }

View File

@ -20,6 +20,8 @@ import (
"strings" "strings"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
) )
@ -76,9 +78,9 @@ func (detector *OsReleaseNamespaceDetector) Detect(data map[string][]byte) *data
var versionFormat string var versionFormat string
switch OS { switch OS {
case "debian", "ubuntu": case "debian", "ubuntu":
versionFormat = "dpkg" versionFormat = dpkg.ParserName
case "centos", "rhel", "fedora", "amzn", "ol", "oracle": case "centos", "rhel", "fedora", "amzn", "ol", "oracle":
versionFormat = "rpm" versionFormat = rpm.ParserName
default: default:
return nil return nil
} }

View File

@ -19,6 +19,7 @@ import (
"strings" "strings"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"
) )
@ -60,7 +61,7 @@ func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *
if len(r) == 4 { if len(r) == 4 {
return &database.Namespace{ return &database.Namespace{
Name: strings.ToLower(r[1]) + ":" + r[3], Name: strings.ToLower(r[1]) + ":" + r[3],
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
} }
} }
@ -70,7 +71,7 @@ func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *
// TODO(vbatts) this is a hack until https://github.com/coreos/clair/pull/193 // TODO(vbatts) this is a hack until https://github.com/coreos/clair/pull/193
return &database.Namespace{ return &database.Namespace{
Name: "centos" + ":" + r[3], Name: "centos" + ":" + r[3],
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
} }
} }
@ -79,7 +80,7 @@ func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *
if len(r) == 4 { if len(r) == 4 {
return &database.Namespace{ return &database.Namespace{
Name: strings.ToLower(r[1]) + ":" + r[3], Name: strings.ToLower(r[1]) + ":" + r[3],
VersionFormat: "rpm", VersionFormat: rpm.ParserName,
} }
} }

View File

@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" cerrors "github.com/coreos/clair/utils/errors"
// Register the required detectors. // Register the required detectors.
@ -89,7 +90,7 @@ func TestProcessWithDistUpgrade(t *testing.T) {
for _, nufv := range nonUpgradedFeatureVersions { for _, nufv := range nonUpgradedFeatureVersions {
nufv.Feature.Namespace.Name = "debian:7" nufv.Feature.Namespace.Name = "debian:7"
nufv.Feature.Namespace.VersionFormat = "dpkg" nufv.Feature.Namespace.VersionFormat = dpkg.ParserName
assert.Contains(t, wheezy.Features, nufv) assert.Contains(t, wheezy.Features, nufv)
} }
} }
@ -102,12 +103,12 @@ func TestProcessWithDistUpgrade(t *testing.T) {
for _, nufv := range nonUpgradedFeatureVersions { for _, nufv := range nonUpgradedFeatureVersions {
nufv.Feature.Namespace.Name = "debian:7" nufv.Feature.Namespace.Name = "debian:7"
nufv.Feature.Namespace.VersionFormat = "dpkg" nufv.Feature.Namespace.VersionFormat = dpkg.ParserName
assert.Contains(t, jessie.Features, nufv) assert.Contains(t, jessie.Features, nufv)
} }
for _, nufv := range nonUpgradedFeatureVersions { for _, nufv := range nonUpgradedFeatureVersions {
nufv.Feature.Namespace.Name = "debian:8" nufv.Feature.Namespace.Name = "debian:8"
nufv.Feature.Namespace.VersionFormat = "dpkg" nufv.Feature.Namespace.VersionFormat = dpkg.ParserName
assert.NotContains(t, jessie.Features, nufv) assert.NotContains(t, jessie.Features, nufv)
} }
} }