Add coverage for rfc.rs Signed-off-by: constantoine <cleo.rebert-ext@treezor.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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()
+ )
+ }
}