Skip to content

Commit

Permalink
Add multi-value support to X-ORIGIN attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Pichugin committed Nov 27, 2018
1 parent 9f5a578 commit 7d1359c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 8 additions & 8 deletions Lib/ldap/schema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -141,7 +141,7 @@ class ObjectClass(SchemaElement):
'ABSTRACT':None,
'MUST':(()),
'MAY':(),
'X-ORIGIN':(None,)
'X-ORIGIN':()
}

def _set_attrs(self,l,d):
Expand All @@ -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:
Expand All @@ -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)


Expand Down Expand Up @@ -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 = {
Expand All @@ -248,7 +248,7 @@ class AttributeType(SchemaElement):
'COLLECTIVE':None,
'NO-USER-MODIFICATION':None,
'USAGE':('userApplications',),
'X-ORIGIN':(None,),
'X-ORIGIN':(),
'X-ORDERED':(None,),
}

Expand All @@ -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]
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 10 additions & 4 deletions Tests/t_ldap_schema_subentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7d1359c

Please sign in to comment.