From f1781b198d999733640cfc274285dadcfc83c1f8 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 12 Jan 2023 12:36:37 +0100 Subject: [PATCH] add tests for ldap compare --- server/src/infra/ldap_handler.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/src/infra/ldap_handler.rs b/server/src/infra/ldap_handler.rs index 6fa87cc..0467df6 100644 --- a/server/src/infra/ldap_handler.rs +++ b/server/src/infra/ldap_handler.rs @@ -2203,6 +2203,36 @@ mod tests { ); } + #[tokio::test] + async fn test_compare() { + let mut mock = MockTestBackendHandler::new(); + mock.expect_create_user() + .with(eq(CreateUserRequest { + user_id: UserId::new("bob"), + email: "".to_owned(), + display_name: Some("Bob".to_string()), + ..Default::default() + })) + .times(1) + .return_once(|_| Ok(())); + let ldap_handler = setup_bound_admin_handler(mock).await; + let dn = "uid=bob,ou=people,dc=example,dc=com".to_owned(); + let request = LdapCompareRequest { + dn, + atype: "cn".to_owned(), + val: b"Bob".to_vec(), + }; + assert_eq!( + ldap_handler.do_compare(request).await, + Ok(vec![LdapOp::CompareResult(LdapResultOp { + code: LdapResultCode::CompareTrue, + matcheddn: dn, + message: "".to_string(), + referral: vec![], + })]) + ); + } + #[tokio::test] async fn test_create_user_wrong_ou() { let ldap_handler = setup_bound_admin_handler(MockTestBackendHandler::new()).await;