mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
move tests to the ldap_handler level
This commit is contained in:
parent
398b0d79ef
commit
3d2e831276
@ -233,48 +233,3 @@ pub async fn get_groups_list<Backend: BackendHandler>(
|
||||
})
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ldap3_proto::LdapFilter;
|
||||
|
||||
use crate::domain::ldap::group::GroupRequestFilter;
|
||||
use crate::domain::ldap::utils::{parse_distinguished_name, LdapInfo};
|
||||
|
||||
use super::convert_group_filter;
|
||||
|
||||
static BASE_DN_STR: &str = "dc=example,dc=com";
|
||||
|
||||
#[test]
|
||||
fn test_convert_group_filter() {
|
||||
let ldap_info = LdapInfo {
|
||||
base_dn: parse_distinguished_name(BASE_DN_STR).unwrap(),
|
||||
base_dn_str: BASE_DN_STR.to_string(),
|
||||
ignored_user_attributes: vec![],
|
||||
ignored_group_attributes: vec![],
|
||||
};
|
||||
// TODO: test all other match cases
|
||||
let res = convert_group_filter(
|
||||
&ldap_info,
|
||||
&LdapFilter::Equality(
|
||||
"dn".to_string(),
|
||||
"uid=test,ou=groups,dc=example,dc=com".to_string(),
|
||||
),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
Ok(GroupRequestFilter::DisplayName("test".to_string().into()))
|
||||
);
|
||||
let res = convert_group_filter(
|
||||
&ldap_info,
|
||||
&LdapFilter::Equality(
|
||||
"dn".to_string(),
|
||||
"cn=test,ou=groups,dc=example,dc=com".to_string(),
|
||||
),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
Ok(GroupRequestFilter::DisplayName("test".to_string().into()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -247,48 +247,3 @@ pub async fn get_user_list<Backend: BackendHandler>(
|
||||
})
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ldap3_proto::LdapFilter;
|
||||
|
||||
use crate::domain::ldap::user::UserRequestFilter;
|
||||
use crate::domain::ldap::utils::{parse_distinguished_name, LdapInfo};
|
||||
|
||||
use super::convert_user_filter;
|
||||
|
||||
static BASE_DN_STR: &str = "dc=example,dc=com";
|
||||
|
||||
#[test]
|
||||
fn test_convert_user_filter() {
|
||||
let ldap_info = LdapInfo {
|
||||
base_dn: parse_distinguished_name(BASE_DN_STR).unwrap(),
|
||||
base_dn_str: BASE_DN_STR.to_string(),
|
||||
ignored_user_attributes: vec![],
|
||||
ignored_group_attributes: vec![],
|
||||
};
|
||||
// TODO: test all other match cases
|
||||
let res = convert_user_filter(
|
||||
&ldap_info,
|
||||
&LdapFilter::Equality(
|
||||
"dn".to_string(),
|
||||
"uid=test,ou=people,dc=example,dc=com".to_string(),
|
||||
),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
Ok(UserRequestFilter::UserId("test".to_string().into()))
|
||||
);
|
||||
let res = convert_user_filter(
|
||||
&ldap_info,
|
||||
&LdapFilter::Equality(
|
||||
"dn".to_string(),
|
||||
"cn=test,ou=people,dc=example,dc=com".to_string(),
|
||||
),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
Ok(UserRequestFilter::UserId("test".to_string().into()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1535,6 +1535,94 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_search_filter_dn_user() {
|
||||
let mut mock = MockTestBackendHandler::new();
|
||||
mock.expect_list_users()
|
||||
.with(
|
||||
eq(Some(UserRequestFilter::UserId("bob_1".to_string().into()))),
|
||||
eq(false),
|
||||
)
|
||||
.times(1)
|
||||
.return_once(|_, _| {
|
||||
Ok(vec![UserAndGroups {
|
||||
user: User {
|
||||
user_id: UserId::new("bob_1"),
|
||||
..Default::default()
|
||||
},
|
||||
groups: None,
|
||||
}])
|
||||
});
|
||||
let mut ldap_handler = setup_bound_admin_handler(mock).await;
|
||||
let request = make_user_search_request(
|
||||
LdapFilter::Equality(
|
||||
"dn".to_string(),
|
||||
"uid=bob_1,ou=people,dc=example,dc=com".to_string(),
|
||||
),
|
||||
vec!["objectclass"],
|
||||
);
|
||||
assert_eq!(
|
||||
ldap_handler.do_search_or_dse(&request).await,
|
||||
Ok(vec![
|
||||
LdapOp::SearchResultEntry(LdapSearchResultEntry {
|
||||
dn: "uid=bob_1,ou=people,dc=example,dc=com".to_string(),
|
||||
attributes: vec![LdapPartialAttribute {
|
||||
atype: "objectclass".to_string(),
|
||||
vals: vec![
|
||||
b"inetOrgPerson".to_vec(),
|
||||
b"posixAccount".to_vec(),
|
||||
b"mailAccount".to_vec(),
|
||||
b"person".to_vec()
|
||||
]
|
||||
},]
|
||||
}),
|
||||
make_search_success()
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_search_filter_dn_group() {
|
||||
let mut mock = MockTestBackendHandler::new();
|
||||
mock.expect_list_groups()
|
||||
.with(eq(Some(GroupRequestFilter::DisplayName(
|
||||
"rockstars".to_string().into(),
|
||||
))))
|
||||
.times(1)
|
||||
.return_once(|_| {
|
||||
let epoch = chrono::Utc.timestamp_opt(0, 0).unwrap();
|
||||
Ok(vec![Group {
|
||||
id: GroupId(0),
|
||||
display_name: "rockstars".to_string(),
|
||||
creation_date: epoch,
|
||||
uuid: Uuid::from_name_and_date("", &epoch),
|
||||
users: vec![],
|
||||
}])
|
||||
});
|
||||
let mut ldap_handler = setup_bound_admin_handler(mock).await;
|
||||
let request = make_search_request(
|
||||
"ou=groups,Dc=example,dc=com",
|
||||
LdapFilter::Equality(
|
||||
"dn".to_string(),
|
||||
"uid=rockstars,ou=groups,dc=example,dc=com".to_string(),
|
||||
),
|
||||
vec!["objectclass"],
|
||||
);
|
||||
assert_eq!(
|
||||
ldap_handler.do_search_or_dse(&request).await,
|
||||
Ok(vec![
|
||||
LdapOp::SearchResultEntry(LdapSearchResultEntry {
|
||||
dn: "cn=rockstars,ou=groups,dc=example,dc=com".to_string(),
|
||||
attributes: vec![LdapPartialAttribute {
|
||||
atype: "objectclass".to_string(),
|
||||
vals: vec![b"groupOfUniqueNames".to_vec(),]
|
||||
},]
|
||||
}),
|
||||
make_search_success()
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_search_both() {
|
||||
let mut mock = MockTestBackendHandler::new();
|
||||
|
Loading…
Reference in New Issue
Block a user