Checking outbound requests starting to happen
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user