Skip to content

Commit

Permalink
Add tests for schema urlfetch
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes committed Nov 30, 2017
1 parent 0d48145 commit 725c623
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Lib/ldap/schema/subentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def urlfetch(uri,trace_level=0):
is loaded with urllib.
"""
uri = uri.strip()
if uri.startswith('ldap:') or uri.startswith('ldaps:') or uri.startswith('ldapi:'):
if uri.startswith(('ldap:', 'ldaps:', 'ldapi:')):
import ldapurl
ldap_url = ldapurl.LDAPUrl(uri)

Expand Down
50 changes: 49 additions & 1 deletion Tests/t_ldap_schema_subentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@

import os
import unittest
import time

# Switch off processing .ldaprc or ldap.conf before importing _ldap
os.environ['LDAPNOINIT'] = '1'
import ldap

import ldif
from ldap.ldapobject import SimpleLDAPObject
import ldap.schema
from ldap.schema.models import ObjectClass
from slapdtest import SlapdTestCase

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

Expand Down Expand Up @@ -44,5 +49,48 @@ def test_subschema_file(self):
self.assertEqual(attributetype.oid, oid)


class TestSubschemaUrlfetch(unittest.TestSuite):
def test_urlfetch_file(self):
freeipa_uri = 'file://{}'.format(TEST_SUBSCHEMA_FILES[0])
dn, schema = ldap.schema.urlfetch(freeipa_uri)
self.assertEqual(dn, 'cn=schema')
self.assertIsInstance(schema, ldap.schema.subentry.SubSchema)
obj = schema.get_obj(ObjectClass, '2.5.6.9')
self.assertEqual(
str(obj),
"( 2.5.6.9 NAME 'groupOfNames' SUP top STRUCTURAL MUST cn "
"MAY ( member $ businessCategory $ seeAlso $ owner $ ou $ o "
"$ description ) )"
)


class TestSubschemaUrlfetchSlapd(SlapdTestCase):
ldap_object_class = SimpleLDAPObject

def assertSlapdSchema(self, dn, schema):
self.assertEqual(dn, 'cn=Subschema')
self.assertIsInstance(schema, ldap.schema.subentry.SubSchema)
obj = schema.get_obj(ObjectClass, '1.3.6.1.1.3.1')
self.assertEqual(
str(obj),
"( 1.3.6.1.1.3.1 NAME 'uidObject' DESC 'RFC2377: uid object' "
"SUP top AUXILIARY MUST uid )"
)
entries = schema.ldap_entry()
self.assertIsInstance(entries, dict)
self.assertEqual(sorted(entries), [
'attributeTypes', 'ldapSyntaxes', 'matchingRuleUse',
'matchingRules', 'objectClasses',
])

def test_urlfetch_ldap(self):
dn, schema = ldap.schema.urlfetch(self.server.ldap_uri)
self.assertSlapdSchema(dn, schema)

def test_urlfetch_ldapi(self):
dn, schema = ldap.schema.urlfetch(self.server.ldapi_uri)
self.assertSlapdSchema(dn, schema)


if __name__ == '__main__':
unittest.main()

0 comments on commit 725c623

Please sign in to comment.