Browse Source

Unit test for what's done of the open invite protocol so far

Ian Goldberg 4 years ago
parent
commit
99ff95dc44
1 changed files with 41 additions and 0 deletions
  1. 41 0
      src/lib.rs

+ 41 - 0
src/lib.rs

@@ -236,3 +236,44 @@ impl BridgeAuth {
 
 // The protocol modules
 pub mod open_invite;
+
+// Unit tests that require access to the testing-only function
+// BridgeLine::random()
+#[cfg(test)]
+mod tests {
+    use super::bridge_table::BridgeLine;
+    use super::*;
+
+    #[test]
+    fn test_open_invite() {
+        // Create a BridegDb
+        let bdb = BridgeDb::new(20);
+        // Create a BridgeAuth
+        let mut ba = BridgeAuth::new(bdb.pubkey);
+
+        // Make 20 buckets with one random bridge each
+        for _ in 0..20 {
+            let bucket: [BridgeLine; 3] =
+                [BridgeLine::random(), Default::default(), Default::default()];
+            ba.bridge_table.new_bucket(bucket);
+        }
+        // And 20 more with three random bridges each
+        for _ in 0..20 {
+            let bucket: [BridgeLine; 3] = [
+                BridgeLine::random(),
+                BridgeLine::random(),
+                BridgeLine::random(),
+            ];
+            ba.bridge_table.new_bucket(bucket);
+        }
+        // Create the encrypted bridge table
+        ba.bridge_table.encrypt_table();
+
+        // Issue an open invitation
+        let inv = bdb.invite();
+
+        // Use it to get a Lox credential
+        let (req, state) = open_invite::request(&inv);
+        let resp = ba.handle_open_invite(req);
+    }
+}