From 9d52f1d5820de38236f4e941f265f825fa869359 Mon Sep 17 00:00:00 2001 From: gersbach Date: Thu, 23 May 2024 10:46:16 -0700 Subject: [PATCH] fixing comments in 1/1 today --- crates/forge_analyzer/src/reporter.rs | 29 +++++++------------------- crates/fsrt/src/test.rs | 30 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/crates/forge_analyzer/src/reporter.rs b/crates/forge_analyzer/src/reporter.rs index ab39338..1be3e22 100644 --- a/crates/forge_analyzer/src/reporter.rs +++ b/crates/forge_analyzer/src/reporter.rs @@ -1,4 +1,3 @@ -use itertools::Itertools; use serde::Serialize; use time::{Date, OffsetDateTime}; @@ -23,6 +22,12 @@ pub struct Vulnerability { pub(crate) date: Date, } +impl Vulnerability { + pub fn check_name(&self) -> &str { + &self.check_name + } +} + pub trait IntoVuln { fn into_vuln(self, reporter: &Reporter) -> Vulnerability; } @@ -106,29 +111,9 @@ impl Reporter { impl Report { #[inline] - pub fn into_vulns(&self) -> &Vec { + pub fn into_vulns(&self) -> &[Vulnerability] { &self.vulns } - - #[inline] - pub fn has_no_vulns(&self) -> bool { - self.vulns.is_empty() - } - - #[inline] - pub fn contains_secret_vuln(&self, expected_len: i32) -> bool { - self.vulns - .iter() - .filter(|vuln| vuln.check_name == "Hardcoded-Secret-11311281663139041059") - .collect_vec() - .len() - == expected_len as usize - } - - #[inline] - pub fn contains_vulns(&self, expected_len: i32) -> bool { - self.vulns.len() == expected_len as usize - } } impl Default for Reporter { diff --git a/crates/fsrt/src/test.rs b/crates/fsrt/src/test.rs index e66ff18..bd5f7fa 100644 --- a/crates/fsrt/src/test.rs +++ b/crates/fsrt/src/test.rs @@ -1,6 +1,7 @@ use crate::{forge_project::ForgeProjectTrait, scan_directory, Args}; use clap::Parser; use forge_analyzer::definitions::PackageData; +use forge_analyzer::reporter::Report; use forge_loader::manifest::{ForgeManifest, FunctionMod}; use std::fmt; use std::{ @@ -11,6 +12,35 @@ use std::{ use swc_core::common::sync::Lrc; use swc_core::common::{FileName, SourceFile, SourceMap}; +trait ReportExt { + fn has_no_vulns(&self) -> bool; + + fn contains_secret_vuln(&self, expected_len: usize) -> bool; + + fn contains_vulns(&self, expected_len: i32) -> bool; +} + +impl ReportExt for Report { + #[inline] + fn has_no_vulns(&self) -> bool { + self.into_vulns().is_empty() + } + + #[inline] + fn contains_secret_vuln(&self, expected_len: usize) -> bool { + self.into_vulns() + .iter() + .filter(|vuln| vuln.check_name() == "Hardcoded-Secret-11311281663139041059") + .count() + == expected_len + } + + #[inline] + fn contains_vulns(&self, expected_len: i32) -> bool { + self.into_vulns().len() == expected_len as usize + } +} + #[derive(Clone)] pub(crate) struct MockForgeProject<'a> { pub files_name_to_source: HashMap>,