2017-01-15 15:52:13 +00:00
// Copyright 2017 clair authors
2016-12-20 00:25:07 +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.
package oracle
import (
"os"
"path/filepath"
"runtime"
"testing"
2017-01-15 15:52:13 +00:00
"github.com/coreos/clair"
2016-12-20 00:25:07 +00:00
"github.com/coreos/clair/database"
2017-01-03 21:00:20 +00:00
"github.com/coreos/clair/ext/versionfmt/rpm"
2016-12-20 00:25:07 +00:00
"github.com/stretchr/testify/assert"
)
func TestOracleParser ( t * testing . T ) {
_ , filename , _ , _ := runtime . Caller ( 0 )
path := filepath . Join ( filepath . Dir ( filename ) )
// Test parsing testdata/fetcher_oracle_test.1.xml
testFile , _ := os . Open ( path + "/testdata/fetcher_oracle_test.1.xml" )
2016-12-20 01:14:10 +00:00
defer testFile . Close ( )
2016-12-20 00:25:07 +00:00
vulnerabilities , err := parseELSA ( testFile )
if assert . Nil ( t , err ) && assert . Len ( t , vulnerabilities , 1 ) {
assert . Equal ( t , "ELSA-2015-1193" , vulnerabilities [ 0 ] . Name )
assert . Equal ( t , "http://linux.oracle.com/errata/ELSA-2015-1193.html" , vulnerabilities [ 0 ] . Link )
2017-01-15 15:52:13 +00:00
assert . Equal ( t , clair . Medium , vulnerabilities [ 0 ] . Severity )
2016-12-20 00:25:07 +00:00
assert . Equal ( t , ` [3.1.1-7] Resolves: rhbz#1217104 CVE-2015-0252 ` , vulnerabilities [ 0 ] . Description )
expectedFeatureVersions := [ ] database . FeatureVersion {
{
Feature : database . Feature {
2016-12-28 01:45:11 +00:00
Namespace : database . Namespace {
Name : "oracle:7" ,
2017-01-03 21:00:20 +00:00
VersionFormat : rpm . ParserName ,
2016-12-28 01:45:11 +00:00
} ,
Name : "xerces-c" ,
2016-12-20 00:25:07 +00:00
} ,
2016-12-28 01:45:11 +00:00
Version : "0:3.1.1-7.el7_1" ,
2016-12-20 00:25:07 +00:00
} ,
{
Feature : database . Feature {
2016-12-28 01:45:11 +00:00
Namespace : database . Namespace {
Name : "oracle:7" ,
2017-01-03 21:00:20 +00:00
VersionFormat : rpm . ParserName ,
2016-12-28 01:45:11 +00:00
} ,
Name : "xerces-c-devel" ,
2016-12-20 00:25:07 +00:00
} ,
2016-12-28 01:45:11 +00:00
Version : "0:3.1.1-7.el7_1" ,
2016-12-20 00:25:07 +00:00
} ,
{
Feature : database . Feature {
2016-12-28 01:45:11 +00:00
Namespace : database . Namespace {
Name : "oracle:7" ,
2017-01-03 21:00:20 +00:00
VersionFormat : rpm . ParserName ,
2016-12-28 01:45:11 +00:00
} ,
Name : "xerces-c-doc" ,
2016-12-20 00:25:07 +00:00
} ,
2016-12-28 01:45:11 +00:00
Version : "0:3.1.1-7.el7_1" ,
2016-12-20 00:25:07 +00:00
} ,
}
for _ , expectedFeatureVersion := range expectedFeatureVersions {
assert . Contains ( t , vulnerabilities [ 0 ] . FixedIn , expectedFeatureVersion )
}
}
2016-12-20 01:14:10 +00:00
testFile2 , _ := os . Open ( path + "/testdata/fetcher_oracle_test.2.xml" )
defer testFile2 . Close ( )
vulnerabilities , err = parseELSA ( testFile2 )
2016-12-20 00:25:07 +00:00
if assert . Nil ( t , err ) && assert . Len ( t , vulnerabilities , 1 ) {
assert . Equal ( t , "ELSA-2015-1207" , vulnerabilities [ 0 ] . Name )
assert . Equal ( t , "http://linux.oracle.com/errata/ELSA-2015-1207.html" , vulnerabilities [ 0 ] . Link )
2017-01-15 15:52:13 +00:00
assert . Equal ( t , clair . Critical , vulnerabilities [ 0 ] . Severity )
2016-12-20 00:25:07 +00:00
assert . Equal ( t , ` [38.1.0-1.0.1.el7_1] - Add firefox-oracle-default-prefs.js and remove the corresponding Red Hat file [38.1.0-1] - Update to 38.1.0 ESR [38.0.1-2] - Fixed rhbz#1222807 by removing preun section ` , vulnerabilities [ 0 ] . Description )
expectedFeatureVersions := [ ] database . FeatureVersion {
{
Feature : database . Feature {
2016-12-28 01:45:11 +00:00
Namespace : database . Namespace {
Name : "oracle:6" ,
2017-01-03 21:00:20 +00:00
VersionFormat : rpm . ParserName ,
2016-12-28 01:45:11 +00:00
} ,
Name : "firefox" ,
2016-12-20 00:25:07 +00:00
} ,
2016-12-28 01:45:11 +00:00
Version : "0:38.1.0-1.0.1.el6_6" ,
2016-12-20 00:25:07 +00:00
} ,
{
Feature : database . Feature {
2016-12-28 01:45:11 +00:00
Namespace : database . Namespace {
Name : "oracle:7" ,
2017-01-03 21:00:20 +00:00
VersionFormat : rpm . ParserName ,
2016-12-28 01:45:11 +00:00
} ,
Name : "firefox" ,
2016-12-20 00:25:07 +00:00
} ,
2016-12-28 01:45:11 +00:00
Version : "0:38.1.0-1.0.1.el7_1" ,
2016-12-20 00:25:07 +00:00
} ,
}
for _ , expectedFeatureVersion := range expectedFeatureVersions {
assert . Contains ( t , vulnerabilities [ 0 ] . FixedIn , expectedFeatureVersion )
}
}
}