Skip to content

Commit 071a2b7

Browse files
authored
Merge pull request #4 from azmeuk/ldapsearch-command
ldapsearch command
2 parents 18fe44f + f8366ea commit 071a2b7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
33
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
44
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
55

6+
[0.1.1] - 2021-11-24
7+
====================
8+
9+
Added
10+
*****
11+
12+
- Added `ldapsearch` command. :pr:`4`
13+
614
[0.1.0] - 2021-04-02
715
====================
816

slapd/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def _find_commands(self):
213213
self.PATH_LDAPADD = self._find_command("ldapadd")
214214
self.PATH_LDAPDELETE = self._find_command("ldapdelete")
215215
self.PATH_LDAPMODIFY = self._find_command("ldapmodify")
216+
self.PATH_LDAPSEARCH = self._find_command("ldapsearch")
216217
self.PATH_LDAPWHOAMI = self._find_command("ldapwhoami")
217218
self.PATH_SLAPADD = self._find_command("slapadd")
218219
self.PATH_SLAPCAT = self._find_command("slapcat")
@@ -558,6 +559,27 @@ def ldapdelete(self, dn, recursive=False, extra_args=None, expected=0):
558559
self.PATH_LDAPDELETE, extra_args=extra_args, expected=expected
559560
)
560561

562+
def ldapsearch(self, filter, searchbase=None, extra_args=None, expected=0):
563+
"""
564+
Runs search on this slapd instance
565+
566+
:param filter: The search filter.
567+
:param base: The starting point for the search.
568+
:param extra_args: Extra argument to pass to *ldapdelete*.
569+
:param expected: Expected return code. Defaults to `0`.
570+
:type expected: An integer or a list of integers
571+
572+
:return: A :class:`subprocess.CompletedProcess` with the *ldapdelete* execution data.
573+
"""
574+
if extra_args is None:
575+
extra_args = []
576+
if searchbase:
577+
extra_args.extend(["-b", searchbase])
578+
extra_args.append(filter)
579+
return self._cli_popen(
580+
self.PATH_LDAPSEARCH, extra_args=extra_args, expected=expected
581+
)
582+
561583
def slapadd(self, ldif, extra_args=None, expected=0):
562584
"""
563585
Runs slapadd on this slapd instance, passing it the ldif content

tests/test_slapdobject.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def test_commands():
3333
"dn:cn=manager,dc=slapd-test,dc=python-ldap,dc=org\n"
3434
== server.ldapwhoami().stdout.decode("utf-8")
3535
)
36+
server.ldapsearch("ou=home", "dc=slapd-test,dc=python-ldap,dc=org", expected=32)
37+
3638
ldif = (
3739
"dn: dc=slapd-test,dc=python-ldap,dc=org\n"
3840
"objectClass: dcObject\n"
@@ -55,6 +57,8 @@ def test_commands():
5557
in server.slapcat().stdout.decode("utf-8")
5658
)
5759

60+
server.ldapsearch("ou=home", "dc=slapd-test,dc=python-ldap,dc=org")
61+
5862
ldif = (
5963
"dn: ou=home,dc=slapd-test,dc=python-ldap,dc=org\n"
6064
"changetype: modify\n"

0 commit comments

Comments
 (0)