Skip to content

Commit 47ce0df

Browse files
committed
Skip some TLS tests when libldap used NSS
Some TLS tests are broken or flaky when libldap is compiled with NSS as TLS provider. It currently affects Fedora 27 and older releases. Fedora issue: https://bugzilla.redhat.com/show_bug.cgi?id=1519167 #60 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent e716349 commit 47ce0df

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ env:
4343
# -Werror: turn all warnings into fatal errors
4444
# -Werror=declaration-after-statement: strict ISO C90
4545
- CFLAGS="-std=c90 -Wno-int-in-bool-context -Werror -Werror=declaration-after-statement"
46-
# pass CFLAGS and WITH_GCOV to tox tasks
47-
- TOX_TESTENV_PASSENV="CFLAGS WITH_GCOV"
46+
# pass CFLAGS, CI (for Travis CI) and WITH_GCOV to tox tasks
47+
- TOX_TESTENV_PASSENV="CFLAGS CI WITH_GCOV"
4848

4949
install:
5050
- pip install "pip>=7.1.0"

Lib/slapdtest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
from logging.handlers import SysLogHandler
1919
import unittest
2020

21+
# Switch off processing .ldaprc or ldap.conf before importing _ldap
22+
os.environ['LDAPNOINIT'] = '1'
23+
24+
import ldap
2125
from ldap.compat import quote_plus
2226

2327
# a template string for generating simple slapd.conf file
@@ -52,6 +56,41 @@
5256

5357
LOCALHOST = '127.0.0.1'
5458

59+
60+
def identity(test_item):
61+
"""Identity decorator
62+
63+
"""
64+
return test_item
65+
66+
67+
def skip_unless_travis(reason):
68+
"""Skip test unless test case is executed on CI like Travis CI
69+
"""
70+
if os.environ.get('CI', False):
71+
return identity
72+
else:
73+
return unittest.skip(reason)
74+
75+
76+
def requires_tls(skip_nss=False):
77+
"""Decorator for TLS tests
78+
79+
Tests are not skipped on CI (e.g. Travis CI)
80+
81+
:param skip_nss: Skip test when libldap is compiled with NSS as TLS lib
82+
"""
83+
if not ldap.TLS_AVAIL:
84+
return skip_unless_travis("test needs ldap.TLS_AVAIL")
85+
elif skip_nss and ldap.get_option(ldap.OPT_X_TLS_PACKAGE) == 'MozNSS':
86+
return skip_unless_travis(
87+
"Test doesn't work correctly with Mozilla NSS, see "
88+
"https://bugzilla.redhat.com/show_bug.cgi?id=1519167"
89+
)
90+
else:
91+
return identity
92+
93+
5594
def combined_logger(
5695
log_name,
5796
log_level=logging.WARN,

Tests/t_cext.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
import os
1111
import unittest
12-
from slapdtest import SlapdTestCase
12+
13+
from slapdtest import SlapdTestCase, requires_tls
1314

1415
# Switch off processing .ldaprc or ldap.conf before importing _ldap
1516
os.environ['LDAPNOINIT'] = '1'
@@ -717,12 +718,6 @@ def test_sasl(self):
717718
return
718719
# TODO
719720

720-
def test_tls(self):
721-
l = self._open_conn()
722-
if not self._require_attr(l, 'start_tls_s'): # HAVE_TLS
723-
return
724-
# TODO
725-
726721
def test_cancel(self):
727722
l = self._open_conn()
728723
if not self._require_attr(l, 'cancel'): # FEATURE_CANCEL
@@ -807,7 +802,7 @@ def test_invalid_controls(self):
807802
l.sasl_interactive_bind_s, 'who', 'SASLObject', post=(1,))
808803
self.assertInvalidControls(l.unbind_ext)
809804

810-
@unittest.skipUnless(_ldap.TLS_AVAIL, "needs tls")
805+
@requires_tls(skip_nss=True)
811806
def test_tls_ext(self):
812807
l = self._open_conn(bind=False)
813808
# StartTLS needs LDAPv3
@@ -817,15 +812,17 @@ def test_tls_ext(self):
817812
l.set_option(_ldap.OPT_X_TLS_NEWCTX, 0)
818813
l.start_tls_s()
819814

820-
@unittest.skipUnless(_ldap.TLS_AVAIL, "needs tls")
815+
@requires_tls(skip_nss=False)
821816
def test_tls_ext_noca(self):
822817
l = self._open_conn(bind=False)
823818
l.set_option(_ldap.OPT_PROTOCOL_VERSION, _ldap.VERSION3)
824-
l.set_option(_ldap.OPT_X_TLS_NEWCTX, 0)
825-
with self.assertRaises(_ldap.CONNECT_ERROR):
819+
with self.assertRaises(_ldap.CONNECT_ERROR) as e:
826820
l.start_tls_s()
821+
# some platforms return '(unknown error code)' as reason
822+
if '(unknown error code)' not in str(e.exception):
823+
self.assertIn('not trusted', str(e.exception))
827824

828-
@unittest.skipUnless(_ldap.TLS_AVAIL, "needs tls")
825+
@requires_tls(skip_nss=True)
829826
def test_tls_ext_clientcert(self):
830827
l = self._open_conn(bind=False)
831828
l.set_option(_ldap.OPT_PROTOCOL_VERSION, _ldap.VERSION3)
@@ -836,5 +833,12 @@ def test_tls_ext_clientcert(self):
836833
l.set_option(_ldap.OPT_X_TLS_NEWCTX, 0)
837834
l.start_tls_s()
838835

836+
@requires_tls(skip_nss=False)
837+
def test_tls_packages(self):
838+
# libldap has tls_g.c, tls_m.c, and tls_o.c with ldap_int_tls_impl
839+
package = _ldap.get_option(_ldap.OPT_X_TLS_PACKAGE)
840+
self.assertIn(package, {"GnuTLS", "MozNSS", "OpenSSL"})
841+
842+
839843
if __name__ == '__main__':
840844
unittest.main()

Tests/t_ldap_sasl.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ldap.ldapobject import SimpleLDAPObject
1616
import ldap.sasl
17-
from slapdtest import SlapdTestCase
17+
from slapdtest import SlapdTestCase, requires_tls
1818

1919

2020
LDIF = """
@@ -75,19 +75,15 @@ def test_external_ldapi(self):
7575
"dn:{}".format(self.server.root_dn.lower())
7676
)
7777

78+
@requires_tls(skip_nss=True)
7879
def test_external_tlscert(self):
7980
ldap_conn = self.ldap_object_class(self.server.ldap_uri)
8081
ldap_conn.set_option(ldap.OPT_X_TLS_CACERTFILE, self.server.cafile)
8182
ldap_conn.set_option(ldap.OPT_X_TLS_CERTFILE, self.server.clientcert)
8283
ldap_conn.set_option(ldap.OPT_X_TLS_KEYFILE, self.server.clientkey)
8384
ldap_conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_HARD)
8485
ldap_conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
85-
try:
86-
ldap_conn.start_tls_s()
87-
except ldap.CONNECT_ERROR as e:
88-
# TODO: On Fedora 27 OpenLDAP server refuses STARTTLS when test
89-
# is executed with other tests,
90-
raise unittest.SkipTest("buggy start_tls_s: {}".format(e))
86+
ldap_conn.start_tls_s()
9187

9288
auth = ldap.sasl.external()
9389
ldap_conn.sasl_interactive_bind_s("", auth)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy