Skip to content

Commit

Permalink
Fix TLS and Quic test failures due to subsequent sessions on same por…
Browse files Browse the repository at this point in the history
…t number
  • Loading branch information
oteffahi committed May 29, 2024
1 parent f91e885 commit 2714ced
Showing 1 changed file with 51 additions and 53 deletions.
104 changes: 51 additions & 53 deletions zenoh/tests/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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::<EndPoint>().unwrap()]);
let mut config = config::client([format!("tls/127.0.0.1:{}", port)
.parse::<EndPoint>()
.unwrap()]);
config
.insert_json5(
"transport",
Expand All @@ -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::<EndPoint>().unwrap()]);
let mut config = config::client([format!("tls/127.0.0.1:{}", port)
.parse::<EndPoint>()
.unwrap()]);
config
.insert_json5(
"transport",
Expand All @@ -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::<EndPoint>().unwrap()]);
let mut config = config::client([format!("quic/127.0.0.1:{}", port)
.parse::<EndPoint>()
.unwrap()]);
config
.insert_json5(
"transport",
Expand All @@ -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::<EndPoint>().unwrap()]);
let mut config = config::client([format!("quic/127.0.0.1:{}", port)
.parse::<EndPoint>()
.unwrap()]);
config
.insert_json5(
"transport",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()));
Expand All @@ -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",
Expand Down Expand Up @@ -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()));
Expand All @@ -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",
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()));
Expand All @@ -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",
Expand Down Expand Up @@ -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()));
Expand All @@ -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",
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 2714ced

Please sign in to comment.