Skip to main content

Temporary slapd launcher for testing purposes

Project description

https://secure.travis-ci.org/rbarrois/volatildap.png?branch=master Latest Version Supported Python versions Wheel status License

volatildap provides simple helpers for testing code against a LDAP database.

Its main features include:

  • Simple configuration: Don’t provide anything the LDAP server will start with sane defaults

  • Built-in cleanup: As soon as the test ends / the test process exits, the server is instantly removed

  • Cross-distribution setup: Automatically discover system paths for OpenLDAP binaries, schemas, etc.

Usage

import volatildap

class MyTests(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        super(MyTests, cls).setUpClass()
        cls._slapd = volatildap.LdapServer(suffix='dc=example,dc=org')

    def setUp(self):
        # Will start the server, or reset/restart it if already started from a previous test.
        self._slapd.start()

    def test_something(self):
        conn = ldap.connection(self._slapd.uri)
        # Do some tests

    def test_with_data(self):
        # Load some data
        self._slapd.add({'ou=people': {'cn': [b'Users']}})
        # Run the tests

The volatildap.LdapServer provides a few useful methods:

start()

Start or restart the server. This will:

  • Clear all data, if any

  • Start the server if it’s not yet running

  • Populate the initial data

stop()

Stop the server.

This will clean up all data and kill the proces.

add(data)

Add some data, see the initial_data structure below.

get(dn)

Retrieve an object by its distinguished name;

Returns a dictionary mapping an attribute to the list of its values, as bytes.

Raises KeyError if the distinguished name is unknown to the underlying database.

reset()

Restore the server to its pristine, initial state. This includes loading the inital_data.

Configuration

The volatildap.LdapServer class accepts a few parameters:

suffix

The suffix to use for the LDAP tree

Default: dc=example,dc=org

rootdn

The administrator account for the LDAP server

Default: cn=testadmin,dc=example,dc=org

rootpw

The administrator password.

Default: A random value, available through LdapServer.rootpw

schemas

List of schemas to load; can be either a simple name (e.g cosine.schema; looked up in openldap installation); or a path to a custom one.

Default: ['core.schema']

initial_data

Dict mapping a distinguished name to a dict of attribute/values:

slapd(initial_data={
    'ou=people': {
        'objectClass': ['organizationalUnit'],
        'cn': ['People'],
    },
})

Note: When adding data, the suffix can be omitted on objects DNs.

Default: {}

skip_missing_schemas

When loading schemas, this flag instructs volatildap to continue if some schemas can’t be found.

Default: False

port

The port to use.

Default: An available TCP port on the system

slapd_debug

The debug level for slapd; see slapd.conf

Default: 0

max_server_startup_delay

The maximum delay allowed for server startup, in seconds.

Default: 30

tls_config

A set of TLS certificate files for configuring the server. A valid set for localhost is provided as volatildap.LOCALHOST_TLS_CONFIG, but users may also provide their own:

tls_config = volatildap.TLSConfig(
   root=read(ca_path),
   chain=[
      read(intermediate_path),
   ],
   certificate=read(certificate_path),
   key=read(key_path),
)

Per-distribution specificities

Ubuntu

Under Ubuntu, the default AppArmor policy does not allow slapd (the LDAP daemon) to read temporary folders. Users should update the /etc/apparmor.d/usr.sbin.slapd file and add /tmp/** rw there.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

volatildap-1.3.0.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

volatildap-1.3.0-py2.py3-none-any.whl (13.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file volatildap-1.3.0.tar.gz.

File metadata

  • Download URL: volatildap-1.3.0.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

File hashes

Hashes for volatildap-1.3.0.tar.gz
Algorithm Hash digest
SHA256 7ef4cac02c4f907b87d5e3f5e872287a874d0c0d0a7c1054a8caae8e9c17b367
MD5 cb7bf27e2d5b33eff1bfa48d04704e11
BLAKE2b-256 57f69fce31e6f1d47bfc827d969de3d7d798acbb806124a7eb7c0b31781db203

See more details on using hashes here.

File details

Details for the file volatildap-1.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: volatildap-1.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

File hashes

Hashes for volatildap-1.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d9ef3ee7fcdf8d3ae1dd243e0a8c3892e404e4552caa60153fa0de97287bcfc6
MD5 42379b0c72eaf1dc8126c10f7dba16aa
BLAKE2b-256 a83c980994abfce5c138a554be3042a4d3e137fc55cf1ce8f5ec761508299092

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page