Skip to content

Commit

Permalink
[3]
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-gherman committed Sep 7, 2024
1 parent 684a520 commit df549d0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 153 deletions.
151 changes: 0 additions & 151 deletions kaminari/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,154 +85,3 @@ pub fn get_tls_client_conf(s: &str) -> Option<TlsClientConf> {
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=;",
];
}
}
2 changes: 1 addition & 1 deletion kaminari/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion kaminari/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit df549d0

Please sign in to comment.