#!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import with_statement import pytest import sys import subprocess from tempfile import NamedTemporaryFile as tempfile import re from ldapcherry import LdapCherry from ldapcherry.exceptions import * from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError import ldapcherry.backend.backendAD import cherrypy from cherrypy.process import plugins, servers from cherrypy import Application import logging from ldapcherry.lclogging import * from disable import * import json from tidylib import tidy_document if sys.version < '3': from sets import Set as set cherrypy.session = {} adcfg = { 'display_name': u'test☭', 'domain': 'DC.LDAPCHERRY.ORG', 'login': 'Administrator', 'password': 'qwertyP455', 'uri': 'ldaps://ad.ldapcherry.org', 'checkcert': 'off', } adattr = ['shell', 'cn', 'sAMAccountName', 'uidNumber', 'gidNumber', 'home', 'unicodePwd', 'givenName', 'email', 'sn'] addefault_user = { 'sAMAccountName': u'☭default_user', 'sn': u'test☭1', 'cn': u'test☭2', 'unicodePwd': u'test☭P666', 'uidNumber': '42', 'gidNumber': '42', 'homeDirectory': '/home/test/' } # 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 conf = {'/static': {'tools.staticdir.dir': './resources/static/', 'tools.staticdir.on': True}, 'roles': {'roles.file': './tests/cfg/roles.yml'}, 'global': {'tools.sessions.on': True, 'log.access_handler': 'syslog', 'log.level': 'debug', 'server.thread_pool': 8, 'log.error_handler': 'syslog', 'server.socket_port': 8080, 'server.socket_host': '127.0.0.1', 'tools.sessions.timeout': 10, 'request.show_tracebacks': False}, 'auth': {'auth.mode': 'or'}, 'backends': {'ldap.checkcert': 'off', 'ldap.module': 'ldapcherry.backends.ldap', 'ldap.uri': 'ldaps://ldap.ldapcherry.org', 'ldap.starttls': 'on', 'ldap.groupdn': 'ou=group,dc=example,dc=com', 'ldap.people': 'ou=group,dc=example,dc=com', 'ldap.authdn': 'cn=ldapcherry,dc=example,dc=com', 'ldap.password': 'password', 'ldap.ca': '/etc/dnscherry/TEST-cacert.pem', 'ad.module': 'ldapcherry.backends.ad', 'ad.auth': 'Administrator', 'ad.password': 'password'}, 'attributes': {'attributes.file': './tests/cfg/attributes.yml'}, 'resources': {'templates.dir': './resources/templates/'}} def loadconf(configfile, instance): app = cherrypy.tree.mount(instance, '/', configfile) cherrypy.config.update(configfile) instance.reload(app.config) class HtmlValidationFailed(Exception): def __init__(self, out): self.errors = out def _is_html_error(line): for p in [ r'.*Warning: trimming empty .*', r'.*Error: