fix(redhat): possibility of false positives on RHEL (#1115)
This commit is contained in:
13
oval/util.go
13
oval/util.go
@@ -378,9 +378,6 @@ func isOvalDefAffected(def ovalmodels.Definition, req request, family string, ru
|
||||
return false, false, ""
|
||||
}
|
||||
|
||||
var centosVerPattern = regexp.MustCompile(`\.[es]l(\d+)(?:_\d+)?(?:\.centos)?`)
|
||||
var esVerPattern = regexp.MustCompile(`\.el(\d+)(?:_\d+)?`)
|
||||
|
||||
func lessThan(family, newVer string, packInOVAL ovalmodels.Package) (bool, error) {
|
||||
switch family {
|
||||
case config.Debian,
|
||||
@@ -416,8 +413,8 @@ func lessThan(family, newVer string, packInOVAL ovalmodels.Package) (bool, error
|
||||
|
||||
case config.RedHat,
|
||||
config.CentOS:
|
||||
vera := rpmver.NewVersion(centosVerPattern.ReplaceAllString(newVer, ".el$1"))
|
||||
verb := rpmver.NewVersion(esVerPattern.ReplaceAllString(packInOVAL.Version, ".el$1"))
|
||||
vera := rpmver.NewVersion(centOSVersionToRHEL(newVer))
|
||||
verb := rpmver.NewVersion(packInOVAL.Version)
|
||||
return vera.LessThan(verb), nil
|
||||
|
||||
default:
|
||||
@@ -425,3 +422,9 @@ func lessThan(family, newVer string, packInOVAL ovalmodels.Package) (bool, error
|
||||
}
|
||||
return false, xerrors.Errorf("Package version comparison not supported: %s", family)
|
||||
}
|
||||
|
||||
var centosVerPattern = regexp.MustCompile(`\.[es]l(\d+)(?:_\d+)?(?:\.centos)?`)
|
||||
|
||||
func centOSVersionToRHEL(ver string) string {
|
||||
return centosVerPattern.ReplaceAllString(ver, ".el$1")
|
||||
}
|
||||
|
||||
@@ -1193,3 +1193,36 @@ func Test_major(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_centOSVersionToRHEL(t *testing.T) {
|
||||
type args struct {
|
||||
ver string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "remove centos.",
|
||||
args: args{
|
||||
ver: "grub2-tools-2.02-0.80.el7.centos.x86_64",
|
||||
},
|
||||
want: "grub2-tools-2.02-0.80.el7.x86_64",
|
||||
},
|
||||
{
|
||||
name: "noop",
|
||||
args: args{
|
||||
ver: "grub2-tools-2.02-0.80.el7.x86_64",
|
||||
},
|
||||
want: "grub2-tools-2.02-0.80.el7.x86_64",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := centOSVersionToRHEL(tt.args.ver); got != tt.want {
|
||||
t.Errorf("centOSVersionToRHEL() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user