Skip to content

Commit

Permalink
Relax honeypot check (fixes #2595)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Nov 30, 2022
1 parent 41d4852 commit d7726f6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/api_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub fn site_description_length_check(description: &str) -> Result<(), LemmyError

/// 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("".to_string()) {
Err(LemmyError::from_message("honeypot_fail"))
} else {
Ok(())
Expand Down Expand Up @@ -724,7 +724,7 @@ pub fn listing_type_with_site_default(

#[cfg(test)]
mod tests {
use crate::utils::password_length_check;
use crate::utils::{honeypot_check, password_length_check};

#[test]
#[rustfmt::skip]
Expand All @@ -734,4 +734,12 @@ mod tests {
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("".to_string())).is_ok());
assert!(honeypot_check(&Some("1".to_string())).is_err());
assert!(honeypot_check(&Some("message".to_string())).is_err());
}
}

0 comments on commit d7726f6

Please sign in to comment.