try fixing clippy and fmt
This commit is contained in:
parent
69bcb01715
commit
3de009713d
@ -252,26 +252,28 @@ 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) {
|
||||||
let tls = var("LDAP_TLS").unwrap_or_else(|_| "false".to_owned());
|
(Some(addr), Some(base_dn)) => {
|
||||||
let tls = match tls.as_ref() {
|
let tls = var("LDAP_TLS").unwrap_or_else(|_| "false".to_owned());
|
||||||
"1" | "true" | "TRUE" => true,
|
let tls = match tls.as_ref() {
|
||||||
"0" | "false" | "FALSE" => false,
|
"1" | "true" | "TRUE" => true,
|
||||||
_ => panic!("Invalid LDAP configuration : tls"),
|
"0" | "false" | "FALSE" => false,
|
||||||
};
|
_ => panic!("Invalid LDAP configuration : tls"),
|
||||||
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 user_name_attr = var("LDAP_USER_NAME_ATTR").unwrap_or_else(|_| "cn".to_owned());
|
||||||
Some(LdapConfig {
|
let mail_attr = var("LDAP_USER_MAIL_ATTR").unwrap_or_else(|_| "mail".to_owned());
|
||||||
addr: addr.unwrap(),
|
Some(LdapConfig {
|
||||||
base_dn: base_dn.unwrap(),
|
addr,
|
||||||
tls,
|
base_dn,
|
||||||
user_name_attr,
|
tls,
|
||||||
mail_attr,
|
user_name_attr,
|
||||||
})
|
mail_attr,
|
||||||
} else if addr.is_some() || base_dn.is_some() {
|
})
|
||||||
panic!("Invalid LDAP configuration : both LDAP_ADDR and LDAP_BASE_DN must be set")
|
}
|
||||||
} else {
|
(None, None) => None,
|
||||||
None
|
(_, _) => {
|
||||||
|
panic!("Invalid LDAP configuration : both LDAP_ADDR and LDAP_BASE_DN must be set")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1275,7 +1275,10 @@ pub(crate) mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(User::login(conn, "test", "test_password").unwrap().id, test_user.id);
|
assert_eq!(
|
||||||
|
User::login(conn, "test", "test_password").unwrap().id,
|
||||||
|
test_user.id
|
||||||
|
);
|
||||||
assert!(User::login(conn, "test", "other_password").is_err());
|
assert!(User::login(conn, "test", "other_password").is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user