def test_invalid_zone_names(zone):
	lo = utils.get_ldap_connection()
	with udm_test.UCSTestUDM() as udm, _ucr.UCSTestConfigRegistry() as ucr:
		pos = 'cn=dns,%s' % (udm.LDAP_BASE,)
		dn = 'zoneName=%s,%s' % (ldap.dn.escape_dn_chars(zone), pos)
		attrs = {
			'nSRecord': ['%(hostname)s.%(domainname)s.'],
			'objectClass': ['dNSZone', 'top'],
			'dNSTTL': ['10800'],
			'relativeDomainName': ['@'],
			'zoneName': [zone],
			'sOARecord': ['%(hostname)s.%(domainname)s. root.%(domainname)s. 9 28800 7200 604800 10800'],
		}
		al = [(key, [v % dict(ucr) for v in val]) for key, val in attrs.items()]
		print(('Creating', dn))
		lo.add(dn, al)
		try:
			utils.wait_for_replication_and_postrun()
			check(zone)

			lo.modify(dn, [('dNSTTL', '10800', '10900')])
			utils.wait_for_replication_and_postrun()
			check(zone)
		finally:
			lo.delete(dn)

		utils.wait_for_replication_and_postrun()
		check(zone, True)
Beispiel #2
0
 def __init__(self,
              connection=None,
              ucr=None,
              name=None,
              typ=None,
              domains=None,
              wlan=None,
              priority=None):
     self.name = name if name else uts.random_string()
     self.typ = typ if typ else random.choice(['whitelist', 'blacklist'])
     if domains:
         self.domains = domains
     else:
         dom = RandomDomain()
         domains = dom.getDomainList(random.randint(1, 10))
         self.domains = sorted(domains)
     if isinstance(wlan, bool):
         self.wlan = wlan
     else:
         self.wlan = random.choice([True, False])
     self.priority = priority if priority else random.randint(1, 10)
     self.ucr = ucr if ucr else ucr_test.UCSTestConfigRegistry()
     if connection:
         self.client = connection
     else:
         self.client = Client.get_test_connection()
Beispiel #3
0
def create_shared_mailfolder(udm, mailHomeServer, mailAddress=None, user_permission=None, group_permission=None):
	with ucr_test.UCSTestConfigRegistry() as ucr:
		domain = ucr.get('domainname').lower()  # lower() can be removed, when #39721 is fixed
		basedn = ucr.get('ldap/base')
	name = uts.random_name()
	folder_mailaddress = ''
	if isinstance(mailAddress, str):
		folder_mailaddress = mailAddress
	elif mailAddress:
		folder_mailaddress = '%s@%s' % (name, domain)

	folder_dn = udm.create_object(
		'mail/folder',
		position='cn=folder,cn=mail,%s' % basedn,
		set={
			'name': name,
			'mailHomeServer': mailHomeServer,
			'mailDomain': domain,
			'mailPrimaryAddress': folder_mailaddress
		},
		append={
			'sharedFolderUserACL': user_permission or [],
			'sharedFolderGroupACL': group_permission or [],
		}
	)
	if mailAddress:
		folder_name = 'shared/%s' % folder_mailaddress
	else:
		folder_name = '%s@%s/INBOX' % (name, domain)
	return folder_dn, folder_name, folder_mailaddress
Beispiel #4
0
	def __init__(self, school, role, school_classes, mode='A', username=None, firstname=None, lastname=None, password=None, mail=None, schools=None):
		super(User, self).__init__(school, role)

		if username:
			self.username = username
			self.dn = self.make_dn()
		if firstname:
			self.firstname = firstname
		if lastname:
			self.lastname = lastname
		if mail:
			self.mail = mail
		if school_classes:
			self.school_classes = school_classes
		self.schools = schools or [self.school]
		self.typ = 'teachersAndStaff' if self.role == 'teacher_staff' else self.role
		self.mode = mode

		utils.wait_for_replication()
		self.ucr = ucr_test.UCSTestConfigRegistry()
		self.ucr.load()
		host = self.ucr.get('ldap/master')
		self.client = Client(host)
		account = utils.UCSTestDomainAdminCredentials()
		admin = account.username
		passwd = account.bindpw
		self.password = password if password else passwd
		self.client.authenticate(admin, passwd)
Beispiel #5
0
 def __init__(self, quota_type="usrquota", fs_type="ext4"):
     ucr = ucr_test.UCSTestConfigRegistry()
     ucr.load()
     self.my_fqdn = '%s.%s' % (ucr.get('hostname'), ucr.get('domainname'))
     account = utils.UCSTestDomainAdminCredentials()
     self.umc_client = Client(self.my_fqdn,
                              username=account.username,
                              password=account.bindpw)
     self.share_name = uts.random_name()
     self.username = uts.random_name()
     self.quota_type = quota_type
     self.fs_type = fs_type
     self.quota_policy = {
         "inodeSoftLimit":
         '10',
         "inodeHardLimit":
         '15',
         "spaceSoftLimit":
         str(1024**2),
         "spaceHardLimit":
         str(2048**2),
         "reapplyQuota":
         'TRUE',
         "name":
         uts.random_name(),
         "position":
         'cn=userquota,cn=shares,cn=policies,%s' % ucr.get('ldap/base'),
     }
