Check login before logging it

This commit is contained in:
2024-02-19 19:11:13 +01:00
parent 75b70008e3
commit e71fad8546
7 changed files with 71 additions and 5 deletions

View File

@ -36,9 +36,14 @@ pub fn apply_env_vars(val: &str) -> String {
val
}
/// Check out whether a given login is acceptable or not
pub fn is_acceptable_login(login: &str) -> bool {
mailchecker::is_valid(login) || lazy_regex::regex!("^[a-zA-Z0-9-+]+$").is_match(login)
}
#[cfg(test)]
mod test {
use crate::utils::string_utils::apply_env_vars;
use crate::utils::string_utils::{apply_env_vars, is_acceptable_login};
use std::env;
const VAR_ONE: &str = "VAR_ONE";
@ -56,4 +61,12 @@ mod test {
let src = format!("This is ${{{}}}", VAR_INVALID);
assert_eq!(src, apply_env_vars(&src));
}
#[test]
fn test_is_acceptable_login() {
assert!(is_acceptable_login("admin"));
assert!(is_acceptable_login("someone@somewhere.fr"));
assert!(!is_acceptable_login("someone@somewhere.#fr"));
assert!(!is_acceptable_login("bad bad"));
}
}