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 debian
|
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"
|
|
|
|
|
|
|
|
"github.com/coreos/clair/database"
|
2016-12-28 01:45:11 +00:00
|
|
|
"github.com/coreos/clair/ext/versionfmt"
|
2017-01-03 21:00:20 +00:00
|
|
|
"github.com/coreos/clair/ext/versionfmt/dpkg"
|
2015-11-13 19:11:28 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDebianParser(t *testing.T) {
|
|
|
|
_, filename, _, _ := runtime.Caller(0)
|
|
|
|
|
|
|
|
// Test parsing testdata/fetcher_debian_test.json
|
2016-05-17 21:30:40 +00:00
|
|
|
testFile, _ := os.Open(filepath.Join(filepath.Dir(filename)) + "/testdata/fetcher_debian_test.json")
|
2015-11-13 19:11:28 +00:00
|
|
|
response, err := buildResponse(testFile, "")
|
2017-07-26 23:22:29 +00:00
|
|
|
if assert.Nil(t, err) && assert.Len(t, response.Vulnerabilities, 2) {
|
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)
|
2017-01-19 18:42:37 +00:00
|
|
|
assert.Equal(t, database.LowSeverity, vulnerability.Severity)
|
2015-11-13 19:11:28 +00:00
|
|
|
assert.Equal(t, "This vulnerability is not very dangerous.", vulnerability.Description)
|
|
|
|
|
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: "debian:8",
|
|
|
|
VersionFormat: dpkg.ParserName,
|
2016-01-19 18:36:19 +00:00
|
|
|
},
|
2017-07-26 23:22:29 +00:00
|
|
|
FeatureName: "aptdaemon",
|
|
|
|
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: "debian:unstable",
|
|
|
|
VersionFormat: dpkg.ParserName,
|
2016-01-19 18:36:19 +00:00
|
|
|
},
|
2017-07-26 23:22:29 +00:00
|
|
|
FeatureName: "aptdaemon",
|
|
|
|
AffectedVersion: "1.1.1+bzr982-1",
|
|
|
|
FixedInVersion: "1.1.1+bzr982-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
|
|
|
}
|
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)
|
2017-01-19 18:42:37 +00:00
|
|
|
assert.Equal(t, database.HighSeverity, vulnerability.Severity)
|
2015-11-13 19:11:28 +00:00
|
|
|
assert.Equal(t, "But this one is very dangerous.", vulnerability.Description)
|
|
|
|
|
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: "debian:8",
|
|
|
|
VersionFormat: dpkg.ParserName,
|
2016-01-19 18:36:19 +00:00
|
|
|
},
|
2017-07-26 23:22:29 +00:00
|
|
|
FeatureName: "aptdaemon",
|
|
|
|
FixedInVersion: "0.7.0",
|
|
|
|
AffectedVersion: "0.7.0",
|
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: "debian:unstable",
|
|
|
|
VersionFormat: dpkg.ParserName,
|
2016-01-19 18:36:19 +00:00
|
|
|
},
|
2017-07-26 23:22:29 +00:00
|
|
|
FeatureName: "aptdaemon",
|
|
|
|
FixedInVersion: "0.7.0",
|
|
|
|
AffectedVersion: "0.7.0",
|
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: "debian:8",
|
|
|
|
VersionFormat: dpkg.ParserName,
|
2016-01-19 18:36:19 +00:00
|
|
|
},
|
2017-07-26 23:22:29 +00:00
|
|
|
FeatureName: "asterisk",
|
|
|
|
FixedInVersion: "0.5.56",
|
|
|
|
AffectedVersion: "0.5.56",
|
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
|
|
|
}
|
|
|
|
} else {
|
2017-07-26 23:22:29 +00:00
|
|
|
assert.Fail(t, "Wrong vulnerability name: ", vulnerability.Namespace.Name+":"+vulnerability.Name)
|
2015-11-13 19:11:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|