From df549d0c99aaf4d40f4f680756da2ec9434436cd Mon Sep 17 00:00:00 2001 From: Raul Gherman Date: Sat, 7 Sep 2024 18:01:05 +0300 Subject: [PATCH] [3] --- kaminari/src/opt.rs | 151 -------------------------------------------- kaminari/src/tls.rs | 2 +- kaminari/src/ws.rs | 2 +- 3 files changed, 2 insertions(+), 153 deletions(-) diff --git a/kaminari/src/opt.rs b/kaminari/src/opt.rs index edec1f3..123bb2e 100644 --- a/kaminari/src/opt.rs +++ b/kaminari/src/opt.rs @@ -85,154 +85,3 @@ pub fn get_tls_client_conf(s: &str) -> Option { panic!("tls: require sni") } } - -#[cfg(test)] -#[cfg(any(feature = "ws", feature = "tls"))] -mod test { - use super::*; - - #[test] - #[cfg(feature = "ws")] - fn ws_conf() { - macro_rules! y { - ( $( ($s:expr, $host: expr, $path: expr); )+ )=> { - $( - assert_eq!(get_ws_conf($s), Some(WsConf{ - host: String::from($host), - path: String::from($path), - })); - )+ - } - } - - y![ - ("ws;host=a.b.c;path=/", "a.b.c", "/"); - ("ws;host=a.b.c;path=/abc", "a.b.c", "/abc"); - ("ws;path=/abc;host=a.b.c", "a.b.c", "/abc"); - ("ws;path=/abc;host=a.b.c;", "a.b.c", "/abc"); - ]; - } - - #[test] - #[should_panic] - #[cfg(feature = "ws")] - fn ws_conf_err() { - macro_rules! n { - ( $( $s: expr, )+ ) => {{ - $( - assert_eq!(get_ws_conf($s), None); - )+ - }} - } - - n![ - "ws", - "ws;", - "ws;host", - "ws;host=", - "ws;host=;", - "ws;host=a.b.c;", - "ws;host=a.b.c;path", - "ws;host=a.b.c;path=", - "ws;host=a.b.c;path=;", - ]; - } - - #[test] - #[cfg(feature = "tls")] - fn tls_client_conf() { - macro_rules! y { - ( $( ($s:expr, $sni: expr, $alpn: expr, $insecure: expr, $early_data: expr); )+ )=> { - $( - assert_eq!(get_tls_client_conf($s), Some(TlsClientConf{ - sni: String::from($sni), - alpn: $alpn.split(',').map(str::trim).map(Vec::from) - .filter(|v|!v.is_empty()).collect(), - insecure: $insecure, - early_data: $early_data, - })); - )+ - } - } - - y![ - ("tls;sni=a.b.c", "a.b.c", "", false, false); - ("tls;sni=a.b.c;alpn=h2", "a.b.c", "h2", false, false); - ("tls;sni=a.b.c;alpn=http/1.1;insecure", "a.b.c", "http/1.1", true, false); - ("tls;sni=a.b.c;alpn=h2,http/1.1;insecure;", "a.b.c", "h2,http/1.1", true, false); - ("tls;sni=a.b.c;alpn=h2,http/1.1;insecure;0rtt", "a.b.c", "h2,http/1.1", true, true); - ("tls;sni=a.b.c;alpn=h2,http/1.1;insecure;0rtt;" ,"a.b.c", "h2,http/1.1", true, true); - ]; - } - - #[test] - #[should_panic] - #[cfg(feature = "tls")] - fn tls_client_err() { - macro_rules! n { - ( $( $s: expr, )+ ) => {{ - $( - assert_eq!(get_tls_client_conf($s), None); - )+ - }} - } - - n!["", "tls", "tls;", "tls;sni", "tls;sni=", "tls;sni=;",]; - } - - #[test] - #[cfg(feature = "tls")] - fn tls_server_conf() { - macro_rules! y { - ( $( ($s:expr, $key: expr, $crt: expr, $server_name: expr); )+ )=> { - $( - assert_eq!(get_tls_server_conf($s), Some(TlsServerConf{ - key: String::from($key), - crt: String::from($crt), - ocsp: String::new(), - server_name: String::from($server_name), - })); - )+ - } - } - - y![ - ("tls;key=/a;cert=/b", "/a", "/b", ""); - ("tls;key=/a;cert=/b;", "/a", "/b", ""); - ("tls;key=/a;cert=/b;servername=;", "/a", "/b", ""); - - ("tls;servername=a.b.c", "", "", "a.b.c"); - ("tls;servername=a.b.c;", "", "", "a.b.c"); - ("tls;key=;cert=;servername=a.b.c", "", "", "a.b.c"); - - // this is expected - ("tls;key=/a;cert=/b;servername=a.b.c;", "/a", "/b", "a.b.c"); - ]; - } - - #[test] - #[should_panic] - #[cfg(feature = "tls")] - fn tls_server_err() { - macro_rules! n { - ( $( $s: expr, )+ ) => {{ - $( - assert_eq!(get_tls_server_conf($s), None); - )+ - }} - } - - n![ - "", - "tls", - "tls;", - "tls;key", - "tls;key=", - "tls;key=;", - "tls;key=/a;", - "tls;key=/a;cert", - "tls;key=/a;cert=", - "tls;key=/a;cert=;", - ]; - } -} diff --git a/kaminari/src/tls.rs b/kaminari/src/tls.rs index 6bfae68..f28d6a1 100644 --- a/kaminari/src/tls.rs +++ b/kaminari/src/tls.rs @@ -3,7 +3,7 @@ use std::future::Future; use std::sync::Arc; use std::fmt::{Debug, Display, Formatter}; -use super::{IOStream, AsyncAccept, AsyncConnect}; +use super::{IOStream, AsyncConnect}; use tokio_rustls::rustls; use rustls::client::ClientConfig; diff --git a/kaminari/src/ws.rs b/kaminari/src/ws.rs index 4040e6d..05727d2 100644 --- a/kaminari/src/ws.rs +++ b/kaminari/src/ws.rs @@ -3,7 +3,7 @@ use std::future::Future; use std::marker::PhantomData; use std::fmt::{Display, Formatter}; -use super::{IOStream, AsyncAccept, AsyncConnect}; +use super::{IOStream, AsyncConnect}; use lightws::endpoint::Endpoint; use lightws::role::{Server, Client, StandardClient, FixedMaskClient, ClientRole};