Skip to content

Add support for X-ORIGIN in schema element class ObjectClass #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 7, 2019
17 changes: 13 additions & 4 deletions Lib/ldap/schema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class ObjectClass(SchemaElement):
sup
This list of strings contains NAMEs or OIDs of object classes
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. It can a list of strings
Copy link
Member

@encukou encukou Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the source of the associated schema element. It can a list of strings
the source of the associated schema element. It should be a tuple of strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. But it has a small typo - "be be"

Copy link
Contributor Author

@droideck droideck Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should we change other docstrings then for the consistency? For example, 'may' also should be a tuple but the docstring states 'This list of strings':

may
    This list of strings contains NAMEs or OIDs of additional attributes
    an entry of the object class may have

I can add one more commit here for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess "sequence" is the exact thing we want here.
Perhaps write it out as "sequence (list/tuple)", to aid people who don't actively know that definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, list wouldn't work because the SchemaElement class explicitly requires a 'tuple'.

class SchemaElement:
    def key_list(self,key,values,sep=' ',quoted=0):
        assert type(values)==tuple,TypeError("values has to be a tuple, was %r" % values)

"""
schema_attribute = u'objectClasses'
token_defaults = {
Expand All @@ -137,7 +140,8 @@ class ObjectClass(SchemaElement):
'AUXILIARY':None,
'ABSTRACT':None,
'MUST':(()),
'MAY':()
'MAY':(),
'X-ORIGIN':()
}

def _set_attrs(self,l,d):
Expand All @@ -146,6 +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']
# Default is STRUCTURAL, see RFC2552 or draft-ietf-ldapbis-syntaxes
self.kind = 0
if d['ABSTRACT']!=None:
Expand All @@ -168,6 +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_list('X-ORIGIN',self.x_origin,quoted=1))
return '( %s )' % ''.join(result)


Expand Down Expand Up @@ -224,6 +230,9 @@ class AttributeType(SchemaElement):
sup
This list of strings contains NAMEs or OIDs of attribute types
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. It can a list of strings
"""
schema_attribute = u'attributeTypes'
token_defaults = {
Expand All @@ -239,7 +248,7 @@ class AttributeType(SchemaElement):
'COLLECTIVE':None,
'NO-USER-MODIFICATION':None,
'USAGE':('userApplications',),
'X-ORIGIN':(None,),
'X-ORIGIN':(),
'X-ORDERED':(None,),
}

Expand All @@ -251,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 @@ -302,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
26 changes: 24 additions & 2 deletions Tests/t_ldap_schema_subentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import ldif
from ldap.ldapobject import SimpleLDAPObject
import ldap.schema
from ldap.schema.models import ObjectClass
from ldap.schema.models import ObjectClass, AttributeType
from slapdtest import SlapdTestCase, requires_ldapi

HERE = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -61,10 +61,32 @@ def test_urlfetch_file(self):
str(obj),
"( 2.5.6.9 NAME 'groupOfNames' SUP top STRUCTURAL MUST cn "
"MAY ( member $ businessCategory $ seeAlso $ owner $ ou $ o "
"$ description ) )"
"$ description ) X-ORIGIN 'RFC 4519' )"
)


class TestXOrigin(unittest.TestCase):
def get_attribute_type(self, oid):
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.16.840.1.113719.1.301.4.24.1').x_origin,
())

def test_origin_string(self):
self.assertEqual(
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):
ldap_object_class = SimpleLDAPObject

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy