|
7 | 7 |
|
8 | 8 | import os
|
9 | 9 | 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 |
11 | 14 |
|
12 | 15 | import ldif
|
| 16 | +from ldap.ldapobject import SimpleLDAPObject |
13 | 17 | import ldap.schema
|
14 | 18 | from ldap.schema.models import ObjectClass
|
| 19 | +from slapdtest import SlapdTestCase |
15 | 20 |
|
16 | 21 | HERE = os.path.abspath(os.path.dirname(__file__))
|
17 | 22 |
|
@@ -44,5 +49,48 @@ def test_subschema_file(self):
|
44 | 49 | self.assertEqual(attributetype.oid, oid)
|
45 | 50 |
|
46 | 51 |
|
| 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 | + |
47 | 95 | if __name__ == '__main__':
|
48 | 96 | unittest.main()
|
0 commit comments