/// Checks for a honeypot. If this field is filled, fail the rest of the function
pub fn honeypot_check(honeypot: &Option<String>) -> Result<(), LemmyError> {
- if honeypot.is_some() {
+ if honeypot.is_some() && honeypot != &Some(String::new()) {
Err(LemmyError::from_message("honeypot_fail"))
} else {
Ok(())
#[cfg(test)]
mod tests {
- use crate::utils::password_length_check;
+ use crate::utils::{honeypot_check, password_length_check};
#[test]
#[rustfmt::skip]
assert!(password_length_check("short").is_err());
assert!(password_length_check("looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong").is_err());
}
+
+ #[test]
+ fn honeypot() {
+ assert!(honeypot_check(&None).is_ok());
+ assert!(honeypot_check(&Some(String::new())).is_ok());
+ assert!(honeypot_check(&Some("1".to_string())).is_err());
+ assert!(honeypot_check(&Some("message".to_string())).is_err());
+ }
}