Beispiel #6
0
def connector_setup(sync_mode):
    user_syntax = "directory/manager/web/modules/users/user/properties/username/syntax=string"
    group_syntax = "directory/manager/web/modules/groups/group/properties/name/syntax=string"
    with testing_ucr.UCSTestConfigRegistry():
        ucr_set([user_syntax, group_syntax])
        tcommon.restart_univention_cli_server()
        s4_in_sync_mode(sync_mode)
        yield S4Connection()
Beispiel #7
0
 def __init__(self, school, groupRuleCouples, connection=None, ucr=None):
     self.school = school
     self.groupRuleCouples = groupRuleCouples
     self.ucr = ucr if ucr else ucr_test.UCSTestConfigRegistry()
     if connection:
         self.client = connection
     else:
         self.ucr.load()
         self.client = Client.get_test_connection()
Beispiel #8
0
	def __init__(self, language='en', host=None):
		self._ucr = ucr_test.UCSTestConfigRegistry()
		self._ucr.load()
		self.browser = self.BROWSERS[os.environ.get('UCSTEST_SELENIUM_BROWSER', 'firefox')]
		self.selenium_grid = os.environ.get('UCSTEST_SELENIUM') != 'local'
		self.language = language
		self.base_url = 'https://%s/' % (host or '%s.%s' % (self._ucr.get('hostname'), self._ucr.get('domainname')))
		self.screenshot_path = os.path.abspath('selenium/')
		translator.set_language(self.language)
		logging.basicConfig(level=logging.INFO)
Beispiel #9
0
 def __init__(self, school, user_type):
     self.school = school
     self.user_type = user_type
     self.ucr = ucr_test.UCSTestConfigRegistry()
     self.ucr.load()
     host = self.ucr.get('hostname')
     self.client = Client(host)
     account = utils.UCSTestDomainAdminCredentials()
     admin = account.username
     passwd = account.bindpw
     self.client.authenticate(admin, passwd)
Beispiel #10
0
	def __init__(self, school, connection=None, ucr=None, name=None, users=None, description=None):
		self.school = school
		self.users = users or []
		self.name = name if name else uts.random_string()
		self.description = description if description else uts.random_string()
		self.ucr = ucr if ucr else ucr_test.UCSTestConfigRegistry()
		self.ucr.load()
		if connection:
			self.client = connection
		else:
			self.client = Client.get_test_connection(self.ucr.get('ldap/master'))
Beispiel #11
0
	def __init__(self, quota_type="usrquota", fs_type="ext4"):
		ucr = ucr_test.UCSTestConfigRegistry()
		ucr.load()
		self.ldap_base = ucr.get('ldap/base')
		self.my_fqdn = '%s.%s' % (ucr.get('hostname'), ucr.get('domainname'))
		account = utils.UCSTestDomainAdminCredentials()
		self.umc_client = Client(self.my_fqdn, username=account.username, password=account.bindpw)
		self.share_name = uts.random_name()
		self.share_name2 = uts.random_name()
		self.username = uts.random_name()
		self.quota_type = quota_type
		self.fs_type = fs_type
Beispiel #12
0
    def __init__(self, school, auth_dn, access_allowance):
        """__init__():\n
		:param school: school name
		:type school: string
		:param auth_dn: dn of the authentication actor
		:type auth_dn: ldap object dn
		:param access_allowance: the expected access result
		:type access_allowance: str: 'ALLOWED' or 'DENIED'
		"""
        self.school = school
        self.auth_dn = auth_dn
        self.access_allowance = access_allowance
        self.ucr = ucr_test.UCSTestConfigRegistry()
        self.ucr.load()
 def __init__(self, language='en', host="", suppress_notifications=True):
     # type: (str, str, bool, bool) -> None
     self._ucr = ucr_test.UCSTestConfigRegistry()
     self._ucr.load()
     self.browser = self.BROWSERS[os.environ.get('UCSTEST_SELENIUM_BROWSER',
                                                 'firefox')]
     self.selenium_grid = os.environ.get('UCSTEST_SELENIUM') != 'local'
     self.language = language
     self.base_url = 'https://%s/' % (
         host or '%(hostname)s.%(domainname)s' % self._ucr)
     self.screenshot_path = os.path.abspath('selenium/')
     self.suppress_notifications = suppress_notifications
     translator.set_language(self.language)
     logging.basicConfig(level=logging.INFO)
