From 0f903435381e953a3bbe959011ec75e16529d990 Mon Sep 17 00:00:00 2001 From: Tjemmmic Date: Sun, 21 Apr 2024 23:36:28 -0500 Subject: [PATCH] P2P PSK negative test incomplete --- citadel-internal-service/tests/service.rs | 83 +++++++++++++++-------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/citadel-internal-service/tests/service.rs b/citadel-internal-service/tests/service.rs index e027263..0dd59dc 100644 --- a/citadel-internal-service/tests/service.rs +++ b/citadel-internal-service/tests/service.rs @@ -614,67 +614,96 @@ mod tests { let (ref mut peer_b_sink, ref mut peer_b_stream, peer_b_cid) = &mut second[0]; // Peer B Initiates Peer Registration + info!(target: "citadel", "Peer B Sending First Register Request"); let peer_register = InternalServiceRequest::PeerRegister { request_id: Uuid::new_v4(), cid: *peer_b_cid, peer_cid: *peer_a_cid, session_security_settings: Default::default(), connect_after_register: false, - peer_session_password: Some(PreSharedKey::from("PeerSessionPassword".as_bytes())), + peer_session_password: None,//Some(PreSharedKey::from("PeerSessionPassword".as_bytes())), }; peer_b_sink.send(peer_register).unwrap(); - let _register_request_success = peer_b_stream.recv().await.unwrap(); + + info!(target: "citadel", "Peer A Waiting to Receive Register Notification"); let _register_request_notification = peer_a_stream.recv().await.unwrap(); - // Peer Register WITHOUT PSK when it is expected + // Peer Register with Correct PSK when it is expected + info!(target: "citadel", "Peer A Sending Register Request with Correct PSK"); let peer_register = InternalServiceRequest::PeerRegister { request_id: Uuid::new_v4(), cid: *peer_a_cid, peer_cid: *peer_b_cid, session_security_settings: Default::default(), connect_after_register: false, - peer_session_password: None, + peer_session_password: None,//Some(PreSharedKey::from("PeerSessionPassword".as_bytes())), }; peer_a_sink.send(peer_register).unwrap(); + info!(target: "citadel", "Peer A Waiting for Register Response"); let inbound_response = peer_a_stream.recv().await.unwrap(); - if let InternalServiceResponse::PeerRegisterFailure(..) = inbound_response { - info!(target: "citadel", "Peer Registration Failed as expected - no Peer Session Password Supplied"); + if let InternalServiceResponse::PeerRegisterSuccess(..) = inbound_response { + info!(target: "citadel", "Peer A Received Register Response"); } else { - panic!("Peer Registration Unexpectedly Succeeded"); + panic!("Peer Registration Unexpectedly Failed with correct Peer Register"); } - // Peer Register with INCORRECT PSK when it is expected - let peer_register = InternalServiceRequest::PeerRegister { + let _register_request_response = peer_b_stream.recv().await.unwrap(); + + // Peer B Initiates Peer Registration + info!(target: "citadel", "Peer B Sending First Connect Request"); + let peer_connect = InternalServiceRequest::PeerConnect { request_id: Uuid::new_v4(), - cid: *peer_a_cid, - peer_cid: *peer_b_cid, + cid: *peer_b_cid, + peer_cid: *peer_a_cid, + udp_mode: Default::default(), session_security_settings: Default::default(), - connect_after_register: false, - peer_session_password: Some(PreSharedKey::from("IncorrectPassword".as_bytes())), + peer_session_password: Some(PreSharedKey::from("PeerSessionPassword".as_bytes())), }; - peer_a_sink.send(peer_register).unwrap(); - let inbound_response = peer_a_stream.recv().await.unwrap(); - if let InternalServiceResponse::PeerRegisterFailure(..) = inbound_response { - info!(target: "citadel", "Peer Registration Failed as expected - Incorrect Peer Session Password Supplied"); - } else { - panic!("Peer Registration Unexpectedly Succeeded"); - } + peer_b_sink.send(peer_connect).unwrap(); - // Peer Register with Correct PSK when it is expected - let peer_register = InternalServiceRequest::PeerRegister { + info!(target: "citadel", "Peer A Waiting to Receive Connect Notification"); + let _register_connect_notification = peer_a_stream.recv().await.unwrap(); + + // Peer Responds with Connect Request WITHOUT PSK that is expected + info!(target: "citadel", "Peer A Sending Connect Request without expected PSK"); + let peer_connect = InternalServiceRequest::PeerConnect { request_id: Uuid::new_v4(), cid: *peer_a_cid, peer_cid: *peer_b_cid, + udp_mode: Default::default(), session_security_settings: Default::default(), - connect_after_register: false, - peer_session_password: Some(PreSharedKey::from("PeerSessionPassword".as_bytes())), + peer_session_password: None, }; - peer_a_sink.send(peer_register).unwrap(); + peer_a_sink.send(peer_connect).unwrap(); + info!(target: "citadel", "Peer A Waiting for Connect Response"); let inbound_response = peer_a_stream.recv().await.unwrap(); - if let InternalServiceResponse::PeerRegisterSuccess(..) = inbound_response { - panic!("Peer Registration Unexpectedly Failed with correct Peer Register"); + if let InternalServiceResponse::PeerConnectFailure(..) = inbound_response { + info!(target: "citadel", "Peer A Failed to Connect as Expected"); + } else { + panic!("Peer Connection Unexpectedly Succeeded with incorrect Peer Session Password"); } + // // Peer Responds with Connect Request with INCORRECT PSK that is expected + // info!(target: "citadel", "Peer A Sending Connect Request with Incorrect PSK"); + // let peer_connect = InternalServiceRequest::PeerConnect { + // request_id: Uuid::new_v4(), + // cid: *peer_a_cid, + // peer_cid: *peer_b_cid, + // udp_mode: Default::default(), + // session_security_settings: Default::default(), + // peer_session_password: Some(PreSharedKey::from("IncorrectPassword".as_bytes())), + // }; + // peer_a_sink.send(peer_connect).unwrap(); + // info!(target: "citadel", "Peer A Waiting for Connect Response"); + // let inbound_response = peer_a_stream.recv().await.unwrap(); + // if let InternalServiceResponse::PeerConnectFailure(..) = inbound_response { + // info!(target: "citadel", "Peer A Failed to Connect as Expected"); + // } else { + // panic!("Peer Connection Unexpectedly Succeeded with incorrect Peer Session Password"); + // } + + let _register_request_response = peer_b_stream.recv().await.unwrap(); + Ok(()) }