username_case_mapeed regex correction: match only included chars

This commit is contained in:
Aravinth Manivannan 2021-06-29 19:21:15 +05:30
parent 66d42bfd1d
commit 3330634832
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 26 additions and 3 deletions

View file

@ -83,6 +83,7 @@ impl Config {
.collect::<String>() .collect::<String>()
.trim() .trim()
.to_owned(); .to_owned();
self.validate_username(&clean_username)?; self.validate_username(&clean_username)?;
Ok(clean_username) Ok(clean_username)
} }
@ -216,6 +217,22 @@ mod tests {
assert!(Config::verify(&hash, password).unwrap(), "verify hahsing"); assert!(Config::verify(&hash, password).unwrap(), "verify hahsing");
} }
#[test]
fn username_case_mapped_org() {
let config = ConfigBuilder::default()
.username_case_mapped(true)
.profanity(true)
.blacklist(false)
.password_policy(PasswordPolicy::default())
.build()
.unwrap();
config.init();
let username_err = config.username("a@test.com");
assert_eq!(username_err, Err(CredsError::UsernameCaseMappedError));
}
#[test] #[test]
fn utils_create_new_profane_organisation() { fn utils_create_new_profane_organisation() {
let config = ConfigBuilder::default() let config = ConfigBuilder::default()
@ -236,7 +253,7 @@ mod tests {
fn utils_create_new_forbidden_organisation() { fn utils_create_new_forbidden_organisation() {
let config = Config::default(); let config = Config::default();
config.init(); config.init();
let forbidden_err = config.username(".htaccess"); let forbidden_err = config.username("webmaster");
assert_eq!(forbidden_err, Err(CredsError::BlacklistError)); assert_eq!(forbidden_err, Err(CredsError::BlacklistError));
} }

File diff suppressed because one or more lines are too long