Beispiel #14
0
	def redirector_is(self, expected_redirector):
		"""Check if the redirector is the same as the passed parameter\n
		:param expected_redirector: in the config file
		:type expected_redirector: string
		:return boolean:True if match, False if not match
		"""
		result = False
		with ucr_test.UCSTestConfigRegistry():
			config_lines = get_lines_containing(self.conf, 'url_rewrite_program')
			if config_lines:
				# in config file the first line setting the redirector is activated
				config_line = config_lines[0]
				result = ('url_rewrite_program %s\n' % (expected_redirector,) == config_line)
			else:
				utils.fail("Squid config redirector line does not exist")
		return result
Beispiel #15
0
def spam_delivered(token, mail_address):
	delivered = False
	spam = False
	with ucr_test.UCSTestConfigRegistry() as ucr:
		spam_folder = ucr.get('mail/dovecot/folder/spam') or 'Spam'
	mail_dir = get_dovecot_maildir(mail_address, folder=spam_folder)
	if not os.path.isdir(mail_dir):
		print('Warning: maildir %r does not exist!' % (mail_dir,))
	for _file in get_dir_files(mail_dir, recursive=True, exclude=["tmp"]):
		with open(_file) as fi:
			content = fi.read()
		delivered = delivered or (token in content)
		if delivered:
			if 'X-Spam-Flag: YES' in content:
				spam = spam or True
			break
	return delivered and spam
Beispiel #16
0
 def __init__(self,
              school,
              connection=None,
              sender=None,
              flavor=None,
              ucr=None,
              description=None,
              name=None,
              distributeType='manual',
              distributeTime=None,
              distributeDate=None,
              collectType='manual',
              collectTime=None,
              collectDate=None,
              files=[],
              recipients=[]):
     account = utils.UCSTestDomainAdminCredentials()
     admin = account.username
     passwd = account.bindpw
     self.school = school
     self.name = name if name else uts.random_string()
     self.description = description if description else uts.random_string()
     if distributeTime:
         self.distributeTime = distributeTime
     else:
         self.distributeTime = time.strftime('%I:%M')
     if distributeDate:
         self.distributeDate = distributeDate
     else:
         self.distributeDate = time.strftime('%Y-%m-%d')
     self.collectTime = collectTime if collectTime else time.strftime(
         '%I:%M')
     self.collectDate = collectDate if collectDate else time.strftime(
         '%Y-%m-%d')
     self.distributeType = distributeType
     self.collectType = collectType
     self.files = files
     self.recipients = recipients
     self.ucr = ucr if ucr else ucr_test.UCSTestConfigRegistry()
     self.sender = sender if sender else admin
     self.flavor = flavor if flavor else 'admin'
     if connection:
         self.client = connection
     else:
         self.client = Client(None, admin, passwd)
Beispiel #17
0
    def test_printMode_settings(self, school, user, ip_address, client, ucr):
        ucr = ucr_test.UCSTestConfigRegistry()
        ucr.load()
        self.aquire_room(client)

        printer = uts.random_string()
        add_printer(printer, school, ucr.get('hostname'),
                    ucr.get('domainname'), ucr.get('ldap/base'))
        try:
            # generate all the possible combinations for (rule, printmode, sharemode)
            white_page = 'univention.de'
            rules = ['none', 'Kein Internet', 'Unbeschränkt', 'custom']
            printmodes = ['default', 'all', 'none']
            sharemodes = ['all', 'home']
            settings = itertools.product(rules, printmodes, sharemodes)
            settings_len = len(printmodes) * len(sharemodes) * len(rules)
            t = 120

            # Testing loop
            for i in xrange(settings_len):
                period = datetime.time.strftime(
                    (datetime.datetime.now() +
                     datetime.timedelta(0, t)).time(), '%H:%M')
                t += 60
                rule, printMode, shareMode = next(settings)
                print
                print '***', i, '-(internetRule, printMode, shareMode) = (', \
                 rule, ',', printMode, ',', shareMode, ')', '-' * 10
                new_settings = {
                    'customRule': white_page,
                    'printMode': printMode,
                    'internetRule': rule,
                    'shareMode': shareMode,
                    'period': period
                }
                self.aquire_room(client)
                self.set_room_settings(client, new_settings)
                # check if displayed values match
                self.check_room_settings(client, new_settings)
                self.check_print_behavior(user, ip_address, printer, printMode)

        finally:
            remove_printer(printer, school, ucr.get('ldap/base'))
Beispiel #18
0
 def __init__(self,
              school,
              connection=None,
              ulConnection=None,
              ucr=None,
              name=None,
              description=None,
              members=None):
     self.school = school
     self.name = name if name else uts.random_string()
     self.description = description if description else uts.random_string()
     self.members = members if members else []
     self.ucr = ucr if ucr else ucr_test.UCSTestConfigRegistry()
     self.ucr.load()
     if ulConnection:
         self.ulConnection = ulConnection
     else:
         self.ulConnection = uu.getMachineConnection(ldap_master=False)
     if connection:
         self.client = connection
     else:
         self.client = Client.get_test_connection()
