test formatter 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/src/url_error.rs b/src/url_error.rs
index 1318d06..0161587 100644
--- a/src/url_error.rs
+++ b/src/url_error.rs
@@ -94,7 +94,7 @@ impl std::fmt::Display for TotpUrlError {
#[cfg(feature = "otpauth")]
TotpUrlError::Url(e) => write!(
f,
- "Error parsing URL {}",
+ "Error parsing URL: {}",
e
)
}
@@ -108,4 +108,88 @@ impl From<Rfc6238Error> for TotpUrlError {
Rfc6238Error::SecretTooSmall(bits) => TotpUrlError::SecretSize(bits),
}
}
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::TotpUrlError;
+
+ #[test]
+ fn account_name() {
+ let error = TotpUrlError::AccountName("Laziz:".to_string());
+ assert_eq!(error.to_string(), "Account Name can't contain a colon. \"Laziz:\" contains a colon")
+ }
+
+ #[test]
+ fn account_name_decoding() {
+ let error = TotpUrlError::AccountNameDecoding("Laz&iz".to_string());
+ assert_eq!(error.to_string(), "Couldn't URL decode \"Laz&iz\"".to_string())
+ }
+
+ #[test]
+ fn algorithm() {
+ let error = TotpUrlError::Algorithm("SIKE".to_string());
+ assert_eq!(error.to_string(), "Algorithm can only be SHA1, SHA256 or SHA512, not \"SIKE\"".to_string())
+ }
+
+ #[test]
+ fn digits() {
+ let error = TotpUrlError::Digits("six".to_string());
+ assert_eq!(error.to_string(), "Could not parse \"six\" as a number.".to_string())
+ }
+
+ #[test]
+ fn digits_number() {
+ let error = TotpUrlError::DigitsNumber(5);
+ assert_eq!(error.to_string(), "Implementations MUST extract a 6-digit code at a minimum and possibly 7 and 8-digit code. 5 digits is not allowed".to_string())
+ }
+
+ #[test]
+ fn host() {
+ let error = TotpUrlError::Host("hotp".to_string());
+ assert_eq!(error.to_string(), "Host should be totp, not \"hotp\"".to_string())
+ }
+
+ #[test]
+ fn issuer() {
+ let error = TotpUrlError::Issuer("Iss:uer".to_string());
+ assert_eq!(error.to_string(), "Issuer can't contain a colon. \"Iss:uer\" contains a colon".to_string())
+ }
+
+ #[test]
+ fn issuer_decoding() {
+ let error = TotpUrlError::IssuerDecoding("iss&uer".to_string());
+ assert_eq!(error.to_string(), "Couldn't URL decode \"iss&uer\"".to_string())
+ }
+
+ #[test]
+ fn issuer_mismatch() {
+ let error = TotpUrlError::IssuerMistmatch("Google".to_string(), "Github".to_string());
+ assert_eq!(error.to_string(), "An issuer \"Google\" could be retrieved from the path, but a different issuer \"Github\" was found in the issuer URL parameter".to_string())
+ }
+
+ #[test]
+ fn scheme() {
+ let error = TotpUrlError::Scheme("https".to_string());
+ assert_eq!(error.to_string(), "Scheme should be otpauth, not \"https\"".to_string())
+ }
+
+ #[test]
+ fn secret() {
+ let error = TotpUrlError::Secret("YoLo".to_string());
+ assert_eq!(error.to_string(), "Secret \"YoLo\" is not a valid non-padded base32 string".to_string())
+ }
+
+ #[test]
+ fn secret_size() {
+ let error = TotpUrlError::SecretSize(112);
+ assert_eq!(error.to_string(), "The length of the shared secret MUST be at least 128 bits. 112 bits is not enough".to_string())
+ }
+
+ #[test]
+ #[cfg(feature = "otpauth")]
+ fn step() {
+ let error = TotpUrlError::Url(url::ParseError::EmptyHost);
+ assert_eq!(error.to_string(), "Error parsing URL: empty host".to_string())
+ }
}
\ No newline at end of file