Commit 3f39b3a1bab7711505909635da7007e3fd12e7fa

constantoine 2022-10-05T17:32:31

Add coverage for rfc.rs Signed-off-by: constantoine <cleo.rebert-ext@treezor.com>

diff --git a/src/rfc.rs b/src/rfc.rs
index 94dda8b..38a0ede 100644
--- a/src/rfc.rs
+++ b/src/rfc.rs
@@ -314,6 +314,21 @@ mod tests {
     }
 
     #[test]
+    #[cfg(feature = "otpauth")]
+    fn rfc_with_default_set_values() {
+        let mut rfc = Rfc6238::with_defaults(GOOD_SECRET.to_string()).unwrap();
+        let ok = rfc.digits(8);
+        assert!(ok.is_ok());
+        assert_eq!(rfc.account_name, "");
+        assert_eq!(rfc.issuer, Some("".to_string()));
+        rfc.issuer("Github".to_string());
+        rfc.account_name("constantoine".to_string());
+        assert_eq!(rfc.account_name, "constantoine");
+        assert_eq!(rfc.issuer, Some("Github".to_string()));
+        assert_eq!(rfc.digits, 8)
+    }
+
+    #[test]
     #[cfg(not(feature = "otpauth"))]
     fn rfc_with_default_set_values() {
         let mut rfc = Rfc6238::with_defaults(GOOD_SECRET.to_string()).unwrap();
@@ -325,4 +340,24 @@ mod tests {
         assert!(ok.is_ok());
         assert_eq!(rfc.digits, 8)
     }
+
+    #[test]
+    #[cfg(not(feature = "otpauth"))]
+    fn digits_error() {
+        let error = crate::Rfc6238Error::InvalidDigits(9);
+        assert_eq!(
+            error.to_string(),
+            "Implementations MUST extract a 6-digit code at a minimum and possibly 7 and 8-digit code. 9 digits is not allowed".to_string()
+        )
+    }
+
+    #[test]
+    #[cfg(not(feature = "otpauth"))]
+    fn secret_length_error() {
+        let error = Rfc6238Error::SecretTooSmall(120);
+        assert_eq!(
+            error.to_string(),
+            "The length of the shared secret MUST be at least 128 bits. 120 bits is not enough".to_string()
+        )
+    }
 }