Beispiel #19
0
def test_write_event():
	with udm_test.UCSTestUDM() as udm, ucr_test.UCSTestConfigRegistry() as ucr, univention.admindiary.backend.get_client(version=1) as client:
		d = (datetime.datetime.now() - datetime.timedelta(seconds=5)).isoformat()
		dn, username = udm.create_user()
		expected = {
			'id': 33,
			'date': datetime.datetime.now().strftime('%y-%m-%d %H:%M:%S'),
			'event_name': 'UDM_USERS_USER_CREATED',
			'hostname': ucr['hostname'],
			'username': '******',
			'message': None,
			'args': {'username': username, 'module': 'users/user'},
			'comments': False
		}
		entries = client.query(d, event='UDM_USERS_USER_CREATED')
		# It is not possible to filter by args in query so we use list comprehension
		x = [entry for entry in entries if entry.get('args', {}).get('username') == username][0]
		assert x is not None
		expected['id'] = x['id']
		expected['date'] = x['date']
		expected['context_id'] = x['context_id']
		assert x == expected
Beispiel #20
0
 def __init__(self,
              school,
              typ,
              name=None,
              ip_address=None,
              subnet_mask=None,
              mac_address=None,
              inventory_number=None):
     self.school = school
     self.typ = typ
     self.name = name if name else uts.random_name()
     self.ip_address = ip_address if ip_address else random_ip()
     self.subnet_mask = subnet_mask if subnet_mask else '255.255.255.0'
     self.mac_address = mac_address.lower() if mac_address else random_mac()
     self.inventory_number = inventory_number if inventory_number else ''
     self.ucr = ucr_test.UCSTestConfigRegistry()
     self.ucr.load()
     host = self.ucr.get('ldap/master')
     self.client = Client(host)
     account = utils.UCSTestDomainAdminCredentials()
     admin = account.username
     passwd = account.bindpw
     self.client.authenticate(admin, passwd)
def ucr():
    with ucr_test.UCSTestConfigRegistry() as ucr:
        yield ucr
Beispiel #22
0
 def __init__(self, selenium):
     super(Users, self).__init__(selenium)
     self.ucr = ucr_test.UCSTestConfigRegistry()
     self.ucr.load()
Beispiel #23
0
def random_email():
    """Create random email in the current domainname"""
    ucr = ucr_test.UCSTestConfigRegistry()
    ucr.load()
    return '%s@%s' % (uts.random_name(), ucr.get('domainname'))
def test_check_enabled_email_unverified():
    with ucr_test.UCSTestConfigRegistry():
        handler_set(['saml/idp/selfservice/check_email_verification=True'])
        with pytest.raises(samltest.SamlLoginError) as excinfo:
            check_login(activated_email=False)
        assert excinfo.value.message == 'Got unverified email notice'
##   - univention-config
##   - univention-directory-manager-tools
##   - univention-mail-server

# pylint: disable=attribute-defined-outside-init

from __future__ import print_function

import pytest
import univention.testing.strings as uts
import univention.testing.ucr as ucr_test
import univention.testing.udm as udm_test
import univention.testing.utils as utils
from essential.mail import send_mail, check_delivery, create_shared_mailfolder, imap_search_mail, random_email, make_token, set_mail_forward_copy_to_self_ucrv

with ucr_test.UCSTestConfigRegistry() as ucr:
    DOMAIN = ucr.get("domainname").lower()
    HOSTNAME = ucr.get("hostname")
    FQDN = "%s.%s" % (HOSTNAME, DOMAIN)

DEBUG_LEVEL = 1
set_mail_forward_copy_to_self_ucrv('yes')


class Bunch(object):
    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

    def __str__(self):
        result = []
        for key, value in self.__dict__.items():
def ucr():
    with _ucr.UCSTestConfigRegistry() as ucr:
        yield ucr
def test_check_enabled_email_unverified():
    with ucr_test.UCSTestConfigRegistry():
        handler_set(['saml/idp/selfservice/check_email_verification=True'])
        with pytest.raises(samltest.SamlAccountNotVerified):
            check_login(activated_email=False)
Beispiel #28
0
 def __init__(self, selenium):
     # type: (Any) -> None
     super(Portals, self).__init__(selenium)
     self.ucr = ucr_test.UCSTestConfigRegistry()
     self.ucr.load()
def test_check_enabled_email_verified():
    with ucr_test.UCSTestConfigRegistry():
        handler_set(['saml/idp/selfservice/check_email_verification=True'])
        check_login(activated_email=True)