From 7d1359c9852815a635de9ac01a2767e5b577d512 Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Mon, 26 Nov 2018 02:19:35 +0100 Subject: [PATCH] Add multi-value support to X-ORIGIN attribute --- Lib/ldap/schema/models.py | 16 ++++++++-------- Tests/t_ldap_schema_subentry.py | 14 ++++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Lib/ldap/schema/models.py b/Lib/ldap/schema/models.py index 18d24fb..22affa2 100644 --- a/Lib/ldap/schema/models.py +++ b/Lib/ldap/schema/models.py @@ -128,7 +128,7 @@ class ObjectClass(SchemaElement): this object class is derived from x-origin This string contains the X-ORIGIN text which is typically used to indicate - the source of the associated schema element + the source of the associated schema element. It can a list of strings """ schema_attribute = u'objectClasses' token_defaults = { @@ -141,7 +141,7 @@ class ObjectClass(SchemaElement): 'ABSTRACT':None, 'MUST':(()), 'MAY':(), - 'X-ORIGIN':(None,) + 'X-ORIGIN':() } def _set_attrs(self,l,d): @@ -150,7 +150,7 @@ def _set_attrs(self,l,d): self.desc = d['DESC'][0] self.must = d['MUST'] self.may = d['MAY'] - self.x_origin = d['X-ORIGIN'][0] + self.x_origin = d['X-ORIGIN'] # Default is STRUCTURAL, see RFC2552 or draft-ietf-ldapbis-syntaxes self.kind = 0 if d['ABSTRACT']!=None: @@ -173,7 +173,7 @@ def __str__(self): result.append({0:' STRUCTURAL',1:' ABSTRACT',2:' AUXILIARY'}[self.kind]) result.append(self.key_list('MUST',self.must,sep=' $ ')) result.append(self.key_list('MAY',self.may,sep=' $ ')) - result.append(self.key_attr('X-ORIGIN',self.x_origin,quoted=1)) + result.append(self.key_list('X-ORIGIN',self.x_origin,quoted=1)) return '( %s )' % ''.join(result) @@ -232,7 +232,7 @@ class AttributeType(SchemaElement): this attribute type is derived from x-origin This string contains the X-ORIGIN text which is typically used to indicate - the source of the associated schema element + the source of the associated schema element. It can a list of strings """ schema_attribute = u'attributeTypes' token_defaults = { @@ -248,7 +248,7 @@ class AttributeType(SchemaElement): 'COLLECTIVE':None, 'NO-USER-MODIFICATION':None, 'USAGE':('userApplications',), - 'X-ORIGIN':(None,), + 'X-ORIGIN':(), 'X-ORDERED':(None,), } @@ -260,7 +260,7 @@ def _set_attrs(self,l,d): self.equality = d['EQUALITY'][0] self.ordering = d['ORDERING'][0] self.substr = d['SUBSTR'][0] - self.x_origin = d['X-ORIGIN'][0] + self.x_origin = d['X-ORIGIN'] self.x_ordered = d['X-ORDERED'][0] try: syntax = d['SYNTAX'][0] @@ -311,7 +311,7 @@ def __str__(self): 3:" USAGE dSAOperation", }[self.usage] ) - result.append(self.key_attr('X-ORIGIN',self.x_origin,quoted=1)) + result.append(self.key_list('X-ORIGIN',self.x_origin,quoted=1)) result.append(self.key_attr('X-ORDERED',self.x_ordered,quoted=1)) return '( %s )' % ''.join(result) diff --git a/Tests/t_ldap_schema_subentry.py b/Tests/t_ldap_schema_subentry.py index edce931..3fc394d 100644 --- a/Tests/t_ldap_schema_subentry.py +++ b/Tests/t_ldap_schema_subentry.py @@ -67,18 +67,24 @@ def test_urlfetch_file(self): class TestXOrigin(unittest.TestCase): def get_attribute_type(self, oid): - openldap_uri = 'file://{}'.format(TEST_SUBSCHEMA_FILES[1]) + openldap_uri = 'file://{}'.format(TEST_SUBSCHEMA_FILES[0]) dn, schema = ldap.schema.urlfetch(openldap_uri) return schema.get_obj(AttributeType, oid) def test_origin_none(self): self.assertEqual( - self.get_attribute_type('2.5.4.0').x_origin, None) + self.get_attribute_type('2.16.840.1.113719.1.301.4.24.1').x_origin, + ()) def test_origin_string(self): self.assertEqual( - self.get_attribute_type('1.3.6.1.4.1.3401.8.2.8').x_origin, - 'Pretty Good Privacy (PGP)') + self.get_attribute_type('2.16.840.1.113730.3.1.2091').x_origin, + ('Netscape',)) + + def test_origin_multi_valued(self): + self.assertEqual( + self.get_attribute_type('1.3.6.1.4.1.11.1.3.1.1.3').x_origin, + ('RFC4876', 'user defined')) class TestSubschemaUrlfetchSlapd(SlapdTestCase):