From dc5576e1d7e1bdf98bd78088790e8505e1de7253 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 3 Sep 2020 15:02:17 +0100 Subject: [PATCH] Checking outbound requests starting to happen --- .../simple-socks5/src/allowed_hosts.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/service-providers/simple-socks5/src/allowed_hosts.rs b/service-providers/simple-socks5/src/allowed_hosts.rs index d8cd8262dc..7e4b758dab 100644 --- a/service-providers/simple-socks5/src/allowed_hosts.rs +++ b/service-providers/simple-socks5/src/allowed_hosts.rs @@ -14,16 +14,17 @@ impl OutboundRequestFilter { } } - pub(crate) fn check(&self, host: &str) -> bool { - if self.allowed_hosts.contains(host.to_string()) { + pub(crate) fn check(&mut self, host: &str) -> bool { + let hostname = host.to_string().clone(); + if self.allowed_hosts.contains(hostname.clone()) { true } else { - self.unknown_hosts.maybe_add(host.to_string()); + self.unknown_hosts.maybe_add(hostname); false } } - pub(crate) fn is_unknown(&self, host: &str) -> bool { + pub(crate) fn is_unknown(&self, _host: &str) -> bool { true } } @@ -43,7 +44,7 @@ impl Persistence { } fn maybe_add(&mut self, host: String) { - if !self.contains(host) { + if !self.contains(host.clone()) { self.hosts.push(host); } } @@ -51,7 +52,7 @@ impl Persistence { /// Reloads the allowed.list and unknown.list files into memory. Used primarily for testing. fn reload_from_disk(&self) {} - fn append_to_file(&self, host: String) {} + fn append_to_file(&self, _host: String) {} } // Appender @@ -68,14 +69,14 @@ mod requests_to_unknown_hosts { #[test] fn are_not_allowed() { let host = "unknown.com"; - let filter = setup(); + let mut filter = setup(); assert_eq!(false, filter.check(&host)); } #[test] fn get_saved_to_file() { let host = "unknown.com"; - let filter = setup(); + let mut filter = setup(); filter.check(host); assert!(true, filter.is_unknown(host)); } @@ -83,7 +84,7 @@ mod requests_to_unknown_hosts { #[test] fn get_appended_once_to_the_unknown_hosts_list() { let host = "unknown.com"; - let filter = setup(); + let mut filter = setup(); filter.check(host); assert_eq!(1, filter.unknown_hosts.hosts.len()); } @@ -102,7 +103,7 @@ mod requests_to_allowed_hosts { #[test] fn are_allowed() { let host = "nymtech.net"; - let filter = setup(); + let mut filter = setup(); assert_eq!(true, filter.check(host)); }