-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This test starts a small notus scan and checks, if it generates the correct results
- Loading branch information
Showing
8 changed files
with
119 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-FileCopyrightText: 2023 Greenbone AG | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use models::{FixedVersion, Specifier}; | ||
use notus::{loader::json::JSONAdvisoriesLoader, notus::Notus}; | ||
|
||
#[test] | ||
fn test_notus() { | ||
let mut path = env!("CARGO_MANIFEST_DIR").to_string(); | ||
path.push_str("/data"); | ||
let loader = JSONAdvisoriesLoader::new(path).unwrap(); | ||
let mut notus = Notus::new(loader); | ||
|
||
let packages = vec![ | ||
"gitlab-ce-16.0.1".to_string(), // vul | ||
"bar-7.6.5".to_string(), // no vul | ||
"grafana-8.5.25".to_string(), // no vul | ||
"grafana8-8.5.23".to_string(), // vul | ||
"grafana9-9.4.7".to_string(), // vul | ||
"foo-1.2.3".to_string(), // no vul | ||
]; | ||
|
||
let results = notus.scan("debian_10", packages).unwrap(); | ||
assert_eq!(results.len(), 2); | ||
|
||
let result1 = &results["1.3.6.1.4.1.25623.1.1.7.2.2023.10089729899100"]; | ||
let result2 = &results["1.3.6.1.4.1.25623.1.1.7.2.2023.0988598199100"]; | ||
|
||
assert_eq!(result1.len(), 1); | ||
let vul_pkg = &result1[0]; | ||
assert_eq!(vul_pkg.name, "gitlab-ce".to_string()); | ||
assert_eq!(vul_pkg.installed_version, "16.0.1".to_string()); | ||
assert!(matches!( | ||
&vul_pkg.fixed_version, | ||
FixedVersion::Range { start, end } if start == "16.0.0" && end == "16.0.7" | ||
)); | ||
|
||
assert_eq!(result2.len(), 2); | ||
for vul_pkg in result2 { | ||
match vul_pkg.name.as_str() { | ||
"grafana8" => { | ||
assert_eq!(vul_pkg.installed_version, "8.5.23".to_string()); | ||
assert!(matches!( | ||
&vul_pkg.fixed_version, | ||
FixedVersion::Single { version, specifier } if version == "8.5.24" && matches!(specifier, Specifier::GE) | ||
)); | ||
} | ||
"grafana9" => { | ||
assert_eq!(vul_pkg.installed_version, "9.4.7".to_string()); | ||
assert!(matches!( | ||
&vul_pkg.fixed_version, | ||
FixedVersion::Range { start, end } if start == "9.4.0" && end == "9.4.9" | ||
)); | ||
} | ||
_ => panic!("Unexpected vulnerable package: {}", vul_pkg.name), | ||
} | ||
} | ||
} | ||
} |