mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 10:26:30 +00:00
fix up tests
This commit is contained in:
parent
6baccaf8ea
commit
02394942f3
2 changed files with 13 additions and 12 deletions
|
@ -14,7 +14,7 @@ pub struct AnalyzeDependenciesFuture {
|
||||||
impl AnalyzeDependenciesFuture {
|
impl AnalyzeDependenciesFuture {
|
||||||
pub fn new(engine: Engine, deps: CrateDeps) -> Self {
|
pub fn new(engine: Engine, deps: CrateDeps) -> Self {
|
||||||
let future = engine.fetch_advisory_db().and_then(move |advisory_db| {
|
let future = engine.fetch_advisory_db().and_then(move |advisory_db| {
|
||||||
let analyzer = DependencyAnalyzer::new(&deps, advisory_db);
|
let analyzer = DependencyAnalyzer::new(&deps, Some(advisory_db));
|
||||||
|
|
||||||
let main_deps = deps.main.into_iter().filter_map(|(name, dep)| {
|
let main_deps = deps.main.into_iter().filter_map(|(name, dep)| {
|
||||||
if dep.is_external() { Some(name) } else { None }
|
if dep.is_external() { Some(name) } else { None }
|
||||||
|
|
|
@ -7,18 +7,18 @@ use ::models::crates::{CrateDeps, CrateRelease, CrateName, AnalyzedDependency, A
|
||||||
|
|
||||||
pub struct DependencyAnalyzer {
|
pub struct DependencyAnalyzer {
|
||||||
deps: AnalyzedDependencies,
|
deps: AnalyzedDependencies,
|
||||||
advisory_db: Arc<AdvisoryDatabase>
|
advisory_db: Option<Arc<AdvisoryDatabase>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DependencyAnalyzer {
|
impl DependencyAnalyzer {
|
||||||
pub fn new(deps: &CrateDeps, advisory_db: Arc<AdvisoryDatabase>) -> DependencyAnalyzer {
|
pub fn new(deps: &CrateDeps, advisory_db: Option<Arc<AdvisoryDatabase>>) -> DependencyAnalyzer {
|
||||||
DependencyAnalyzer {
|
DependencyAnalyzer {
|
||||||
deps: AnalyzedDependencies::new(deps),
|
deps: AnalyzedDependencies::new(deps),
|
||||||
advisory_db
|
advisory_db
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_single(name: &CrateName, dep: &mut AnalyzedDependency, ver: &Version, advisory_db: &AdvisoryDatabase) {
|
fn process_single(name: &CrateName, dep: &mut AnalyzedDependency, ver: &Version, advisory_db: Option<&AdvisoryDatabase>) {
|
||||||
if dep.required.matches(&ver) {
|
if dep.required.matches(&ver) {
|
||||||
if let Some(ref mut current_latest_that_matches) = dep.latest_that_matches {
|
if let Some(ref mut current_latest_that_matches) = dep.latest_that_matches {
|
||||||
if *current_latest_that_matches < *ver {
|
if *current_latest_that_matches < *ver {
|
||||||
|
@ -28,7 +28,7 @@ impl DependencyAnalyzer {
|
||||||
dep.latest_that_matches = Some(ver.clone());
|
dep.latest_that_matches = Some(ver.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !advisory_db.find_vulns_for_crate(name.as_ref(), ver).is_empty() {
|
if !advisory_db.map(|db| db.find_vulns_for_crate(name.as_ref(), ver).is_empty()).unwrap_or(true) {
|
||||||
dep.insecure = true;
|
dep.insecure = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,15 +44,16 @@ impl DependencyAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process<I: IntoIterator<Item=CrateRelease>>(&mut self, releases: I) {
|
pub fn process<I: IntoIterator<Item=CrateRelease>>(&mut self, releases: I) {
|
||||||
|
let advisory_db = self.advisory_db.as_ref().map(|r| r.as_ref());
|
||||||
for release in releases.into_iter().filter(|r| !r.yanked) {
|
for release in releases.into_iter().filter(|r| !r.yanked) {
|
||||||
if let Some(main_dep) = self.deps.main.get_mut(&release.name) {
|
if let Some(main_dep) = self.deps.main.get_mut(&release.name) {
|
||||||
DependencyAnalyzer::process_single(&release.name, main_dep, &release.version, &self.advisory_db)
|
DependencyAnalyzer::process_single(&release.name, main_dep, &release.version, advisory_db)
|
||||||
}
|
}
|
||||||
if let Some(dev_dep) = self.deps.dev.get_mut(&release.name) {
|
if let Some(dev_dep) = self.deps.dev.get_mut(&release.name) {
|
||||||
DependencyAnalyzer::process_single(&release.name, dev_dep, &release.version, &self.advisory_db)
|
DependencyAnalyzer::process_single(&release.name, dev_dep, &release.version, advisory_db)
|
||||||
}
|
}
|
||||||
if let Some(build_dep) = self.deps.build.get_mut(&release.name) {
|
if let Some(build_dep) = self.deps.build.get_mut(&release.name) {
|
||||||
DependencyAnalyzer::process_single(&release.name, build_dep, &release.version, &self.advisory_db)
|
DependencyAnalyzer::process_single(&release.name, build_dep, &release.version, advisory_db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ mod tests {
|
||||||
let mut deps = CrateDeps::default();
|
let mut deps = CrateDeps::default();
|
||||||
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.11.0".parse().unwrap()));
|
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.11.0".parse().unwrap()));
|
||||||
|
|
||||||
let mut analyzer = DependencyAnalyzer::new(&deps);
|
let mut analyzer = DependencyAnalyzer::new(&deps, None);
|
||||||
analyzer.process(vec![
|
analyzer.process(vec![
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), deps: Default::default(), yanked: false }
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), deps: Default::default(), yanked: false }
|
||||||
|
@ -89,7 +90,7 @@ mod tests {
|
||||||
let mut deps = CrateDeps::default();
|
let mut deps = CrateDeps::default();
|
||||||
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.10.0".parse().unwrap()));
|
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.10.0".parse().unwrap()));
|
||||||
|
|
||||||
let mut analyzer = DependencyAnalyzer::new(&deps);
|
let mut analyzer = DependencyAnalyzer::new(&deps, None);
|
||||||
analyzer.process(vec![
|
analyzer.process(vec![
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), deps: Default::default(), yanked: false },
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), deps: Default::default(), yanked: false },
|
||||||
|
@ -107,7 +108,7 @@ mod tests {
|
||||||
let mut deps = CrateDeps::default();
|
let mut deps = CrateDeps::default();
|
||||||
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.10.0".parse().unwrap()));
|
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.10.0".parse().unwrap()));
|
||||||
|
|
||||||
let mut analyzer = DependencyAnalyzer::new(&deps);
|
let mut analyzer = DependencyAnalyzer::new(&deps, None);
|
||||||
analyzer.process(vec![
|
analyzer.process(vec![
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), deps: Default::default(), yanked: true },
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1".parse().unwrap(), deps: Default::default(), yanked: true },
|
||||||
|
@ -124,7 +125,7 @@ mod tests {
|
||||||
let mut deps = CrateDeps::default();
|
let mut deps = CrateDeps::default();
|
||||||
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.10.0".parse().unwrap()));
|
deps.main.insert("hyper".parse().unwrap(), CrateDep::External("^0.10.0".parse().unwrap()));
|
||||||
|
|
||||||
let mut analyzer = DependencyAnalyzer::new(&deps);
|
let mut analyzer = DependencyAnalyzer::new(&deps, None);
|
||||||
analyzer.process(vec![
|
analyzer.process(vec![
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.0".parse().unwrap(), deps: Default::default(), yanked: false },
|
||||||
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1-alpha".parse().unwrap(), deps: Default::default(), yanked: false },
|
CrateRelease { name: "hyper".parse().unwrap(), version: "0.10.1-alpha".parse().unwrap(), deps: Default::default(), yanked: false },
|
||||||
|
|
Loading…
Reference in a new issue