add tests (one failing)

This commit is contained in:
Luca 2023-01-12 13:13:31 +01:00
parent f1781b198d
commit bb4de05bd8
No known key found for this signature in database
GPG Key ID: 3133FC373370010F

View File

@ -1040,6 +1040,7 @@ mod tests {
uuid: uuid!("698e1d5f-7a40-3151-8745-b9b8a37839da"), uuid: uuid!("698e1d5f-7a40-3151-8745-b9b8a37839da"),
..Default::default() ..Default::default()
}, },
groups: None,
}, },
UserAndGroups { UserAndGroups {
user: User { user: User {
@ -2206,27 +2207,70 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_compare() { async fn test_compare() {
let mut mock = MockTestBackendHandler::new(); let mut mock = MockTestBackendHandler::new();
mock.expect_create_user() mock.expect_list_users().returning(|_, _| {
.with(eq(CreateUserRequest { Ok(vec![UserAndGroups {
user_id: UserId::new("bob"), user: User {
email: "".to_owned(), user_id: UserId::new("bob"),
display_name: Some("Bob".to_string()), email: "bob@bobmail.bob".to_string(),
..Default::default() display_name: Some("bôb böbberson".to_string()),
})) first_name: Some("bôb".to_string()),
.times(1) last_name: Some("böbberson".to_string()),
.return_once(|_| Ok(())); uuid: uuid!("698e1d5f-7a40-3151-8745-b9b8a37839da"),
let ldap_handler = setup_bound_admin_handler(mock).await; ..Default::default()
let dn = "uid=bob,ou=people,dc=example,dc=com".to_owned(); },
groups: None,
}])
});
mock.expect_list_groups().returning(|_| {
Ok(vec![Group {
id: GroupId(1),
display_name: "group".to_string(),
creation_date: chrono::Utc.timestamp_opt(42, 42).unwrap(),
users: vec![UserId::new("bob")],
uuid: uuid!("04ac75e0-2900-3e21-926c-2f732c26b3fc"),
}])
});
let mut ldap_handler = setup_bound_admin_handler(mock).await;
let mut dn = "uid=bob,ou=people,dc=example,dc=com";
let request = LdapCompareRequest { let request = LdapCompareRequest {
dn, dn: dn.to_string(),
atype: "cn".to_owned(), atype: "uid".to_owned(),
val: b"Bob".to_vec(), val: b"bob".to_vec(),
}; };
assert_eq!( assert_eq!(
ldap_handler.do_compare(request).await, ldap_handler.do_compare(request).await,
Ok(vec![LdapOp::CompareResult(LdapResultOp { Ok(vec![LdapOp::CompareResult(LdapResultOp {
code: LdapResultCode::CompareTrue, code: LdapResultCode::CompareTrue,
matcheddn: dn, matcheddn: dn.to_string(),
message: "".to_string(),
referral: vec![],
})])
);
let request = LdapCompareRequest {
dn: dn.to_string(),
atype: "mail".to_owned(),
val: b"bob@bobmail.bob".to_vec(),
};
assert_eq!(
ldap_handler.do_compare(request).await,
Ok(vec![LdapOp::CompareResult(LdapResultOp {
code: LdapResultCode::CompareTrue,
matcheddn: dn.to_string(),
message: "".to_string(),
referral: vec![],
})])
);
dn = "uid=group,ou=groups,dc=example,dc=com";
let request = LdapCompareRequest {
dn: dn.to_string(),
atype: "uid".to_owned(),
val: b"group".to_vec(),
};
assert_eq!(
ldap_handler.do_compare(request).await,
Ok(vec![LdapOp::CompareResult(LdapResultOp {
code: LdapResultCode::CompareTrue,
matcheddn: dn.to_string(),
message: "".to_string(), message: "".to_string(),
referral: vec![], referral: vec![],
})]) })])