Skip to content

Commit

Permalink
ldapsearch command
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Nov 24, 2021
1 parent 18fe44f commit 6c3b1c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

[0.1.1] - 2021-11-24
====================

Added
*****

- Added `ldapsearch` command.

[0.1.0] - 2021-04-02
====================

Expand Down
22 changes: 22 additions & 0 deletions slapd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def _find_commands(self):
self.PATH_LDAPADD = self._find_command("ldapadd")
self.PATH_LDAPDELETE = self._find_command("ldapdelete")
self.PATH_LDAPMODIFY = self._find_command("ldapmodify")
self.PATH_LDAPSEARCH = self._find_command("ldapsearch")
self.PATH_LDAPWHOAMI = self._find_command("ldapwhoami")
self.PATH_SLAPADD = self._find_command("slapadd")
self.PATH_SLAPCAT = self._find_command("slapcat")
Expand Down Expand Up @@ -558,6 +559,27 @@ def ldapdelete(self, dn, recursive=False, extra_args=None, expected=0):
self.PATH_LDAPDELETE, extra_args=extra_args, expected=expected
)

def ldapsearch(self, filter, searchbase=None, extra_args=None, expected=0):
"""
Runs search on this slapd instance
:param filter: The search filter.
:param base: The starting point for the search.
:param extra_args: Extra argument to pass to *ldapdelete*.
:param expected: Expected return code. Defaults to `0`.
:type expected: An integer or a list of integers
:return: A :class:`subprocess.CompletedProcess` with the *ldapdelete* execution data.
"""
if extra_args is None:
extra_args = []
if searchbase:
extra_args.extend(["-b", searchbase])
extra_args.append(filter)
return self._cli_popen(
self.PATH_LDAPSEARCH, extra_args=extra_args, expected=expected
)

def slapadd(self, ldif, extra_args=None, expected=0):
"""
Runs slapadd on this slapd instance, passing it the ldif content
Expand Down
4 changes: 4 additions & 0 deletions tests/test_slapdobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def test_commands():
"dn:cn=manager,dc=slapd-test,dc=python-ldap,dc=org\n"
== server.ldapwhoami().stdout.decode("utf-8")
)
server.ldapsearch("ou=home", "dc=slapd-test,dc=python-ldap,dc=org", expected=32)

ldif = (
"dn: dc=slapd-test,dc=python-ldap,dc=org\n"
"objectClass: dcObject\n"
Expand All @@ -55,6 +57,8 @@ def test_commands():
in server.slapcat().stdout.decode("utf-8")
)

server.ldapsearch("ou=home", "dc=slapd-test,dc=python-ldap,dc=org")

ldif = (
"dn: ou=home,dc=slapd-test,dc=python-ldap,dc=org\n"
"changetype: modify\n"
Expand Down

0 comments on commit 6c3b1c5

Please sign in to comment.