clair/updater/fetchers/debian/debian_test.go

118 lines
4.0 KiB
Go
Raw Normal View History

2015-11-13 19:11:28 +00:00
// Copyright 2015 clair authors
//
// 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 debian
2015-11-13 19:11:28 +00:00
import (
"os"
"path"
"runtime"
"testing"
"github.com/coreos/clair/database"
"github.com/coreos/clair/utils/types"
"github.com/stretchr/testify/assert"
)
func TestDebianParser(t *testing.T) {
_, filename, _, _ := runtime.Caller(0)
// Test parsing testdata/fetcher_debian_test.json
testFile, _ := os.Open(path.Join(path.Dir(filename)) + "/testdata/fetcher_debian_test.json")
response, err := buildResponse(testFile, "")
2016-01-25 19:50:48 +00:00
if assert.Nil(t, err) && assert.Len(t, response.Vulnerabilities, 3) {
2015-11-13 19:11:28 +00:00
for _, vulnerability := range response.Vulnerabilities {
2016-01-19 18:36:19 +00:00
if vulnerability.Name == "CVE-2015-1323" {
2015-11-13 19:11:28 +00:00
assert.Equal(t, "https://security-tracker.debian.org/tracker/CVE-2015-1323", vulnerability.Link)
2016-01-20 00:17:08 +00:00
assert.Equal(t, types.Low, vulnerability.Severity)
2015-11-13 19:11:28 +00:00
assert.Equal(t, "This vulnerability is not very dangerous.", vulnerability.Description)
2016-01-19 18:36:19 +00:00
expectedFeatureVersions := []database.FeatureVersion{
database.FeatureVersion{
Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"},
Name: "aptdaemon",
},
2015-11-13 19:11:28 +00:00
Version: types.MaxVersion,
},
2016-01-19 18:36:19 +00:00
database.FeatureVersion{
Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:unstable"},
Name: "aptdaemon",
},
2015-11-13 19:11:28 +00:00
Version: types.NewVersionUnsafe("1.1.1+bzr982-1"),
},
}
2016-01-19 18:36:19 +00:00
for _, expectedFeatureVersion := range expectedFeatureVersions {
assert.Contains(t, vulnerability.FixedIn, expectedFeatureVersion)
2015-11-13 19:11:28 +00:00
}
2016-01-19 18:36:19 +00:00
} else if vulnerability.Name == "CVE-2003-0779" {
2015-11-13 19:11:28 +00:00
assert.Equal(t, "https://security-tracker.debian.org/tracker/CVE-2003-0779", vulnerability.Link)
2016-01-20 00:17:08 +00:00
assert.Equal(t, types.High, vulnerability.Severity)
2015-11-13 19:11:28 +00:00
assert.Equal(t, "But this one is very dangerous.", vulnerability.Description)
2016-01-19 18:36:19 +00:00
expectedFeatureVersions := []database.FeatureVersion{
database.FeatureVersion{
Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"},
Name: "aptdaemon",
},
2015-11-13 19:11:28 +00:00
Version: types.NewVersionUnsafe("0.7.0"),
},
2016-01-19 18:36:19 +00:00
database.FeatureVersion{
Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:unstable"},
Name: "aptdaemon",
},
2015-11-13 19:11:28 +00:00
Version: types.NewVersionUnsafe("0.7.0"),
},
2016-01-19 18:36:19 +00:00
database.FeatureVersion{
Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"},
Name: "asterisk",
},
2015-11-13 19:11:28 +00:00
Version: types.NewVersionUnsafe("0.5.56"),
},
}
2016-01-25 19:50:48 +00:00
for _, expectedFeatureVersion := range expectedFeatureVersions {
assert.Contains(t, vulnerability.FixedIn, expectedFeatureVersion)
}
} else if vulnerability.Name == "CVE-2013-2685" {
assert.Equal(t, "https://security-tracker.debian.org/tracker/CVE-2013-2685", vulnerability.Link)
assert.Equal(t, types.Negligible, vulnerability.Severity)
assert.Equal(t, "Un-affected packages.", vulnerability.Description)
expectedFeatureVersions := []database.FeatureVersion{
database.FeatureVersion{
Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"},
Name: "asterisk",
},
Version: types.MinVersion,
},
}
2016-01-19 18:36:19 +00:00
for _, expectedFeatureVersion := range expectedFeatureVersions {
assert.Contains(t, vulnerability.FixedIn, expectedFeatureVersion)
2015-11-13 19:11:28 +00:00
}
} else {
assert.Fail(t, "Wrong vulnerability name: ", vulnerability.ID)
}
}
}
}