From 3f39b3a1bab7711505909635da7007e3fd12e7fa Mon Sep 17 00:00:00 2001 From: constantoine Date: Wed, 5 Oct 2022 17:32:31 +0200 Subject: [PATCH] Add coverage for rfc.rs Signed-off-by: constantoine --- src/rfc.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/rfc.rs b/src/rfc.rs index 94dda8b..38a0ede 100644 --- a/src/rfc.rs +++ b/src/rfc.rs @@ -313,6 +313,21 @@ mod tests { assert!(totp.is_ok()); } + #[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() { @@ -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() + ) + } }