Skip to content

Commit

Permalink
fixing comments in 1/1 today
Browse files Browse the repository at this point in the history
  • Loading branch information
gersbach committed May 23, 2024
1 parent 285cf8f commit 9d52f1d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
29 changes: 7 additions & 22 deletions crates/forge_analyzer/src/reporter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use itertools::Itertools;
use serde::Serialize;
use time::{Date, OffsetDateTime};

Expand All @@ -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;
}
Expand Down Expand Up @@ -106,29 +111,9 @@ impl Reporter {

impl Report {
#[inline]
pub fn into_vulns(&self) -> &Vec<Vulnerability> {
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 {
Expand Down
30 changes: 30 additions & 0 deletions crates/fsrt/src/test.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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<PathBuf, Arc<SourceFile>>,
Expand Down

0 comments on commit 9d52f1d

Please sign in to comment.