Skip to content

Commit 7d1359c

Browse files
committed
Add multi-value support to X-ORIGIN attribute
1 parent 9f5a578 commit 7d1359c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Lib/ldap/schema/models.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ObjectClass(SchemaElement):
128128
this object class is derived from
129129
x-origin
130130
This string contains the X-ORIGIN text which is typically used to indicate
131-
the source of the associated schema element
131+
the source of the associated schema element. It can a list of strings
132132
"""
133133
schema_attribute = u'objectClasses'
134134
token_defaults = {
@@ -141,7 +141,7 @@ class ObjectClass(SchemaElement):
141141
'ABSTRACT':None,
142142
'MUST':(()),
143143
'MAY':(),
144-
'X-ORIGIN':(None,)
144+
'X-ORIGIN':()
145145
}
146146

147147
def _set_attrs(self,l,d):
@@ -150,7 +150,7 @@ def _set_attrs(self,l,d):
150150
self.desc = d['DESC'][0]
151151
self.must = d['MUST']
152152
self.may = d['MAY']
153-
self.x_origin = d['X-ORIGIN'][0]
153+
self.x_origin = d['X-ORIGIN']
154154
# Default is STRUCTURAL, see RFC2552 or draft-ietf-ldapbis-syntaxes
155155
self.kind = 0
156156
if d['ABSTRACT']!=None:
@@ -173,7 +173,7 @@ def __str__(self):
173173
result.append({0:' STRUCTURAL',1:' ABSTRACT',2:' AUXILIARY'}[self.kind])
174174
result.append(self.key_list('MUST',self.must,sep=' $ '))
175175
result.append(self.key_list('MAY',self.may,sep=' $ '))
176-
result.append(self.key_attr('X-ORIGIN',self.x_origin,quoted=1))
176+
result.append(self.key_list('X-ORIGIN',self.x_origin,quoted=1))
177177
return '( %s )' % ''.join(result)
178178

179179

@@ -232,7 +232,7 @@ class AttributeType(SchemaElement):
232232
this attribute type is derived from
233233
x-origin
234234
This string contains the X-ORIGIN text which is typically used to indicate
235-
the source of the associated schema element
235+
the source of the associated schema element. It can a list of strings
236236
"""
237237
schema_attribute = u'attributeTypes'
238238
token_defaults = {
@@ -248,7 +248,7 @@ class AttributeType(SchemaElement):
248248
'COLLECTIVE':None,
249249
'NO-USER-MODIFICATION':None,
250250
'USAGE':('userApplications',),
251-
'X-ORIGIN':(None,),
251+
'X-ORIGIN':(),
252252
'X-ORDERED':(None,),
253253
}
254254

@@ -260,7 +260,7 @@ def _set_attrs(self,l,d):
260260
self.equality = d['EQUALITY'][0]
261261
self.ordering = d['ORDERING'][0]
262262
self.substr = d['SUBSTR'][0]
263-
self.x_origin = d['X-ORIGIN'][0]
263+
self.x_origin = d['X-ORIGIN']
264264
self.x_ordered = d['X-ORDERED'][0]
265265
try:
266266
syntax = d['SYNTAX'][0]
@@ -311,7 +311,7 @@ def __str__(self):
311311
3:" USAGE dSAOperation",
312312
}[self.usage]
313313
)
314-
result.append(self.key_attr('X-ORIGIN',self.x_origin,quoted=1))
314+
result.append(self.key_list('X-ORIGIN',self.x_origin,quoted=1))
315315
result.append(self.key_attr('X-ORDERED',self.x_ordered,quoted=1))
316316
return '( %s )' % ''.join(result)
317317

Tests/t_ldap_schema_subentry.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,24 @@ def test_urlfetch_file(self):
6767

6868
class TestXOrigin(unittest.TestCase):
6969
def get_attribute_type(self, oid):
70-
openldap_uri = 'file://{}'.format(TEST_SUBSCHEMA_FILES[1])
70+
openldap_uri = 'file://{}'.format(TEST_SUBSCHEMA_FILES[0])
7171
dn, schema = ldap.schema.urlfetch(openldap_uri)
7272
return schema.get_obj(AttributeType, oid)
7373

7474
def test_origin_none(self):
7575
self.assertEqual(
76-
self.get_attribute_type('2.5.4.0').x_origin, None)
76+
self.get_attribute_type('2.16.840.1.113719.1.301.4.24.1').x_origin,
77+
())
7778

7879
def test_origin_string(self):
7980
self.assertEqual(
80-
self.get_attribute_type('1.3.6.1.4.1.3401.8.2.8').x_origin,
81-
'Pretty Good Privacy (PGP)')
81+
self.get_attribute_type('2.16.840.1.113730.3.1.2091').x_origin,
82+
('Netscape',))
83+
84+
def test_origin_multi_valued(self):
85+
self.assertEqual(
86+
self.get_attribute_type('1.3.6.1.4.1.11.1.3.1.1.3').x_origin,
87+
('RFC4876', 'user defined'))
8288

8389

8490
class TestSubschemaUrlfetchSlapd(SlapdTestCase):

0 commit comments

Comments
 (0)