Skip to content

Commit

Permalink
Add noise initiator/responder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pool2win committed Jun 12, 2024
1 parent 15ad407 commit 7800773
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/node/noise_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ impl NoiseHandler {
mod tests {

use super::NoiseHandler;
use tokio_util::bytes::Bytes;

static TEST_KEY: &str = "
-----BEGIN PRIVATE KEY-----
MFECAQEwBQYDK2VwBCIEIJ7pILqR7yBPsVuysfGyofjOEm19skmtqcJYWiVwjKH1
Expand All @@ -208,10 +210,23 @@ gSEA68zeZuy7PMMQC9ECPmWqDl5AOFj5bi243F823ZVWtXY=
";

#[test]
fn it_buids_noise_helper() {
fn it_builds_noise_handler() {
let handler = NoiseHandler::new(true, TEST_KEY.to_string());
assert!(handler.initiator);
assert!(handler.handshake_state.is_some());
assert!(handler.transport_state.is_none());
}

#[test]
fn it_builds_initiator_noise_handler() {
let mut handler = NoiseHandler::new(true, TEST_KEY.to_string());
let noise_message: Bytes = handler.build_handshake_message(b"test bytes");
let len = noise_message.len();
assert_eq!(&noise_message[(len - 10)..], b"test bytes");

let mut responder = NoiseHandler::new(false, TEST_KEY.to_string());
let read_message: Bytes = responder.read_handshake_message(noise_message);
let len = read_message.len();
assert_eq!(&read_message[(len - 10)..], b"test bytes");
}
}

0 comments on commit 7800773

Please sign in to comment.