diff --git a/server/src/infra/ldap_handler.rs b/server/src/infra/ldap_handler.rs index 99b675b..049f44f 100644 --- a/server/src/infra/ldap_handler.rs +++ b/server/src/infra/ldap_handler.rs @@ -711,11 +711,20 @@ impl LdapHandler LdapHandler { + if field == "user_id" { + Ok(UserRequestFilter::UserId(UserId::new(value))) + } else { + Ok(UserRequestFilter::Equality(field, value.clone())) + } + } + Err(_) => { + warn!(r#"Ignoring unknown user attribute "{}" in filter"#, field); + Ok(UserRequestFilter::Not(Box::new(UserRequestFilter::And( + vec![], + )))) + } } } } @@ -1330,6 +1348,9 @@ mod tests { GroupRequestFilter::Not(Box::new(GroupRequestFilter::Not(Box::new( GroupRequestFilter::And(vec![]), )))), + GroupRequestFilter::Not(Box::new( + GroupRequestFilter::And(vec![]), + )), ])))) .times(1) .return_once(|_| { @@ -1355,6 +1376,7 @@ mod tests { LdapFilter::Not(Box::new(LdapFilter::Present( "random_attribUte".to_string(), ))), + LdapFilter::Equality("unknown_attribute".to_string(), "randomValue".to_string()), ]), vec!["1.1"], ); @@ -1449,9 +1471,9 @@ mod tests { let mut ldap_handler = setup_bound_handler(MockTestBackendHandler::new()).await; let request = make_search_request( "ou=groups,dc=example,dc=com", - LdapFilter::And(vec![LdapFilter::Equality( + LdapFilter::And(vec![LdapFilter::Substring( "whatever".to_string(), - "group_1".to_string(), + ldap3_server::proto::LdapSubstringFilter::default(), )]), vec!["cn"], ); @@ -1459,7 +1481,8 @@ mod tests { ldap_handler.do_search(&request).await, vec![make_search_error( LdapResultCode::UnwillingToPerform, - "Unsupported group filter: Unknown field: whatever".to_string() + r#"Unsupported group filter: Unsupported group filter: Substring("whatever", LdapSubstringFilter { initial: None, any: [], final_: None })"# + .to_string() )] ); } @@ -1476,6 +1499,7 @@ mod tests { UserRequestFilter::And(vec![]), UserRequestFilter::And(vec![]), UserRequestFilter::Not(Box::new(UserRequestFilter::And(vec![]))), + UserRequestFilter::Not(Box::new(UserRequestFilter::And(vec![]))), ]), ])))) .times(1) @@ -1492,6 +1516,7 @@ mod tests { LdapFilter::Present("objectClass".to_string()), LdapFilter::Present("uid".to_string()), LdapFilter::Present("unknown".to_string()), + LdapFilter::Equality("unknown_attribute".to_string(), "randomValue".to_string()), ])]), vec!["objectClass"], );