Skip to content

Commit 9752c96

Browse files
authored
Merge PR #52 – Fix schema urlfetch and add tests
#52
2 parents 53fa5b7 + 094624a commit 9752c96

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

Lib/ldap/schema/subentry.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,13 @@ def urlfetch(uri,trace_level=0):
452452
is loaded with urllib.
453453
"""
454454
uri = uri.strip()
455-
if uri.startswith('ldap:') or uri.startswith('ldaps:') or uri.startswith('ldapi:'):
455+
if uri.startswith(('ldap:', 'ldaps:', 'ldapi:')):
456456
import ldapurl
457457
ldap_url = ldapurl.LDAPUrl(uri)
458458

459-
# This is an internal function; don't enable bytes_mode.
460-
l=ldap.initialize(ldap_url.initializeUrl(),trace_level,bytes_mode=False)
459+
l=ldap.initialize(ldap_url.initializeUrl(),trace_level)
461460
l.protocol_version = ldap.VERSION3
462-
l.simple_bind_s(ldap_url.who or '', ldap_url.cred or '')
461+
l.simple_bind_s(ldap_url.who or u'', ldap_url.cred or u'')
463462
subschemasubentry_dn = l.search_subschemasubentry_s(ldap_url.dn)
464463
if subschemasubentry_dn is None:
465464
s_temp = None

Tests/t_ldap_schema_subentry.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88
import os
99
import unittest
10-
import time
10+
11+
# Switch off processing .ldaprc or ldap.conf before importing _ldap
12+
os.environ['LDAPNOINIT'] = '1'
13+
import ldap
1114

1215
import ldif
16+
from ldap.ldapobject import SimpleLDAPObject
1317
import ldap.schema
1418
from ldap.schema.models import ObjectClass
19+
from slapdtest import SlapdTestCase
1520

1621
HERE = os.path.abspath(os.path.dirname(__file__))
1722

@@ -44,5 +49,48 @@ def test_subschema_file(self):
4449
self.assertEqual(attributetype.oid, oid)
4550

4651

52+
class TestSubschemaUrlfetch(unittest.TestSuite):
53+
def test_urlfetch_file(self):
54+
freeipa_uri = 'file://{}'.format(TEST_SUBSCHEMA_FILES[0])
55+
dn, schema = ldap.schema.urlfetch(freeipa_uri)
56+
self.assertEqual(dn, 'cn=schema')
57+
self.assertIsInstance(schema, ldap.schema.subentry.SubSchema)
58+
obj = schema.get_obj(ObjectClass, '2.5.6.9')
59+
self.assertEqual(
60+
str(obj),
61+
"( 2.5.6.9 NAME 'groupOfNames' SUP top STRUCTURAL MUST cn "
62+
"MAY ( member $ businessCategory $ seeAlso $ owner $ ou $ o "
63+
"$ description ) )"
64+
)
65+
66+
67+
class TestSubschemaUrlfetchSlapd(SlapdTestCase):
68+
ldap_object_class = SimpleLDAPObject
69+
70+
def assertSlapdSchema(self, dn, schema):
71+
self.assertEqual(dn, 'cn=Subschema')
72+
self.assertIsInstance(schema, ldap.schema.subentry.SubSchema)
73+
obj = schema.get_obj(ObjectClass, '1.3.6.1.1.3.1')
74+
self.assertEqual(
75+
str(obj),
76+
"( 1.3.6.1.1.3.1 NAME 'uidObject' DESC 'RFC2377: uid object' "
77+
"SUP top AUXILIARY MUST uid )"
78+
)
79+
entries = schema.ldap_entry()
80+
self.assertIsInstance(entries, dict)
81+
self.assertEqual(sorted(entries), [
82+
'attributeTypes', 'ldapSyntaxes', 'matchingRuleUse',
83+
'matchingRules', 'objectClasses',
84+
])
85+
86+
def test_urlfetch_ldap(self):
87+
dn, schema = ldap.schema.urlfetch(self.server.ldap_uri)
88+
self.assertSlapdSchema(dn, schema)
89+
90+
def test_urlfetch_ldapi(self):
91+
dn, schema = ldap.schema.urlfetch(self.server.ldapi_uri)
92+
self.assertSlapdSchema(dn, schema)
93+
94+
4795
if __name__ == '__main__':
4896
unittest.main()

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