瀏覽代碼

Get back down to zero mutants killed

mutagen was pointing out three cases where the 'data' part of the packet was only one byte long, calculated by subtracting the length of the bytes parsed so far from the packet's stated length.

Although I admit these tests don't add much, having 100% mutation coverage is something I've found so useful, it's definitely worth the five minutes or so it took to write them.
Benjamin Sago 4 年之前
父節點
當前提交
459d7cd578
共有 3 個文件被更改,包括 55 次插入5 次删除
  1. 18 2
      dns/src/record/sshfp.rs
  2. 20 2
      dns/src/record/tlsa.rs
  3. 17 1
      dns/src/record/uri.rs

+ 18 - 2
dns/src/record/sshfp.rs

@@ -73,14 +73,30 @@ mod test {
         let buf = &[
             0x01,  // algorithm
             0x01,  // fingerprint type
-            0x21, 0x22, 0x23, 0x24,  // an extremely short fingerprint
+            0x21, 0x22, 0x23, 0x24, 0x25, 0x26,  // a short fingerprint
         ];
 
         assert_eq!(SSHFP::read(buf.len() as _, &mut Cursor::new(buf)).unwrap(),
                    SSHFP {
                        algorithm: 1,
                        fingerprint_type: 1,
-                       fingerprint: vec![ 0x21, 0x22, 0x23, 0x24 ],
+                       fingerprint: vec![ 0x21, 0x22, 0x23, 0x24, 0x25, 0x26 ],
+                   });
+    }
+
+    #[test]
+    fn one_byte_fingerprint() {
+        let buf = &[
+            0x01,  // algorithm
+            0x01,  // fingerprint type
+            0x21,  // an extremely short fingerprint
+        ];
+
+        assert_eq!(SSHFP::read(buf.len() as _, &mut Cursor::new(buf)).unwrap(),
+                   SSHFP {
+                       algorithm: 1,
+                       fingerprint_type: 1,
+                       fingerprint: vec![ 0x21 ],
                    });
     }
 

+ 20 - 2
dns/src/record/tlsa.rs

@@ -82,7 +82,7 @@ mod test {
             0x03,  // certificate usage
             0x01,  // selector
             0x01,  // matching type
-            0x05, 0x95, 0x98,  // data
+            0x05, 0x95, 0x98, 0x11, 0x22, 0x33 // data
         ];
 
         assert_eq!(TLSA::read(buf.len() as _, &mut Cursor::new(buf)).unwrap(),
@@ -90,7 +90,25 @@ mod test {
                        certificate_usage: 3,
                        selector: 1,
                        matching_type: 1,
-                       certificate_data: vec![ 0x05, 0x95, 0x98 ],
+                       certificate_data: vec![ 0x05, 0x95, 0x98, 0x11, 0x22, 0x33 ],
+                   });
+    }
+
+    #[test]
+    fn one_byte_certificate() {
+        let buf = &[
+            0x03,  // certificate usage
+            0x01,  // selector
+            0x01,  // matching type
+            0x05,  // one byte of data
+        ];
+
+        assert_eq!(TLSA::read(buf.len() as _, &mut Cursor::new(buf)).unwrap(),
+                   TLSA {
+                       certificate_usage: 3,
+                       selector: 1,
+                       matching_type: 1,
+                       certificate_data: vec![ 0x05 ],
                    });
     }
 

+ 17 - 1
dns/src/record/uri.rs

@@ -47,7 +47,7 @@ impl Wire for URI {
         }
 
         let remaining_length = stated_length - 4;
-        let mut buf = Vec::with_capacity(usize::from(remaining_length));
+        let mut buf = Vec::with_capacity(remaining_length.into());
 
         for _ in 0 .. remaining_length {
             buf.push(c.read_u8()?);
@@ -83,6 +83,22 @@ mod test {
                    });
     }
 
+    #[test]
+    fn one_byte_of_uri() {
+        let buf = &[
+            0x00, 0x0A,  // priority
+            0x00, 0x10,  // weight
+            0x2f,  // one byte of uri (invalid but still a legitimate DNS record)
+        ];
+
+        assert_eq!(URI::read(buf.len() as _, &mut Cursor::new(buf)).unwrap(),
+                   URI {
+                       priority: 10,
+                       weight: 16,
+                       target: String::from("/"),
+                   });
+    }
+
     #[test]
     fn missing_any_data() {
         let buf = &[