コード例 #1
0
ファイル: test_LdapCherry.py プロジェクト: zktr/ldapcherry
 def testLogin(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     app.auth_mode = 'or'
     try:
         app.login(u'jwatsoné', u'passwordwatsoné')
     except cherrypy.HTTPRedirect as e:
         expected = 'http://127.0.0.1:8080/'
         assert e.urls[0] == expected
     else:
         raise AssertionError("expected an exception")
コード例 #2
0
 def testLoginFailure(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     app.auth_mode = 'or'
     try:
         app.login('jwatson', 'wrongPassword')
     except cherrypy.HTTPRedirect as e:
         expected = 'http://127.0.0.1:8080/signin'
         assert e[0][0] == expected
     else:
         raise AssertionError("expected an exception")
コード例 #3
0
    def testModifyUserOneBackend(self):
        app = LdapCherry()
        loadconf('./tests/cfg/ldapcherry_adldap.cfg', app)
        inv = ldapcherry.backend.backendAD.Backend(adcfg, cherrypy.log, u'test☭', adattr, 'sAMAccountName')
	try:
            app._deleteuser(u'☭default_user')
        except:
            pass
        inv.add_user(addefault_user.copy())
        modify_form = { 'attrs': {'first-name': u'Test42 ☭', 'uid': u'☭default_user'}, 'roles': { 'admin-lv3': u'on'}}
        app._modify(modify_form)
        app._deleteuser(u'☭default_user')
コード例 #4
0
 def testLogger(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry.ini', app)
     assert get_loglevel('debug') is logging.DEBUG and \
     get_loglevel('notice') is logging.INFO and \
     get_loglevel('info') is logging.INFO and \
     get_loglevel('warning') is logging.WARNING and \
     get_loglevel('err') is logging.ERROR and \
     get_loglevel('critical') is logging.CRITICAL and \
     get_loglevel('alert') is logging.CRITICAL and \
     get_loglevel('emergency') is logging.CRITICAL and \
     get_loglevel('notalevel') is logging.INFO
コード例 #5
0
 def testHtml(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     pages = {
             'signin': app.signin(),
             'index': app.index(),
             'searchuser': app.searchuser('smit'),
             'searchadmin':app.searchadmin('smit'),
             'adduser': app.adduser(),
             'modify':app.modify('jsmith'),
             'selfmodify':app.selfmodify(),
             }
     for page in pages:
         print(page)
         htmlvalidator(pages[page])
コード例 #6
0
 def testGetUser(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     expected = {
         'password': u'passwordsmith',
         'cn': u'Sheri Smith',
         'uid': u'ssmith',
         'name': u'smith',
         'email': [u'*****@*****.**',
                  u'*****@*****.**',
                  u'*****@*****.**'
             ],
         }
     ret = app._get_user('ssmith')
     assert expected == ret
コード例 #7
0
ファイル: test_LdapCherry.py プロジェクト: zktr/ldapcherry
 def testParse(self):
     app = LdapCherry()
     form = {'attr.val': 'val', 'role.id': 'id', 'group.ldap.id': 'id'}
     ret = app._parse_params(form)
     expected = {
         'attrs': {
             'val': 'val'
         },
         'roles': {
             'id': 'id'
         },
         'groups': {
             'ldap': ['id']
         }
     }
     assert expected == ret
コード例 #8
0
 def testNaughtyStrings(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     with open('./tests/cfg/blns.json') as data_file:
         data = json.load(data_file)
     for attr in data:
         print('testing: ' + attr)
         # delete whatever is happening...
         try:
             app._deleteuser('test')
         except:
             pass
         form = {'groups': {}, 'attrs': {'password1': u'password☭', 'password2': u'password☭', 'cn': 'Test', 'name': attr, 'uidNumber': u'1000', 'gidNumber': u'1000', 'home': u'/home/test', 'first-name': u'Test ☭', 'email': u'*****@*****.**', 'uid': 'test'}, 'roles': {'admin-lv3': u'on', 'admin-lv2': u'on', 'users': u'on'}}
         app._adduser(form)
         page = app.searchuser('test'),
         app._deleteuser('test')
         htmlvalidator(page[0])
コード例 #9
0
ファイル: debug_lc.py プロジェクト: zktr/ldapcherry
        if section not in result:
            result[section] = {}
        for option in self.options(section):
            value = self.get(section, option, raw=raw, vars=vars)
            try:
                value = cherrypy.lib.reprconf.unrepr(value)
            except Exception:
                x = sys.exc_info()[1]
                msg = ("Config error in section: %r, option: %r, "
                       "value: %r. Config values must be valid Python." %
                       (section, option, value))
                raise ValueError(msg, x.__class__.__name__, x.args)
            result[section][option] = value
    return result
cherrypy.lib.reprconf.Parser.as_dict = new_as_dict


def loadconf(configfile, instance):
    app = cherrypy.tree.mount(instance, '/', configfile)
    cherrypy.config.update(configfile)
    instance.reload(app.config)

app = LdapCherry()
loadconf('./tests/cfg/ldapcherry.ini', app)
ret = app._get_user('ssmith')
print ret

}

form = {'groups': {}, 'attrs': {'password1': u'password☭', 'password2': u'password☭', 'shell': u'/bin/zsh', 'cn': u'Test ☭ Test', 'name': u'Test ☭', 'uidNumber': u'1000', 'gidNumber': u'1000', 'home': u'/home/test', 'first-name': u'Test ☭', 'email': u'*****@*****.**', 'uid': u'test'}, 'roles': {'admin-lv3': u'on', 'admin-lv2': u'on', 'users': u'on'}}
コード例 #10
0
 def testNominal(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry.ini', app)
     return True
コード例 #11
0
def start(configfile=None,
          daemonize=False,
          environment=None,
          fastcgi=False,
          scgi=False,
          pidfile=None,
          cgi=False,
          debug=False,
          context_root='/'):
    """Subscribe all engine plugins and start the engine."""
    sys.path = [''] + sys.path

    # monkey patching cherrypy to disable config interpolation
    def new_as_dict(self, raw=True, vars=None):
        """Convert an INI file to a dictionary"""
        # Load INI file into a dict
        result = {}
        for section in self.sections():
            if section not in result:
                result[section] = {}
            for option in self.options(section):
                value = self.get(section, option, raw=raw, vars=vars)
                try:
                    value = cherrypy.lib.reprconf.unrepr(value)
                except Exception:
                    x = sys.exc_info()[1]
                    msg = ("Config error in section: %r, option: %r, "
                           "value: %r. Config values must be valid Python." %
                           (section, option, value))
                    raise ValueError(msg, x.__class__.__name__, x.args)
                result[section][option] = value
        return result

    cherrypy.lib.reprconf.Parser.as_dict = new_as_dict

    class Root(object):
        @cherrypy.expose
        def index(self):
            return 'Nothing here'

    instance = LdapCherry()
    if context_root != '/':
        root = cherrypy.tree.mount(Root())
    app = cherrypy.tree.mount(instance, context_root, configfile)
    cherrypy.config.update(configfile)
    instance.reload(app.config, debug)

    engine = cherrypy.engine

    # Turn off autoreload
    cherrypy.config.update({'engine.autoreload.on': False})

    if environment is not None:
        cherrypy.config.update({'environment': environment})

    # Only daemonize if asked to.
    if daemonize:
        # Don't print anything to stdout/sterr.
        cherrypy.config.update({'log.screen': False})
        plugins.Daemonizer(engine).subscribe()

    if pidfile:
        plugins.PIDFile(engine, pidfile).subscribe()

    if hasattr(engine, "signal_handler"):
        engine.signal_handler.subscribe()
    if hasattr(engine, "console_control_handler"):
        engine.console_control_handler.subscribe()

    if (fastcgi and (scgi or cgi)) or (scgi and cgi):
        cherrypy.log.error(
            "You may only specify one of the cgi, fastcgi, and "
            "scgi options.", 'ENGINE')
        sys.exit(1)
    elif fastcgi or scgi or cgi:
        # Turn off the default HTTP server (which is subscribed by default).
        cherrypy.server.unsubscribe()

        addr = cherrypy.server.bind_addr
        if fastcgi:
            f = servers.FlupFCGIServer(application=cherrypy.tree,
                                       bindAddress=addr)
        elif scgi:
            f = servers.FlupSCGIServer(application=cherrypy.tree,
                                       bindAddress=addr)
        else:
            f = servers.FlupCGIServer(application=cherrypy.tree,
                                      bindAddress=addr)
        s = servers.ServerAdapter(engine, httpserver=f, bind_addr=addr)
        s.subscribe()

    # Always start the engine; this will start all other services
    try:
        engine.start()
    except Exception as e:
        # Assume the error has been logged already via bus.log.
        sys.exit(1)
    else:
        engine.block()
コード例 #12
0
 def testDeleteUserOneBackend(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_adldap.cfg', app)
     inv = ldapcherry.backend.backendAD.Backend(adcfg, cherrypy.log, u'test☭', adattr, 'sAMAccountName')
     inv.add_user(addefault_user.copy())
     app._deleteuser(u'☭default_user')
コード例 #13
0
 def testNoneModify(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     app.modify(user=None)
コード例 #14
0
 def testNoneType(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     app.modify('ssmith')
コード例 #15
0
 def testPPolicy(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry.ini', app)
     wrong = app._checkppolicy('password')['match']
     good = app._checkppolicy('Passw0rd.')['match']
     assert wrong == False and good == True
コード例 #16
0
 def testAddUser(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry_test.ini', app)
     form = {'groups': {}, 'attrs': {'password1': u'password☭', 'password2': u'password☭', 'cn': u'Test ☭ Test', 'name': u'Test ☭', 'uidNumber': u'1000', 'gidNumber': u'1000', 'home': u'/home/test', 'first-name': u'Test ☭', 'email': u'*****@*****.**', 'uid': u'test'}, 'roles': {'admin-lv3': u'on', 'admin-lv2': u'on', 'users': u'on'}}
     app._adduser(form)
     app._deleteuser('test')
コード例 #17
0
 def testRandomException(self):
     app = LdapCherry()
     loadconf('./tests/cfg/ldapcherry.ini', app)
     e = Exception()
     app._handle_exception(e)