summary history branches tags files
commit:9d6ab603686f0dae139edf49b7fa91e41b10755c
author:Trevor Bentley
committer:Trevor Bentley
date:Thu May 23 17:58:00 2019 +0200
parents:2f3b59f9022c973a34603ce6a6cdac8a43f8ec61
Light documentation for test cases
diff --git a/tests/basic.rs b/tests/basic.rs
line changes: +7/-0
index 9b87ca7..966ff9a
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -1,3 +1,10 @@
+// basic.rs
+//
+// Basic test of Ossuary communication library, without authentication
+//
+// Establishes a non-authenticated session between a client and server over a
+// TCP connection, and exchanges encrypted messages.
+//
 use ossuary::{OssuaryConnection, ConnectionType};
 use ossuary::OssuaryError;
 

diff --git a/tests/basic_auth.rs b/tests/basic_auth.rs
line changes: +8/-0
index ffcb9db..c1a74d4
--- a/tests/basic_auth.rs
+++ b/tests/basic_auth.rs
@@ -1,3 +1,11 @@
+// basic_auth.rs
+//
+// Basic test of Ossuary communication library, with authentication
+//
+// Establishes a authenticated session between a client and server over a TCP
+// connection, and exchanges encrypted messages.  Both client and server only
+// accept connections from each other, authenticated with known keys.
+//
 use ossuary::{OssuaryConnection, ConnectionType};
 use ossuary::OssuaryError;
 

diff --git a/tests/clib_ffi.rs b/tests/clib_ffi.rs
line changes: +11/-0
index dc1fb3a..87f5349
--- a/tests/clib_ffi.rs
+++ b/tests/clib_ffi.rs
@@ -1,3 +1,8 @@
+// clib_ffi.rs
+//
+// Tests the C FFI interface from Rust.
+// Performs handshake and exchanges a few messages.
+//
 use ossuary::clib::{
     ossuary_create_connection,
     ossuary_destroy_connection,
@@ -69,6 +74,7 @@ fn server() -> Result<(), std::io::Error> {
             &mut out_len);
         let _ = stream.write_all(&out_buf[0..sz as usize]).unwrap();
 
+        let mut msgs = Vec::<String>::new();
         let in_buf = reader.fill_buf().unwrap();
         if in_buf.len() > 0 {
             let mut out_len = out_buf.len() as u16;
@@ -80,9 +86,11 @@ fn server() -> Result<(), std::io::Error> {
             if len != -1 {
                 println!("CLIB READ: {:?}",
                          std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap());
+                msgs.push(std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap().into());
                 reader.consume(len as usize);
             }
         }
+        assert_eq!(msgs, vec!("from client".to_string()));
 
         ossuary_destroy_connection(&mut conn);
         break;
@@ -142,6 +150,7 @@ fn client() -> Result<(), std::io::Error> {
 
     //let mut stream = std::io::BufReader::new(stream);
     let mut count = 0;
+    let mut msgs = Vec::<String>::new();
     loop {
         let in_buf = reader.fill_buf().unwrap();
         if in_buf.len() == 0 || count == 2 {
@@ -159,10 +168,12 @@ fn client() -> Result<(), std::io::Error> {
         if len > 0 {
             println!("CLIB READ: {:?}",
                      std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap());
+            msgs.push(std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap().into());
             reader.consume(len as usize);
             count += 1;
         }
     }
+    assert_eq!(msgs, vec!("from server 1".to_string(), "from server 2".to_string()));
 
     ossuary_destroy_connection(&mut conn);
     Ok(())

diff --git a/tests/corruption.rs b/tests/corruption.rs
line changes: +26/-13
index 8d9dffe..0048a0e
--- a/tests/corruption.rs
+++ b/tests/corruption.rs
@@ -1,21 +1,30 @@
+// corruption.rs
+//
+// Test cases for Ossuary handshakes with packet corruption
+//
+// Runs through a bunch of rounds of connection handshaking with corrupted data
+// injected at known points throughout the handshake.  Verifies that the correct
+// errors are raised, and that the connection either retries successfully or
+// fails permanently depending on the test.
+//
 use ossuary::{OssuaryConnection, ConnectionType};
 use ossuary::OssuaryError;
 
+#[derive(Debug)]
+enum Corruption {
+    ClientKey,
+    ClientNonce,
+    ClientChal,
+    ClientAuth,
+    ClientInvalidPkt,
+    ServerKey,
+    ServerNonce,
+    ServerAuth,
+    ServerInvalidPkt,
+}
+
 #[test]
 fn corruption() {
-    #[derive(Debug)]
-    enum Corruption {
-        ClientKey,
-        ClientNonce,
-        ClientChal,
-        ClientAuth,
-        ClientInvalidPkt,
-        ServerKey,
-        ServerNonce,
-        ServerAuth,
-        ServerInvalidPkt,
-    };
-
     // Corruption test tuple format:
     // (test type, loop iteration, byte offset, byte value, expected recv error, permanent)
     let corruptions = [
@@ -51,6 +60,7 @@ fn corruption() {
         LoopClient,
         LoopServer,
     };
+
     for corruption in &corruptions {
         println!("Corruption test: {:?}", corruption.0);
         let server_secret_key = &[
@@ -128,6 +138,9 @@ fn corruption() {
                     _ => panic!("Handshake failed: {:?}", e),
                 },
             }
+            // Check if handshake is done and call recv_data because recv_handshake()
+            // does not respond to connection resets after the connection is (thought
+            // to be) established.
             match send_conn.handshake_done() {
                 Ok(true) => {
                     let mut plaintext = Vec::<u8>::new();