Example #1
0
 def testWrongType(self):
     try:
         inv = Attributes('./tests/cfg/attributes_wrong_type.yml')
     except WrongAttributeType:
         return
     else:
         raise AssertionError("expected an exception")
Example #2
0
 def testDuplicatePassword(self):
     try:
         inv = Attributes('./tests/cfg/attribute_pwderror.yml')
     except PasswordAttributesCollision:
         return
     else:
         raise AssertionError("expected an exception")
Example #3
0
 def testNoFile(self):
     try:
         inv = Attributes('./tests/cfg/dontexist')
     except MissingAttributesFile:
         return
     else:
         raise AssertionError("expected an exception")
Example #4
0
 def testMissingMandatory(self):
     try:
         inv = Attributes('./tests/cfg/attributes_missing_mandatory.yml')
     except MissingKey:
         return
     else:
         raise AssertionError("expected an exception")
Example #5
0
 def testWrongGetBackendAttributes(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     try:
         ret = inv.get_backend_attributes('notabackend')
     except WrongBackend:
         return
     else:
         raise AssertionError("expected an exception")
Example #6
0
    def reload(self, config=None, debug=False):
        """ load/reload configuration
        @dict: configuration of ldapcherry
        """
        try:
            # log configuration handling
            # get log level
            # (if not in configuration file, log level is set to debug)
            level = get_loglevel(
                self._get_param(
                    'global',
                    'log.level',
                    config,
                    'debug',
                ))
            # configure access log
            self._set_access_log(config, level)
            # configure error log
            self._set_error_log(config, level, debug)

            # load template files
            self._load_templates(config)

            # loading the auth configuration
            self._init_auth(config)

            # Loading the attributes
            self.attributes_file = \
                self._get_param('attributes', 'attributes.file', config)
            cherrypy.log.error(msg="loading attributes file '%(file)s'" %
                               {'file': self.attributes_file},
                               severity=logging.DEBUG)

            self.notifications = {}

            self.attributes = Attributes(self.attributes_file)

            cherrypy.log.error(msg="init directories backends",
                               severity=logging.DEBUG)
            self._init_backends(config)
            self._check_backends()

            # loading the ppolicy
            self._init_ppolicy(config)

            # loading custom javascript
            self._init_custom_js(config)

            cherrypy.log.error(msg="application started",
                               severity=logging.INFO)

        except Exception as e:
            self._handle_exception(e)
            cherrypy.log.error(msg="application failed to start",
                               severity=logging.ERROR)
            exit(1)
Example #7
0
 def testValidateError(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     attrs = {'email': 'notamail', 'uidNumber': 'not an integer', 'shell': '/bin/not in list', 'logscript': 'not fixed'}
     for attrid in attrs:
         try:
             inv.check_attr(attrid, attrs[attrid])
         except WrongAttrValue:
             pass
         else:
             raise AssertionError("expected an exception")
Example #8
0
from ldapcherry.attributes import Attributes
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
from yaml import load, dump
import yaml

try:
    from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
    from yaml import Loader, Dumper


class CustomDumper(yaml.SafeDumper):
    "A custom YAML dumper that never emits aliases"

    def ignore_aliases(self, _data):
        return True


try:
    inv = Attributes('./tests/cfg/attributes.yml')
    #inv = Attributes('./tests/cfg/attributes_wrong_type.yml')
except Exception as e:
    print e.log

print inv.backend_attributes
Example #9
0
 def testValidate(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     attrs = {'cn': 'test', 'email': '*****@*****.**', 'uidNumber': 4242, 'shell': '/bin/bash', 'logscript': 'login1.bat'}
     for attrid in attrs:
         inv.check_attr(attrid, attrs[attrid])
Example #10
0
 def testGetKey(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     ret = inv.get_key()
     expected = 'uid'
     assert ret == expected
Example #11
0
 def testGetBackendAttributes(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     ret = inv.get_backend_attributes('ldap')
     expected = ['shell', 'cn', 'userPassword', 'uidNumber', 'gidNumber', 'sn', 'home', 'givenName', 'email', 'uid']
     assert ret == expected
Example #12
0
 def testGetSearchAttributes(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     ret = inv.get_search_attributes()
     expected = {'first-name': {'backends': {'ad': 'givenName', 'ldap': 'givenName'}, 'display_name': 'First Name', 'description': 'First name of the user', 'weight': 20, 'search_displayed': True, 'type': 'string'}, 'cn': {'autofill': {'function': 'cn', 'args': ['$first-name', '$name']}, 'backends': {'ad': 'cn', 'ldap': 'cn'}, 'display_name': 'Display Name', 'description': 'Firt Name and Display Name', 'weight': 30, 'search_displayed': True, 'type': 'string'}, 'name': {'backends': {'ad': 'sn', 'ldap': 'sn'}, 'display_name': 'Name', 'description': 'Family name of the user', 'weight': 10, 'search_displayed': True, 'type': 'string'}, 'uid': {'display_name': 'UID', 'description': 'UID of the user', 'weight': 50, 'autofill': {'function': 'uid', 'args': ['$first-name', '$last-name']}, 'backends': {'ad': 'UID', 'ldap': 'uid'}, 'key': True, 'search_displayed': True, 'type': 'string'}}
     assert ret == expected
Example #13
0
 def testGetSelfAttributes(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     ret = inv.get_backends()
     expected = Set(['ldap', 'ad'])
     assert ret == expected
Example #14
0
 def testGetSelfAttributes(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     ret = inv.get_selfattributes()
     expected = {'password': {'backends': {'ad': 'unicodePwd', 'ldap': 'userPassword'}, 'display_name': 'Password', 'description': 'Password of the user', 'weight': 31, 'self': True, 'type': 'password'}, 'shell': {'backends': {'ad': 'SHELL', 'ldap': 'shell'}, 'display_name': 'Shell', 'description': 'Shell of the user', 'weight': 80, 'values': ['/bin/bash', '/bin/zsh', '/bin/sh'], 'self': True, 'type': 'stringlist'}}
     assert ret == expected
Example #15
0
 def testNominal(self):
     inv = Attributes('./tests/cfg/attributes.yml')
     inv.get_attributes()
     return True