fix test following ldap udpate
Reviewed-on: https://git.joinplu.me/Plume/Plume/pulls/828 Reviewed-by: Mina Galić <me+git@igalic.co>
This commit is contained in:
commit
0cd26dfbf4
@ -252,7 +252,8 @@ pub struct LdapConfig {
|
|||||||
fn get_ldap_config() -> Option<LdapConfig> {
|
fn get_ldap_config() -> Option<LdapConfig> {
|
||||||
let addr = var("LDAP_ADDR").ok();
|
let addr = var("LDAP_ADDR").ok();
|
||||||
let base_dn = var("LDAP_BASE_DN").ok();
|
let base_dn = var("LDAP_BASE_DN").ok();
|
||||||
if addr.is_some() && base_dn.is_some() {
|
match (addr, base_dn) {
|
||||||
|
(Some(addr), Some(base_dn)) => {
|
||||||
let tls = var("LDAP_TLS").unwrap_or_else(|_| "false".to_owned());
|
let tls = var("LDAP_TLS").unwrap_or_else(|_| "false".to_owned());
|
||||||
let tls = match tls.as_ref() {
|
let tls = match tls.as_ref() {
|
||||||
"1" | "true" | "TRUE" => true,
|
"1" | "true" | "TRUE" => true,
|
||||||
@ -262,16 +263,17 @@ fn get_ldap_config() -> Option<LdapConfig> {
|
|||||||
let user_name_attr = var("LDAP_USER_NAME_ATTR").unwrap_or_else(|_| "cn".to_owned());
|
let user_name_attr = var("LDAP_USER_NAME_ATTR").unwrap_or_else(|_| "cn".to_owned());
|
||||||
let mail_attr = var("LDAP_USER_MAIL_ATTR").unwrap_or_else(|_| "mail".to_owned());
|
let mail_attr = var("LDAP_USER_MAIL_ATTR").unwrap_or_else(|_| "mail".to_owned());
|
||||||
Some(LdapConfig {
|
Some(LdapConfig {
|
||||||
addr: addr.unwrap(),
|
addr,
|
||||||
base_dn: base_dn.unwrap(),
|
base_dn,
|
||||||
tls,
|
tls,
|
||||||
user_name_attr,
|
user_name_attr,
|
||||||
mail_attr,
|
mail_attr,
|
||||||
})
|
})
|
||||||
} else if addr.is_some() || base_dn.is_some() {
|
}
|
||||||
|
(None, None) => None,
|
||||||
|
(_, _) => {
|
||||||
panic!("Invalid LDAP configuration : both LDAP_ADDR and LDAP_BASE_DN must be set")
|
panic!("Invalid LDAP configuration : both LDAP_ADDR and LDAP_BASE_DN must be set")
|
||||||
} else {
|
}
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ impl User {
|
|||||||
for entry in search.0 {
|
for entry in search.0 {
|
||||||
let entry = SearchEntry::construct(entry);
|
let entry = SearchEntry::construct(entry);
|
||||||
let email = entry.attrs.get("mail").and_then(|vec| vec.first());
|
let email = entry.attrs.get("mail").and_then(|vec| vec.first());
|
||||||
if email.is_some() {
|
if let Some(email) = email {
|
||||||
let _ = ldap_conn.unbind();
|
let _ = ldap_conn.unbind();
|
||||||
return NewUser::new_local(
|
return NewUser::new_local(
|
||||||
conn,
|
conn,
|
||||||
@ -330,7 +330,7 @@ impl User {
|
|||||||
name.to_owned(),
|
name.to_owned(),
|
||||||
Role::Normal,
|
Role::Normal,
|
||||||
"",
|
"",
|
||||||
email.unwrap().to_owned(),
|
email.to_owned(),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1149,7 +1149,7 @@ pub(crate) mod tests {
|
|||||||
Role::Admin,
|
Role::Admin,
|
||||||
"Hello there, I'm the admin",
|
"Hello there, I'm the admin",
|
||||||
"admin@example.com".to_owned(),
|
"admin@example.com".to_owned(),
|
||||||
"invalid_admin_password".to_owned(),
|
Some("invalid_admin_password".to_owned()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let user = NewUser::new_local(
|
let user = NewUser::new_local(
|
||||||
@ -1159,7 +1159,7 @@ pub(crate) mod tests {
|
|||||||
Role::Normal,
|
Role::Normal,
|
||||||
"Hello there, I'm no one",
|
"Hello there, I'm no one",
|
||||||
"user@example.com".to_owned(),
|
"user@example.com".to_owned(),
|
||||||
"invalid_user_password".to_owned(),
|
Some("invalid_user_password".to_owned()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let other = NewUser::new_local(
|
let other = NewUser::new_local(
|
||||||
@ -1169,7 +1169,7 @@ pub(crate) mod tests {
|
|||||||
Role::Normal,
|
Role::Normal,
|
||||||
"Hello there, I'm someone else",
|
"Hello there, I'm someone else",
|
||||||
"other@example.com".to_owned(),
|
"other@example.com".to_owned(),
|
||||||
"invalid_other_password".to_owned(),
|
Some("invalid_other_password".to_owned()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
vec![admin, user, other]
|
vec![admin, user, other]
|
||||||
@ -1188,7 +1188,7 @@ pub(crate) mod tests {
|
|||||||
Role::Normal,
|
Role::Normal,
|
||||||
"Hello I'm a test",
|
"Hello I'm a test",
|
||||||
"test@example.com".to_owned(),
|
"test@example.com".to_owned(),
|
||||||
User::hash_pass("test_password").unwrap(),
|
Some(User::hash_pass("test_password").unwrap()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1271,12 +1271,15 @@ pub(crate) mod tests {
|
|||||||
Role::Normal,
|
Role::Normal,
|
||||||
"Hello I'm a test",
|
"Hello I'm a test",
|
||||||
"test@example.com".to_owned(),
|
"test@example.com".to_owned(),
|
||||||
User::hash_pass("test_password").unwrap(),
|
Some(User::hash_pass("test_password").unwrap()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(test_user.auth("test_password"));
|
assert_eq!(
|
||||||
assert!(!test_user.auth("other_password"));
|
User::login(conn, "test", "test_password").unwrap().id,
|
||||||
|
test_user.id
|
||||||
|
);
|
||||||
|
assert!(User::login(conn, "test", "other_password").is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user