Skip to content

Commit

Permalink
P2P PSK negative test incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjemmmic committed Apr 22, 2024
1 parent c670e3e commit 0f90343
Showing 1 changed file with 56 additions and 27 deletions.
83 changes: 56 additions & 27 deletions citadel-internal-service/tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down

0 comments on commit 0f90343

Please sign in to comment.