mirror of
https://github.com/epi052/feroxbuster.git
synced 2026-05-29 10:31:12 -03:00
appeased clippy
This commit is contained in:
@@ -459,7 +459,7 @@ impl Configuration {
|
||||
|
||||
/// Parse all possible versions of the ferox-config.toml file, adhering to the order of
|
||||
/// precedence outlined above
|
||||
fn parse_config_files(mut config: &mut Self) -> Result<()> {
|
||||
fn parse_config_files(config: &mut Self) -> Result<()> {
|
||||
// Next, we parse the ferox-config.toml file, if present and set the values
|
||||
// therein to overwrite our default values. Deserialized defaults are specified
|
||||
// in the Configuration struct so that we don't change anything that isn't
|
||||
@@ -475,7 +475,7 @@ impl Configuration {
|
||||
let config_file = PathBuf::new()
|
||||
.join("/etc/feroxbuster")
|
||||
.join(DEFAULT_CONFIG_NAME);
|
||||
Self::parse_and_merge_config(config_file, &mut config)?;
|
||||
Self::parse_and_merge_config(config_file, config)?;
|
||||
|
||||
// merge a config found at ~/.config/feroxbuster/ferox-config.toml
|
||||
// config_dir() resolves to one of the following
|
||||
@@ -484,7 +484,7 @@ impl Configuration {
|
||||
// - windows: {FOLDERID_RoamingAppData}
|
||||
let config_dir = dirs::config_dir().ok_or_else(|| anyhow!("Couldn't load config"))?;
|
||||
let config_file = config_dir.join("feroxbuster").join(DEFAULT_CONFIG_NAME);
|
||||
Self::parse_and_merge_config(config_file, &mut config)?;
|
||||
Self::parse_and_merge_config(config_file, config)?;
|
||||
|
||||
// merge a config found in same the directory as feroxbuster executable
|
||||
let exe_path = current_exe()?;
|
||||
@@ -492,12 +492,12 @@ impl Configuration {
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("Couldn't load config"))?;
|
||||
let config_file = bin_dir.join(DEFAULT_CONFIG_NAME);
|
||||
Self::parse_and_merge_config(config_file, &mut config)?;
|
||||
Self::parse_and_merge_config(config_file, config)?;
|
||||
|
||||
// merge a config found in the user's current working directory
|
||||
let cwd = current_dir()?;
|
||||
let config_file = cwd.join(DEFAULT_CONFIG_NAME);
|
||||
Self::parse_and_merge_config(config_file, &mut config)?;
|
||||
Self::parse_and_merge_config(config_file, config)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -804,7 +804,7 @@ impl Configuration {
|
||||
config.config = conf_str;
|
||||
|
||||
// update the settings
|
||||
Self::merge_config(&mut config, settings);
|
||||
Self::merge_config(config, settings);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -85,13 +85,7 @@ impl Handles {
|
||||
let configuration = config.unwrap_or_else(|| Arc::new(Configuration::new().unwrap()));
|
||||
let (tx, rx) = mpsc::unbounded_channel::<Command>();
|
||||
let terminal_handle = TermOutHandle::new(tx.clone(), tx.clone());
|
||||
let stats_handle = StatsHandle::new(
|
||||
Arc::new(Stats::new(
|
||||
configuration.extensions.len(),
|
||||
configuration.json,
|
||||
)),
|
||||
tx.clone(),
|
||||
);
|
||||
let stats_handle = StatsHandle::new(Arc::new(Stats::new(configuration.json)), tx.clone());
|
||||
let filters_handle = FiltersHandle::new(Arc::new(FeroxFilters::default()), tx.clone());
|
||||
let handles = Self::new(stats_handle, filters_handle, terminal_handle, configuration);
|
||||
if let Some(sh) = scanned_urls {
|
||||
|
||||
@@ -155,7 +155,7 @@ impl StatsHandler {
|
||||
pub fn initialize(config: Arc<Configuration>) -> (Joiner, StatsHandle) {
|
||||
log::trace!("enter: initialize");
|
||||
|
||||
let data = Arc::new(Stats::new(config.extensions.len(), config.json));
|
||||
let data = Arc::new(Stats::new(config.json));
|
||||
let (tx, rx): FeroxChannel<Command> = mpsc::unbounded_channel();
|
||||
|
||||
let mut handler = StatsHandler::new(data.clone(), rx);
|
||||
|
||||
@@ -198,11 +198,11 @@ impl<'a> Extractor<'a> {
|
||||
/// - homepage/assets/img/
|
||||
/// - homepage/assets/
|
||||
/// - homepage/
|
||||
fn add_all_sub_paths(&self, url_path: &str, mut links: &mut HashSet<String>) -> Result<()> {
|
||||
fn add_all_sub_paths(&self, url_path: &str, links: &mut HashSet<String>) -> Result<()> {
|
||||
log::trace!("enter: add_all_sub_paths({}, {:?})", url_path, links);
|
||||
|
||||
for sub_path in self.get_sub_paths_from_path(url_path) {
|
||||
self.add_link_to_set_of_links(&sub_path, &mut links)?;
|
||||
self.add_link_to_set_of_links(&sub_path, links)?;
|
||||
}
|
||||
|
||||
log::trace!("exit: add_all_sub_paths");
|
||||
@@ -327,7 +327,7 @@ impl<'a> Extractor<'a> {
|
||||
let new_response = logged_request(&new_url, self.handles.clone()).await?;
|
||||
|
||||
let new_ferox_response =
|
||||
FeroxResponse::from(new_response, &url, true, self.handles.config.output_level).await;
|
||||
FeroxResponse::from(new_response, url, true, self.handles.config.output_level).await;
|
||||
|
||||
log::trace!("exit: request_link -> {:?}", new_ferox_response);
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ pub async fn initialize(handles: Arc<Handles>) -> Result<()> {
|
||||
|
||||
// if successful, create a filter based on the response's body
|
||||
let fr =
|
||||
FeroxResponse::from(resp, &similarity_filter, true, handles.config.output_level).await;
|
||||
FeroxResponse::from(resp, similarity_filter, true, handles.config.output_level).await;
|
||||
|
||||
// hash the response body and store the resulting hash in the filter object
|
||||
let hash = FuzzyHash::new(&fr.text()).to_string();
|
||||
|
||||
@@ -5,18 +5,9 @@ use indicatif::ProgressDrawTarget;
|
||||
/// Interactive scan cancellation menu
|
||||
#[derive(Debug)]
|
||||
pub(super) struct Menu {
|
||||
/// character to use as visual separator of lines
|
||||
separator: String,
|
||||
|
||||
/// name of menu
|
||||
name: String,
|
||||
|
||||
/// header: name surrounded by separators
|
||||
header: String,
|
||||
|
||||
/// instructions
|
||||
instructions: String,
|
||||
|
||||
/// footer: instructions surrounded by separators
|
||||
footer: String,
|
||||
|
||||
@@ -62,10 +53,7 @@ impl Menu {
|
||||
let footer = format!("{}\n{}\n{}\n{}", border, instructions, padded_force, border);
|
||||
|
||||
Self {
|
||||
separator,
|
||||
name,
|
||||
header,
|
||||
instructions,
|
||||
footer,
|
||||
term: Term::stderr(),
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ fn feroxstates_feroxserialize_implementation() {
|
||||
ferox_scans.insert(ferox_scan);
|
||||
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Arc::new(Stats::new(config.extensions.len(), config.json));
|
||||
let stats = Arc::new(Stats::new(config.json));
|
||||
|
||||
let json_response = r#"{"type":"response","url":"https://nerdcore.com/css","path":"/css","wildcard":true,"status":301,"content_length":173,"line_count":10,"word_count":16,"headers":{"server":"nginx/1.16.1"}}"#;
|
||||
let response: FeroxResponse = serde_json::from_str(json_response).unwrap();
|
||||
|
||||
@@ -126,9 +126,6 @@ pub struct Stats {
|
||||
/// tracker for total runtime
|
||||
total_runtime: Mutex<Vec<f64>>,
|
||||
|
||||
/// tracker for the number of extensions the user specified
|
||||
num_extensions: usize,
|
||||
|
||||
/// tracker for whether to use json during serialization or not
|
||||
json: bool,
|
||||
}
|
||||
@@ -203,7 +200,7 @@ impl<'a> Deserialize<'a> for Stats {
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let stats = Self::new(0, false);
|
||||
let stats = Self::new(false);
|
||||
|
||||
let map: HashMap<String, Value> = HashMap::deserialize(deserializer)?;
|
||||
|
||||
@@ -446,9 +443,8 @@ impl<'a> Deserialize<'a> for Stats {
|
||||
impl Stats {
|
||||
/// Small wrapper for default to set `kind` to "statistics" and `total_runtime` to have at least
|
||||
/// one value
|
||||
pub fn new(num_extensions: usize, is_json: bool) -> Self {
|
||||
pub fn new(is_json: bool) -> Self {
|
||||
Self {
|
||||
num_extensions,
|
||||
json: is_json,
|
||||
kind: String::from("statistics"),
|
||||
total_runtime: Mutex::new(vec![0.0]),
|
||||
@@ -790,7 +786,7 @@ mod tests {
|
||||
/// - errors
|
||||
fn stats_increments_timeouts() {
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
|
||||
stats.add_error(StatError::Timeout);
|
||||
stats.add_error(StatError::Timeout);
|
||||
@@ -808,7 +804,7 @@ mod tests {
|
||||
/// - responses_filtered
|
||||
fn stats_increments_wildcards() {
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
|
||||
assert_eq!(stats.responses_filtered.load(Ordering::Relaxed), 0);
|
||||
assert_eq!(stats.wildcards_filtered.load(Ordering::Relaxed), 0);
|
||||
@@ -824,7 +820,7 @@ mod tests {
|
||||
/// when Stats::update_usize_field receives StatField::ResponsesFiltered, it should increment
|
||||
fn stats_increments_responses_filtered() {
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
|
||||
assert_eq!(stats.responses_filtered.load(Ordering::Relaxed), 0);
|
||||
|
||||
@@ -840,7 +836,7 @@ mod tests {
|
||||
fn stats_merge_from_alters_correct_fields() {
|
||||
let contents = r#"{"statistics":{"type":"statistics","timeouts":1,"requests":9207,"expected_per_scan":707,"total_expected":9191,"errors":3,"successes":720,"redirects":13,"client_errors":8474,"server_errors":2,"total_scans":13,"initial_targets":1,"links_extracted":51,"status_403s":3,"status_200s":720,"status_301s":12,"status_302s":1,"status_401s":4,"status_429s":2,"status_500s":5,"status_503s":9,"status_504s":6,"status_508s":7,"wildcards_filtered":707,"responses_filtered":707,"resources_discovered":27,"directory_scan_times":[2.211973078,1.989015505,1.898675839,3.9714468910000003,4.938152838,5.256073528,6.021986595,6.065740734,6.42633762,7.095142125,7.336982137,5.319785619,4.843649778],"total_runtime":[11.556575456000001],"url_format_errors":17,"redirection_errors":12,"connection_errors":21,"request_errors":4}}"#;
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
|
||||
let tfile = NamedTempFile::new().unwrap();
|
||||
write(&tfile, contents).unwrap();
|
||||
@@ -891,7 +887,7 @@ mod tests {
|
||||
/// ensure update runtime overwrites the default 0th entry
|
||||
fn update_runtime_works() {
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
|
||||
assert!((stats.total_runtime.lock().unwrap()[0] - 0.0).abs() < f64::EPSILON);
|
||||
stats.update_runtime(20.2);
|
||||
@@ -902,7 +898,7 @@ mod tests {
|
||||
/// ensure status_403s returns the correct value
|
||||
fn status_403s_returns_correct_value() {
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
stats.status_403s.store(12, Ordering::Relaxed);
|
||||
assert_eq!(stats.status_403s(), 12);
|
||||
}
|
||||
@@ -911,7 +907,7 @@ mod tests {
|
||||
/// ensure status_403s returns the correct value
|
||||
fn status_429s_returns_correct_value() {
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
stats.status_429s.store(141, Ordering::Relaxed);
|
||||
assert_eq!(stats.status_429s(), 141);
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ macro_rules! atomic_increment {
|
||||
#[macro_export]
|
||||
macro_rules! atomic_load {
|
||||
($metric:expr) => {
|
||||
$metric.load(Ordering::Relaxed);
|
||||
$metric.load(Ordering::Relaxed)
|
||||
};
|
||||
($metric:expr, $ordering:expr) => {
|
||||
$metric.load($ordering);
|
||||
$metric.load($ordering)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ async fn statistics_handler_exits() -> Result<()> {
|
||||
/// Stats::save should write contents of Stats to disk
|
||||
fn save_writes_stats_object_to_disk() {
|
||||
let config = Configuration::new().unwrap();
|
||||
let stats = Stats::new(config.extensions.len(), config.json);
|
||||
let stats = Stats::new(config.json);
|
||||
|
||||
stats.add_request();
|
||||
stats.add_request();
|
||||
|
||||
Reference in New Issue
Block a user