2017-01-15 15:52:13 +00:00
// Copyright 2017 clair authors
2015-11-13 19:11:28 +00:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2016-01-13 21:41:00 +00:00
package ubuntu
2015-11-13 19:11:28 +00:00
import (
"os"
2016-05-17 21:30:40 +00:00
"path/filepath"
2015-11-13 19:11:28 +00:00
"runtime"
"testing"
2016-12-28 01:45:11 +00:00
"github.com/stretchr/testify/assert"
2015-11-13 19:11:28 +00:00
"github.com/coreos/clair/database"
2016-12-28 01:45:11 +00:00
"github.com/coreos/clair/ext/versionfmt"
2017-02-28 17:55:54 +00:00
"github.com/coreos/clair/ext/versionfmt/dpkg"
2015-11-13 19:11:28 +00:00
)
func TestUbuntuParser ( t * testing . T ) {
_ , filename , _ , _ := runtime . Caller ( 0 )
2016-05-17 21:30:40 +00:00
path := filepath . Join ( filepath . Dir ( filename ) )
2015-11-13 19:11:28 +00:00
// Test parsing testdata/fetcher_
testData , _ := os . Open ( path + "/testdata/fetcher_ubuntu_test.txt" )
defer testData . Close ( )
2016-01-19 18:36:19 +00:00
vulnerability , unknownReleases , err := parseUbuntuCVE ( testData )
2015-11-13 19:11:28 +00:00
if assert . Nil ( t , err ) {
2016-01-19 18:36:19 +00:00
assert . Equal ( t , "CVE-2015-4471" , vulnerability . Name )
2017-01-19 18:42:37 +00:00
assert . Equal ( t , database . MediumSeverity , vulnerability . Severity )
2015-11-13 19:11:28 +00:00
assert . Equal ( t , "Off-by-one error in the lzxd_decompress function in lzxd.c in libmspack before 0.5 allows remote attackers to cause a denial of service (buffer under-read and application crash) via a crafted CAB archive." , vulnerability . Description )
// Unknown release (line 28)
_ , hasUnkownRelease := unknownReleases [ "unknown" ]
assert . True ( t , hasUnkownRelease )
2017-07-26 23:22:29 +00:00
expectedFeatures := [ ] database . AffectedFeature {
2016-02-25 00:29:36 +00:00
{
2017-07-26 23:22:29 +00:00
Namespace : database . Namespace {
Name : "ubuntu:14.04" ,
VersionFormat : dpkg . ParserName ,
2016-01-19 18:36:19 +00:00
} ,
2017-07-26 23:22:29 +00:00
FeatureName : "libmspack" ,
AffectedVersion : versionfmt . MaxVersion ,
2015-12-01 19:58:17 +00:00
} ,
2016-02-25 00:29:36 +00:00
{
2017-07-26 23:22:29 +00:00
Namespace : database . Namespace {
Name : "ubuntu:15.04" ,
VersionFormat : dpkg . ParserName ,
2016-01-19 18:36:19 +00:00
} ,
2017-07-26 23:22:29 +00:00
FeatureName : "libmspack" ,
FixedInVersion : "0.4-3" ,
AffectedVersion : "0.4-3" ,
2015-12-01 19:58:17 +00:00
} ,
2016-02-25 00:29:36 +00:00
{
2017-07-26 23:22:29 +00:00
Namespace : database . Namespace {
Name : "ubuntu:15.10" ,
VersionFormat : dpkg . ParserName ,
2016-01-19 18:36:19 +00:00
} ,
2017-07-26 23:22:29 +00:00
FeatureName : "libmspack-anotherpkg" ,
FixedInVersion : "0.1" ,
AffectedVersion : "0.1" ,
2015-12-01 19:58:17 +00:00
} ,
}
2017-07-26 23:22:29 +00:00
for _ , expectedFeature := range expectedFeatures {
assert . Contains ( t , vulnerability . Affected , expectedFeature )
2015-11-13 19:11:28 +00:00
}
}
}