diff --git a/zenoh/tests/authentication.rs b/zenoh/tests/authentication.rs index bec7aac262..2f16b49735 100644 --- a/zenoh/tests/authentication.rs +++ b/zenoh/tests/authentication.rs @@ -38,28 +38,18 @@ mod test { test_pub_sub_allow_then_deny_usrpswd().await; test_get_qbl_allow_then_deny_usrpswd().await; test_get_qbl_deny_then_allow_usrpswd().await; - tokio::time::sleep(Duration::from_secs(2)).await; - test_pub_sub_deny_then_allow_tls().await; - tokio::time::sleep(Duration::from_secs(2)).await; + test_pub_sub_deny_then_allow_tls(3774).await; + test_pub_sub_allow_then_deny_tls(3775).await; + test_get_qbl_allow_then_deny_tls(3776).await; + test_get_qbl_deny_then_allow_tls(3777).await; - test_pub_sub_allow_then_deny_tls().await; - tokio::time::sleep(Duration::from_secs(2)).await; + test_pub_sub_deny_then_allow_quic(3774).await; + test_pub_sub_allow_then_deny_quic(3775).await; + test_get_qbl_deny_then_allow_quic(3776).await; + test_get_qbl_allow_then_deny_quic(3777).await; - test_get_qbl_allow_then_deny_tls().await; - tokio::time::sleep(Duration::from_secs(2)).await; - - test_get_qbl_deny_then_allow_tls().await; - tokio::time::sleep(Duration::from_secs(2)).await; - - test_pub_sub_deny_then_allow_quic().await; - // test_get_qbl_allow_then_deny_quic().await; - // test_pub_sub_allow_then_deny_quic().await; - // test_get_qbl_deny_then_allow_quic().await; - - use std::fs::remove_dir_all; - tokio::time::sleep(Duration::from_secs(1)).await; - remove_dir_all(path).unwrap(); + std::fs::remove_dir_all(path).unwrap(); println!("testfiles removed successfully."); } @@ -237,10 +227,10 @@ client2name:client2passwd"; Ok(()) } - async fn get_basic_router_config_tls() -> Config { + async fn get_basic_router_config_tls(port: u16) -> Config { let mut config = config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); - config.listen.endpoints = vec!["tls/127.0.0.1:37447".parse().unwrap()]; + config.listen.endpoints = vec![format!("tls/127.0.0.1:{}", port).parse().unwrap()]; config.scouting.multicast.set_enabled(Some(false)).unwrap(); config .insert_json5( @@ -263,10 +253,10 @@ client2name:client2passwd"; .unwrap(); config } - async fn get_basic_router_config_quic() -> Config { + async fn get_basic_router_config_quic(port: u16) -> Config { let mut config = config::default(); config.set_mode(Some(WhatAmI::Router)).unwrap(); - config.listen.endpoints = vec!["quic/127.0.0.1:37447".parse().unwrap()]; + config.listen.endpoints = vec![format!("quic/127.0.0.1:{}", port).parse().unwrap()]; config.scouting.multicast.set_enabled(Some(false)).unwrap(); config .insert_json5( @@ -316,9 +306,11 @@ client2name:client2passwd"; ztimeout!(s.close()).unwrap(); } - async fn get_client_sessions_tls() -> (Session, Session) { + async fn get_client_sessions_tls(port: u16) -> (Session, Session) { println!("Opening client sessions"); - let mut config = config::client(["tls/127.0.0.1:37447".parse::().unwrap()]); + let mut config = config::client([format!("tls/127.0.0.1:{}", port) + .parse::() + .unwrap()]); config .insert_json5( "transport", @@ -339,7 +331,9 @@ client2name:client2passwd"; ) .unwrap(); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::client(["tls/127.0.0.1:37447".parse::().unwrap()]); + let mut config = config::client([format!("tls/127.0.0.1:{}", port) + .parse::() + .unwrap()]); config .insert_json5( "transport", @@ -363,9 +357,11 @@ client2name:client2passwd"; (s01, s02) } - async fn get_client_sessions_quic() -> (Session, Session) { + async fn get_client_sessions_quic(port: u16) -> (Session, Session) { println!("Opening client sessions"); - let mut config = config::client(["quic/127.0.0.1:37447".parse::().unwrap()]); + let mut config = config::client([format!("quic/127.0.0.1:{}", port) + .parse::() + .unwrap()]); config .insert_json5( "transport", @@ -386,7 +382,9 @@ client2name:client2passwd"; ) .unwrap(); let s01 = ztimeout!(zenoh::open(config)).unwrap(); - let mut config = config::client(["quic/127.0.0.1:37447".parse::().unwrap()]); + let mut config = config::client([format!("quic/127.0.0.1:{}", port) + .parse::() + .unwrap()]); config .insert_json5( "transport", @@ -454,10 +452,10 @@ client2name:client2passwd"; ztimeout!(s02.close()).unwrap(); } - async fn test_pub_sub_deny_then_allow_tls() { + async fn test_pub_sub_deny_then_allow_tls(port: u16) { println!("test_pub_sub_deny_then_allow_tls"); - let mut config_router = get_basic_router_config_tls().await; + let mut config_router = get_basic_router_config_tls(port).await; config_router .insert_json5( @@ -490,7 +488,7 @@ client2name:client2passwd"; let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (sub_session, pub_session) = get_client_sessions_tls().await; + let (sub_session, pub_session) = get_client_sessions_tls(port).await; { let publisher = pub_session.declare_publisher(KEY_EXPR).await.unwrap(); let received_value = Arc::new(Mutex::new(String::new())); @@ -514,9 +512,9 @@ client2name:client2passwd"; close_router_session(session).await; } - async fn test_pub_sub_allow_then_deny_tls() { + async fn test_pub_sub_allow_then_deny_tls(port: u16) { println!("test_pub_sub_allow_then_deny_tls"); - let mut config_router = get_basic_router_config_tls().await; + let mut config_router = get_basic_router_config_tls(port).await; config_router .insert_json5( "access_control", @@ -547,7 +545,7 @@ client2name:client2passwd"; println!("Opening router session"); let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (sub_session, pub_session) = get_client_sessions_tls().await; + let (sub_session, pub_session) = get_client_sessions_tls(port).await; { let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR)).unwrap(); let received_value = Arc::new(Mutex::new(String::new())); @@ -573,10 +571,10 @@ client2name:client2passwd"; close_router_session(session).await; } - async fn test_get_qbl_deny_then_allow_tls() { + async fn test_get_qbl_deny_then_allow_tls(port: u16) { println!("test_get_qbl_deny_then_allow_tls"); - let mut config_router = get_basic_router_config_tls().await; + let mut config_router = get_basic_router_config_tls(port).await; config_router .insert_json5( "access_control", @@ -608,7 +606,7 @@ client2name:client2passwd"; let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (get_session, qbl_session) = get_client_sessions_tls().await; + let (get_session, qbl_session) = get_client_sessions_tls(port).await; { let mut received_value = String::new(); @@ -647,10 +645,10 @@ client2name:client2passwd"; close_router_session(session).await; } - async fn test_get_qbl_allow_then_deny_tls() { + async fn test_get_qbl_allow_then_deny_tls(port: u16) { println!("test_get_qbl_allow_then_deny_tls"); - let mut config_router = get_basic_router_config_tls().await; + let mut config_router = get_basic_router_config_tls(port).await; config_router .insert_json5( "access_control", @@ -681,7 +679,7 @@ client2name:client2passwd"; let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (get_session, qbl_session) = get_client_sessions_tls().await; + let (get_session, qbl_session) = get_client_sessions_tls(port).await; { let mut received_value = String::new(); @@ -720,10 +718,10 @@ client2name:client2passwd"; close_router_session(session).await; } - async fn test_pub_sub_deny_then_allow_quic() { + async fn test_pub_sub_deny_then_allow_quic(port: u16) { println!("test_pub_sub_deny_then_allow_quic"); - let mut config_router = get_basic_router_config_quic().await; + let mut config_router = get_basic_router_config_quic(port).await; config_router .insert_json5( @@ -756,7 +754,7 @@ client2name:client2passwd"; let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (sub_session, pub_session) = get_client_sessions_quic().await; + let (sub_session, pub_session) = get_client_sessions_quic(port).await; { let publisher = pub_session.declare_publisher(KEY_EXPR).await.unwrap(); let received_value = Arc::new(Mutex::new(String::new())); @@ -781,10 +779,10 @@ client2name:client2passwd"; } #[allow(unused)] - async fn test_pub_sub_allow_then_deny_quic() { + async fn test_pub_sub_allow_then_deny_quic(port: u16) { println!("test_pub_sub_allow_then_deny_quic"); - let mut config_router = get_basic_router_config_quic().await; + let mut config_router = get_basic_router_config_quic(port).await; config_router .insert_json5( "access_control", @@ -815,7 +813,7 @@ client2name:client2passwd"; println!("Opening router session"); let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (sub_session, pub_session) = get_client_sessions_quic().await; + let (sub_session, pub_session) = get_client_sessions_quic(port).await; { let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR)).unwrap(); let received_value = Arc::new(Mutex::new(String::new())); @@ -842,10 +840,10 @@ client2name:client2passwd"; } #[allow(unused)] - async fn test_get_qbl_deny_then_allow_quic() { + async fn test_get_qbl_deny_then_allow_quic(port: u16) { println!("test_get_qbl_deny_then_allow_quic"); - let mut config_router = get_basic_router_config_quic().await; + let mut config_router = get_basic_router_config_quic(port).await; config_router .insert_json5( "access_control", @@ -877,7 +875,7 @@ client2name:client2passwd"; let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (get_session, qbl_session) = get_client_sessions_quic().await; + let (get_session, qbl_session) = get_client_sessions_quic(port).await; { let mut received_value = String::new(); @@ -917,10 +915,10 @@ client2name:client2passwd"; } #[allow(unused)] - async fn test_get_qbl_allow_then_deny_quic() { + async fn test_get_qbl_allow_then_deny_quic(port: u16) { println!("test_get_qbl_allow_then_deny_quic"); - let mut config_router = get_basic_router_config_quic().await; + let mut config_router = get_basic_router_config_quic(port).await; config_router .insert_json5( "access_control", @@ -951,7 +949,7 @@ client2name:client2passwd"; let session = ztimeout!(zenoh::open(config_router)).unwrap(); - let (get_session, qbl_session) = get_client_sessions_quic().await; + let (get_session, qbl_session) = get_client_sessions_quic(port).await; { let mut received_value = String::new();