Skip to content

Commit

Permalink
Run tests without SASL and TLS bindings
Browse files Browse the repository at this point in the history
Also fixes tests when _ldap extension is compiled without SASL support.

https://github.com/python-ldap/python-ldap/pull/91
Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Dec 4, 2017
1 parent 9f86c06 commit c5ad802
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ matrix:
env:
- TOXENV=py36
- WITH_GCOV=1
- python: 2.7
env:
- TOXENV=py2-nosasltls
- WITH_GCOV=1
- python: 3.6
env:
- TOXENV=py3-nosasltls
- WITH_GCOV=1
- python: 3.6
env: TOXENV=doc

Expand Down
2 changes: 2 additions & 0 deletions Doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ for checking things independent of the Python version:
* ``doc`` checks syntax and spelling of the documentation
* ``coverage-report`` generates a test coverage report for Python code.
It must be used last, e.g. ``tox -e py27,py36,coverage-report``.
* ``py2-nosasltls`` and ``py3-nosasltls`` check functionality without
SASL and TLS bindings compiled in.


When your change is ready, commit to Git, and submit a pull request on GitHub.
Expand Down
2 changes: 1 addition & 1 deletion Lib/slapdtest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
__version__ = '3.0.0b1'

from slapdtest._slapdtest import SlapdObject, SlapdTestCase, SysLogHandler
from slapdtest._slapdtest import skip_unless_ci, requires_tls
from slapdtest._slapdtest import skip_unless_ci, requires_sasl, requires_tls
24 changes: 18 additions & 6 deletions Lib/slapdtest/_slapdtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ def identity(test_item):
return test_item


def skip_unless_ci(reason):
def skip_unless_ci(reason, feature=None):
"""Skip test unless test case is executed on CI like Travis CI
"""
if os.environ.get('CI', False):
return identity
else:
if not os.environ.get('CI', False):
return unittest.skip(reason)
elif feature in os.environ.get('CI_DISABLED', '').split(':'):
return unittest.skip(reason)
else:
# Don't skip on Travis
return identity


def requires_tls(skip_nss=False):
Expand All @@ -81,16 +84,25 @@ def requires_tls(skip_nss=False):
:param skip_nss: Skip test when libldap is compiled with NSS as TLS lib
"""
if not ldap.TLS_AVAIL:
return skip_unless_ci("test needs ldap.TLS_AVAIL")
return skip_unless_ci("test needs ldap.TLS_AVAIL", feature='TLS')
elif skip_nss and ldap.get_option(ldap.OPT_X_TLS_PACKAGE) == 'MozNSS':
return skip_unless_ci(
"Test doesn't work correctly with Mozilla NSS, see "
"https://bugzilla.redhat.com/show_bug.cgi?id=1519167"
"https://bugzilla.redhat.com/show_bug.cgi?id=1519167",
feature="NSS"
)
else:
return identity


def requires_sasl():
if not ldap.SASL_AVAIL:
return skip_unless_ci(
"test needs ldap.SASL_AVAIL", feature='SASL')
else:
return identity


def combined_logger(
log_name,
log_level=logging.WARN,
Expand Down
15 changes: 15 additions & 0 deletions Tests/t_cext.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ def test_constants(self):
self.assertNotNone(_ldap.URL_ERR_BADSCOPE)
self.assertNotNone(_ldap.URL_ERR_MEM)

def test_test_flags(self):
# test flag, see slapdtest and tox.ini
disabled = os.environ.get('CI_DISABLED')
if not disabled:
self.skipTest("No CI_DISABLED env var")
disabled = set(disabled.split(':'))
if 'TLS' in disabled:
self.assertFalse(_ldap.TLS_AVAIL)
else:
self.assertFalse(_ldap.TLS_AVAIL)
if 'SASL' in disabled:
self.assertFalse(_ldap.SASL_AVAIL)
else:
self.assertFalse(_ldap.SASL_AVAIL)

def test_simple_bind(self):
l = self._open_conn()

Expand Down
3 changes: 2 additions & 1 deletion Tests/t_ldap_sasl.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ldap.ldapobject import SimpleLDAPObject
import ldap.sasl
from slapdtest import SlapdTestCase, requires_tls
from slapdtest import SlapdTestCase, requires_sasl, requires_tls


LDIF = """
Expand All @@ -39,6 +39,7 @@
"""


@requires_sasl()
class TestSasl(SlapdTestCase):
ldap_object_class = SimpleLDAPObject
# from Tests/certs/client.pem
Expand Down
4 changes: 3 additions & 1 deletion Tests/t_ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import unittest
import pickle
from slapdtest import SlapdTestCase
from slapdtest import SlapdTestCase, requires_sasl

# Switch off processing .ldaprc or ldap.conf before importing _ldap
os.environ['LDAPNOINIT'] = '1'
Expand Down Expand Up @@ -298,6 +298,7 @@ def test005_invalid_credentials(self):
else:
self.fail("expected INVALID_CREDENTIALS, got %r" % r)

@requires_sasl()
def test006_sasl_extenal_bind_s(self):
l = self.ldap_object_class(self.server.ldapi_uri)
l.sasl_external_bind_s()
Expand All @@ -322,6 +323,7 @@ class Test01_ReconnectLDAPObject(Test00_SimpleLDAPObject):

ldap_object_class = ReconnectLDAPObject

@requires_sasl()
def test101_reconnect_sasl_external(self):
l = self.ldap_object_class(self.server.ldapi_uri)
l.sasl_external_bind_s()
Expand Down
24 changes: 23 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

[tox]
# Note: when updating Python versions, also change setup.py and .travis.yml
envlist = py27,py33,py34,py35,py36,doc,coverage-report
envlist = py27,py33,py34,py35,py36,{py2,py3}-nosasltls,doc,coverage-report
minver = 1.8

[testenv]
deps = coverage
Expand All @@ -21,9 +22,30 @@ commands = {envpython} -bb -Werror \

[testenv:py27]
# No warnings with Python 2.7
passenv = {[testenv]passenv}
commands = {envpython} \
-m coverage run --parallel setup.py test

[testenv:py2-nosasltls]
basepython = python2
deps = {[testenv]deps}
passenv = {[testenv]passenv}
setenv =
CI_DISABLED=TLS:SASL
# rebuild without SASL and TLS
commands = {envpython} \
-m coverage run --parallel setup.py \
clean --all \
build_ext -UHAVE_SASL,HAVE_TLS \
test

[testenv:py3-nosasltls]
basepython = python3
deps = {[testenv]deps}
passenv = {[testenv]passenv}
setenv = {[testenv:py2-nosasltls]setenv}
commands = {[testenv:py2-nosasltls]commands}

[testenv:coverage-report]
deps = coverage
skip_install = true
Expand Down

0 comments on commit c5ad802

Please sign in to comment.