|
@@ -724,50 +724,55 @@ mod tests {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //#[test]
|
|
|
|
|
- //fn test_greylist_store() {
|
|
|
|
|
- // let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
-
|
|
|
|
|
- // smol::block_on(async {
|
|
|
|
|
- // let settings = Settings {
|
|
|
|
|
- // localnet: false,
|
|
|
|
|
- // external_addrs: vec![
|
|
|
|
|
- // Url::parse("tcp://foo.bar:123").unwrap(),
|
|
|
|
|
- // Url::parse("tcp://lol.cat:321").unwrap(),
|
|
|
|
|
- // ],
|
|
|
|
|
- // ..Default::default()
|
|
|
|
|
- // };
|
|
|
|
|
-
|
|
|
|
|
- // let hosts = Hosts::new(Arc::new(settings.clone()));
|
|
|
|
|
- // let mut external_addrs = vec![];
|
|
|
|
|
- // for addr in settings.external_addrs {
|
|
|
|
|
- // external_addrs.push((addr, last_seen))
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // hosts.greylist_store(&external_addrs).await;
|
|
|
|
|
- // assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- // let local_hosts = vec![
|
|
|
|
|
- // (Url::parse("tcp://localhost:3921").unwrap(), last_seen),
|
|
|
|
|
- // (Url::parse("tor://[::1]:21481").unwrap(), last_seen),
|
|
|
|
|
- // (Url::parse("tcp://192.168.10.65:311").unwrap(), last_seen),
|
|
|
|
|
- // (Url::parse("tcp+tls://0.0.0.0:2312").unwrap(), last_seen),
|
|
|
|
|
- // (Url::parse("tcp://255.255.255.255:2131").unwrap(), last_seen),
|
|
|
|
|
- // ];
|
|
|
|
|
- // hosts.greylist_store(&local_hosts).await;
|
|
|
|
|
- // assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
-
|
|
|
|
|
- // let remote_hosts = vec![
|
|
|
|
|
- // (Url::parse("tcp://dark.fi:80").unwrap(), last_seen),
|
|
|
|
|
- // (Url::parse("tcp://http.cat:401").unwrap(), last_seen),
|
|
|
|
|
- // (Url::parse("tcp://foo.bar:111").unwrap(), last_seen),
|
|
|
|
|
- // ];
|
|
|
|
|
- // hosts.greylist_store(&remote_hosts).await;
|
|
|
|
|
- // assert!(hosts.greylist_contains(&remote_hosts[0].0).await);
|
|
|
|
|
- // assert!(hosts.greylist_contains(&remote_hosts[1].0).await);
|
|
|
|
|
- // assert!(!hosts.greylist_contains(&remote_hosts[2].0).await);
|
|
|
|
|
- // });
|
|
|
|
|
- //}
|
|
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn test_greylist_store() {
|
|
|
|
|
+ let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
|
|
|
+
|
|
|
|
|
+ smol::block_on(async {
|
|
|
|
|
+ let settings = Settings {
|
|
|
|
|
+ localnet: false,
|
|
|
|
|
+ external_addrs: vec![
|
|
|
|
|
+ Url::parse("tcp://foo.bar:123").unwrap(),
|
|
|
|
|
+ Url::parse("tcp://lol.cat:321").unwrap(),
|
|
|
|
|
+ ],
|
|
|
|
|
+ ..Default::default()
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let hosts = Hosts::new(Arc::new(settings.clone()));
|
|
|
|
|
+ for addr in settings.external_addrs {
|
|
|
|
|
+ hosts.greylist_store(&addr, last_seen).await;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ let local_hosts = vec![
|
|
|
|
|
+ (Url::parse("tcp://localhost:3921").unwrap()),
|
|
|
|
|
+ (Url::parse("tor://[::1]:21481").unwrap()),
|
|
|
|
|
+ (Url::parse("tcp://192.168.10.65:311").unwrap()),
|
|
|
|
|
+ (Url::parse("tcp+tls://0.0.0.0:2312").unwrap()),
|
|
|
|
|
+ (Url::parse("tcp://255.255.255.255:2131").unwrap()),
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ for host in &local_hosts {
|
|
|
|
|
+ hosts.greylist_store(&host, last_seen).await;
|
|
|
|
|
+ }
|
|
|
|
|
+ assert!(hosts.is_empty_greylist().await);
|
|
|
|
|
+
|
|
|
|
|
+ let remote_hosts = vec![
|
|
|
|
|
+ (Url::parse("tcp://dark.fi:80").unwrap()),
|
|
|
|
|
+ (Url::parse("tcp://http.cat:401").unwrap()),
|
|
|
|
|
+ (Url::parse("tcp://foo.bar:111").unwrap()),
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ for host in &remote_hosts {
|
|
|
|
|
+ hosts.greylist_store(&host, last_seen).await;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ assert!(hosts.greylist_contains(&remote_hosts[0]).await);
|
|
|
|
|
+ assert!(hosts.greylist_contains(&remote_hosts[1]).await);
|
|
|
|
|
+ assert!(!hosts.greylist_contains(&remote_hosts[2]).await);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_whitelist_store() {
|
|
fn test_whitelist_store() {
|