def test__dns_forward_zone_check_resolve(self, udm):
        """Creates DNS forward zone entry and try to resolve it"""
        zone = '%s.%s.' % (uts.random_name(), uts.random_name())
        pos = 'cn=dns,%s' % (udm.LDAP_BASE, )

        forward_zone_properties = {
            'zone':
            zone,
            'nameserver':
            udm.FQHN,
            'contact':
            '%s@%s.%s' %
            (uts.random_name(), uts.random_name(), uts.random_name()),
            'serial':
            '%s' % (uts.random_int()),
            'zonettl':
            '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'refresh':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'expire':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'ttl':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'retry':
            '%s' % (uts.random_int()),
            'a': ['%s' % (uts.random_ip())]
        }
        udm.create_object('dns/forward_zone',
                          position=pos,
                          **forward_zone_properties)
        time.sleep(5)
        answers = resolve_dns_entry(zone, 'SOA')
        answer = answers.qname.to_text()
        assert answer == zone, 'resolved name "%s" != created ldap-object "%s"' % (
            answer, zone)
    def test__dns_alias_record_check_resolve(self, udm):
        """Creates DNS alias record and tries to resolve it"""
        zone = '%s.%s.' % (uts.random_name(), uts.random_name())
        pos = 'cn=dns,%s' % (udm.LDAP_BASE, )

        forward_zone_properties = {
            'zone':
            zone,
            'nameserver':
            udm.FQHN,
            'contact':
            '%s@%s.%s' %
            (uts.random_name(), uts.random_name(), uts.random_name()),
            'serial':
            '%s' % (uts.random_int()),
            'zonettl':
            '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'refresh':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'expire':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'ttl':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'retry':
            '%s' % (uts.random_int()),
        }
        forward_zone = udm.create_object('dns/forward_zone',
                                         position=pos,
                                         **forward_zone_properties)

        # IPv4 / IPv6
        host = uts.random_name()
        ipv4 = uts.random_ip()
        ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041'  # create random_ipv6()-method?
        host_record_properties = {
            'name': host,
            'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'a': [ipv4, ipv6],
            'mx': '50 %s' % uts.random_string(),
            'txt': uts.random_string()
        }
        udm.create_object('dns/host_record',
                          superordinate=forward_zone,
                          **host_record_properties)

        alias_name = uts.random_name()
        fqhn = '%s.%s' % (host, zone)
        udm.create_object('dns/alias',
                          superordinate=forward_zone,
                          name=alias_name,
                          cname=fqhn)

        qname = '%s.%s' % (alias_name, zone)
        time.sleep(5)
        answers = resolve_dns_entry(qname, 'CNAME')
        answer = [rdata.target.to_text() for rdata in answers]
        assert answer == [
            fqhn
        ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [fqhn])
    def test__dns_reverse_zone_check_resolve(self, udm):
        """Creates DNS reverse zone entry and try to resolve it"""
        pos = 'cn=dns,%s' % (udm.LDAP_BASE, )

        # IPv4
        ipv4 = uts.random_ip().split('.')
        subnet = ipv4[:3]
        reverse_zone_properties = {
            'subnet':
            '.'.join(subnet),
            'nameserver':
            udm.FQHN,
            'contact':
            '%s@%s.%s' %
            (uts.random_name(), uts.random_name(), uts.random_name()),
            'serial':
            '%s' % (uts.random_int()),
            'zonettl':
            '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'refresh':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'expire':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'ttl':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'retry':
            '%s' % (uts.random_int()),
        }
        udm.create_object('dns/reverse_zone',
                          position=pos,
                          **reverse_zone_properties)
        zoneName = '.'.join(list(reversed(subnet)) + ['in-addr', 'arpa', ''])
        time.sleep(5)
        answers = resolve_dns_entry(zoneName, 'SOA')
        answer = answers.qname.to_text()
        assert answer == zoneName, 'IPv4: resolved name "%s" != created ldap-object "%s"' % (
            answer, zoneName)

        # IPv6
        ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041'.split(
            ':')  # create uts.random_ipV6()?
        subnet = ipv6[:7]
        reverse_zone_properties.update({
            'subnet': ':'.join(subnet),
        })
        udm.create_object('dns/reverse_zone',
                          position=pos,
                          **reverse_zone_properties)
        zoneName = '.'.join(
            list(reversed([nibble for block in subnet
                           for nibble in block])) + ['ip6', 'arpa', ''])
        time.sleep(5)
        answers = resolve_dns_entry(zoneName, 'SOA')
        answer = answers.qname.to_text()
        assert answer == zoneName, 'IPv6: resolved name "%s" != created ldap-object "%s"' % (
            answer, zoneName)
예제 #4
0
def test_create_printer(ucr, udm):
    """Create shares/printer and verify LDAP object"""
    ucr.load()

    properties = {
        'name': uts.random_name(),
        'location': uts.random_string(),
        'description': uts.random_name(),
        'spoolHost': random_fqdn(ucr),
        'uri': '%s %s' % (
            random.choice(PRINTER_PROTOCOLS),
            uts.random_ip(),
        ),
        'model':
        'foomatic-rip/Generic-PCL_4_Printer-gutenprint-ijs-simplified.5.2.ppd',
        'producer':
        'cn=Generic,cn=cups,cn=univention,%s' % (ucr.get('ldap/base'), ),
        'sambaName': uts.random_name(),
        'ACLtype': random.choice(['allow all', 'allow', 'deny']),
        'ACLUsers': 'uid=Administrator,cn=users,%s' % (ucr.get('ldap/base'), ),
        'ACLGroups':
        'cn=Printer Admins,cn=groups,%s' % (ucr.get('ldap/base'), ),
    }

    print('*** Create shares/printer object')
    print_share_dn = udm.create_object('shares/printer',
                                       position='cn=printers,%s' %
                                       (ucr['ldap/base'], ),
                                       **properties)

    utils.verify_ldap_object(print_share_dn, {
        'cn': [properties['name']],
        'description': [properties['description']],
        'univentionObjectType': ['shares/printer'],
        'univentionPrinterACLGroups': [properties['ACLGroups']],
        'univentionPrinterACLUsers': [properties['ACLUsers']],
        'univentionPrinterACLtype': [properties['ACLtype']],
        'univentionPrinterLocation': [properties['location']],
        'univentionPrinterModel': [properties['model']],
        'univentionPrinterSambaName': [properties['sambaName']],
        'univentionPrinterSpoolHost': [properties['spoolHost']],
        'univentionPrinterURI': [properties['uri'].replace(' ', '')],
    },
                             delay=1)

    print('*** Modify shares/printer object')
    properties['sambaName'] = uts.random_name()
    udm.modify_object('shares/printer',
                      dn=print_share_dn,
                      sambaName=properties['sambaName'])
    utils.verify_ldap_object(
        print_share_dn,
        {'univentionPrinterSambaName': [properties['sambaName']]},
        delay=1)
    def test__dns_pointer_record_check_resolve(self, udm):
        """Creates DNS pointer record entry and try to resolve it"""
        pos = 'cn=dns,%s' % (udm.LDAP_BASE, )

        ptr_record = '%s.%s.' % (uts.random_name(), uts.random_name())

        # IPv4
        ipv4 = uts.random_ip().split('.')
        subnet = ipv4[:3]
        reverse_zone_properties = {
            'subnet':
            '.'.join(subnet),
            'nameserver':
            udm.FQHN,
            'contact':
            '%s@%s.%s' %
            (uts.random_name(), uts.random_name(), uts.random_name()),
            'serial':
            '%s' % (uts.random_int()),
            'zonettl':
            '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'refresh':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'expire':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'ttl':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'retry':
            '%s' % (uts.random_int()),
        }
        reverse_zone = udm.create_object('dns/reverse_zone',
                                         position=pos,
                                         **reverse_zone_properties)

        udm.create_object('dns/ptr_record',
                          address=ipv4[3],
                          superordinate=reverse_zone,
                          ptr_record=ptr_record)

        zoneName = '.'.join(list(reversed(ipv4)) + ['in-addr', 'arpa', ''])
        time.sleep(5)
        answers = resolve_dns_entry(zoneName, 'PTR')
        answer = [rdata.to_text() for rdata in answers]
        assert answer == [
            ptr_record
        ], 'resolved name "%s" != created ldap-object "%s"' % (answer,
                                                               [ptr_record])

        # IPv6
        ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041'.split(
            ':')  # create uts.random_ipV6()?
        subnet = ipv6[:7]
        reverse_zone_properties.update({
            'subnet': ':'.join(subnet),
        })
        reverse_zone = udm.create_object('dns/reverse_zone',
                                         position=pos,
                                         **reverse_zone_properties)

        addr = '.'.join(reversed(ipv6[7]))
        udm.create_object('dns/ptr_record',
                          address=addr,
                          superordinate=reverse_zone,
                          ptr_record=ptr_record)

        zoneName = '.'.join(
            list(reversed([nibble for block in ipv6
                           for nibble in block])) + ['ip6', 'arpa', ''])
        time.sleep(5)
        answers = resolve_dns_entry(zoneName, 'PTR')
        answer = [rdata.to_text() for rdata in answers]
        assert answer == [
            ptr_record
        ], 'resolved name "%s" != created ldap-object "%s"' % (answer,
                                                               [ptr_record])
    def test__dns_srv_record_check_resolve(self, udm):
        """Creates DNS srv record and try to resolve it"""
        zone = '%s.%s.' % (uts.random_name(), uts.random_name())
        pos = 'cn=dns,%s' % (udm.LDAP_BASE, )

        forward_zone_properties = {
            'zone':
            zone,
            'nameserver':
            udm.FQHN,
            'contact':
            '%s@%s.%s' %
            (uts.random_name(), uts.random_name(), uts.random_name()),
            'serial':
            '%s' % (uts.random_int()),
            'zonettl':
            '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'refresh':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'expire':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'ttl':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'retry':
            '%s' % (uts.random_int()),
        }
        forward_zone = udm.create_object('dns/forward_zone',
                                         position=pos,
                                         **forward_zone_properties)

        # IPv4 / IPv6
        host = uts.random_name()
        ipv4 = uts.random_ip()
        ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041'  # create random_ipv6()-method?
        host_record_properties = {
            'name': host,
            'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'a': [ipv4, ipv6],
            'mx': '50 %s' % uts.random_string(),
            'txt': uts.random_string()
        }
        udm.create_object('dns/host_record',
                          superordinate=forward_zone,
                          **host_record_properties)

        service = uts.random_string()
        protocol = 'tcp'
        extension = uts.random_string()
        priority = 1
        weight = 100
        port = uts.random_int(top_end=65535)
        fqhn = '%s.%s' % (host, zone)
        srv_record_properties = {
            'name': '%s %s %s' % (service, protocol, extension),
            'location': '%d %d %s %s' % (priority, weight, port, fqhn),
            'zonettl': '128'
        }
        udm.create_object('dns/srv_record',
                          superordinate=forward_zone,
                          **srv_record_properties)

        zoneName = '_%s._%s.%s.%s' % (service, protocol, extension, zone)
        answers = resolve_dns_entry(zoneName, 'SRV')
        answer = [rdata.target.to_text() for rdata in answers]
        assert answer == [
            fqhn
        ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [fqhn])
    def test__dns_host_record_check_resolve(self, udm):
        """Creates DNS host record entry and try to resolve it"""
        zone = '%s.%s.' % (uts.random_name(), uts.random_name())
        pos = 'cn=dns,%s' % (udm.LDAP_BASE, )

        forward_zone_properties = {
            'zone':
            zone,
            'nameserver':
            udm.FQHN,
            'contact':
            '%s@%s.%s' %
            (uts.random_name(), uts.random_name(), uts.random_name()),
            'serial':
            '%s' % (uts.random_int()),
            'zonettl':
            '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'refresh':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'expire':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'ttl':
            '%s' % (uts.random_int(bottom_end=10, top_end=99)),
            'retry':
            '%s' % (uts.random_int()),
        }
        forward_zone = udm.create_object('dns/forward_zone',
                                         position=pos,
                                         **forward_zone_properties)

        # IPv4
        ip = uts.random_ip()
        host = uts.random_name()
        host_record_properties = {
            'name': host,
            'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)),
            'a': ip,
            'mx': '50 %s' % uts.random_string(),
            'txt': uts.random_string()
        }
        udm.create_object('dns/host_record',
                          superordinate=forward_zone,
                          **host_record_properties)

        qname = '%s.%s' % (host, zone)
        answers = resolve_dns_entry(qname, 'A')
        answer = [ip_address(u'%s' % (rdata.address, )) for rdata in answers]
        assert answer == [
            ip_address(u'%s' % (ip, ))
        ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [ip])

        # IPv6
        ip = '2011:06f8:13dc:0002:19b7:d592:09dd:1041'  # create random_ipv6()-method?
        host = uts.random_name()
        host_record_properties.update({
            'name': host,
            'a': ip,
        })
        udm.create_object('dns/host_record',
                          superordinate=forward_zone,
                          **host_record_properties)

        qname = '%s.%s' % (host, zone)
        time.sleep(5)
        answers = resolve_dns_entry(qname, 'AAAA')
        answer = [ip_address(u'%s' % (rdata.address, )) for rdata in answers]
        assert answer == [
            ip_address(u'%s' % (ip, ))
        ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [ip])
예제 #8
0
def test_create_printergroup(ucr, udm):
    """Create shares/printergroup and verify LDAP object"""
    ucr.load()

    spoolHost = random_fqdn(ucr)

    printer_properties1 = {
        'name':
        uts.random_name(),
        'spoolHost':
        spoolHost,
        'uri':
        '%s %s' % (
            random.choice(PRINTER_PROTOCOLS),
            uts.random_ip(),
        ),
        'model':
        'foomatic-rip/Generic-PCL_4_Printer-gutenprint-ijs-simplified.5.2.ppd',
        'producer':
        'cn=Generic,cn=cups,cn=univention,%s' % (ucr.get('ldap/base'), ),
    }

    print('*** Create shares/printer object')
    udm.create_object('shares/printer',
                      position='cn=printers,%s' % (ucr['ldap/base'], ),
                      **printer_properties1)

    printer_properties2 = {
        'name':
        uts.random_name(),
        'spoolHost':
        spoolHost,
        'uri':
        '%s %s' % (
            random.choice(PRINTER_PROTOCOLS),
            uts.random_ip(),
        ),
        'model':
        'foomatic-rip/Generic-PCL_4_Printer-gutenprint-ijs-simplified.5.2.ppd',
        'producer':
        'cn=Generic,cn=cups,cn=univention,%s' % (ucr.get('ldap/base'), ),
    }

    print('*** Create shares/printer object')
    udm.create_object('shares/printer',
                      position='cn=printers,%s' % (ucr['ldap/base'], ),
                      **printer_properties2)

    printergroup_properties = {
        'name': uts.random_name(),
        'spoolHost': spoolHost,
        'groupMember':
        [printer_properties1['name'], printer_properties2['name']],
        'sambaName': uts.random_name(),
    }

    print('*** Create shares/printergroup object')
    printergroup_share_dn = udm.create_object('shares/printergroup',
                                              position='cn=printers,%s' %
                                              (ucr['ldap/base'], ),
                                              **printergroup_properties)

    utils.verify_ldap_object(printergroup_share_dn, {
        'cn': [printergroup_properties['name']],
        'univentionObjectType': ['shares/printergroup'],
        'univentionPrinterSambaName': [printergroup_properties['sambaName']],
        'univentionPrinterSpoolHost': [printergroup_properties['spoolHost']],
        'univentionPrinterGroupMember':
        printergroup_properties['groupMember'],
    },
                             delay=1)

    print('*** Modify shares/printergroup object')
    printergroup_properties['sambaName'] = uts.random_name()
    udm.modify_object('shares/printergroup',
                      dn=printergroup_share_dn,
                      sambaName=printergroup_properties['sambaName'])
    utils.verify_ldap_object(
        printergroup_share_dn,
        {'univentionPrinterSambaName': [printergroup_properties['sambaName']]},
        delay=1)
예제 #9
0
def test_create_printer_and_check_printing_works(ucr, udm):
    """Create shares/printer and check if print access works"""
    ucr.load()
    admin_dn = ucr.get(
        'tests/domainadmin/account',
        'uid=Administrator,cn=users,%s' % (ucr.get('ldap/base'), ))
    admin_name = ldap.dn.str2dn(admin_dn)[0][0][1]
    password = ucr.get('tests/domainadmin/pwd', 'univention')

    spoolhost = '.'.join([ucr['hostname'], ucr['domainname']])
    acltype = random.choice(['allow all', 'allow'])

    properties = {
        'name': uts.random_name(),
        'location': uts.random_string(),
        'description': uts.random_name(),
        'spoolHost': spoolhost,
        'uri': '%s %s' % (
            random.choice(PRINTER_PROTOCOLS),
            uts.random_ip(),
        ),
        'model': 'hp-ppd/HP/HP_Business_Inkjet_2500C_Series.ppd',
        'producer':
        'cn=Generic,cn=cups,cn=univention,%s' % (ucr.get('ldap/base'), ),
        'sambaName': uts.random_name(),
        'ACLtype': acltype,
        'ACLUsers': admin_dn,
        'ACLGroups':
        'cn=Printer Admins,cn=groups,%s' % (ucr.get('ldap/base'), ),
    }

    print('*** Create shares/printer object')
    print_share_dn = udm.create_object('shares/printer',
                                       position='cn=printers,%s' %
                                       (ucr['ldap/base'], ),
                                       **properties)

    utils.verify_ldap_object(print_share_dn, {
        'cn': [properties['name']],
        'description': [properties['description']],
        'univentionObjectType': ['shares/printer'],
        'univentionPrinterACLGroups': [properties['ACLGroups']],
        'univentionPrinterACLUsers': [properties['ACLUsers']],
        'univentionPrinterACLtype': [properties['ACLtype']],
        'univentionPrinterLocation': [properties['location']],
        'univentionPrinterModel': [properties['model']],
        'univentionPrinterSambaName': [properties['sambaName']],
        'univentionPrinterSpoolHost': [properties['spoolHost']],
        'univentionPrinterURI': [properties['uri'].replace(' ', '')],
    },
                             delay=1)

    print('*** Modify shares/printer samba share name')
    properties['sambaName'] = uts.random_name()
    udm.modify_object('shares/printer',
                      dn=print_share_dn,
                      sambaName=properties['sambaName'])
    utils.verify_ldap_object(
        print_share_dn,
        {'univentionPrinterSambaName': [properties['sambaName']]},
        delay=1)

    delay = 15
    print('*** Wait %s seconds for listener postrun' % delay)
    time.sleep(delay)
    p = subprocess.Popen(['lpq', '-P', properties['name']], close_fds=True)
    p.wait()
    assert not p.returncode, "CUPS printer {} not created after {} seconds".format(
        properties['name'], delay)

    p = subprocess.Popen(
        ['su', admin_name, '-c',
         'lpr -P %s /etc/hosts' % properties['name']],
        close_fds=True)
    p.wait()
    assert not p.returncode, "Printing to CUPS printer {} as {} failed".format(
        properties['name'], admin_name)

    s4_dc_installed = utils.package_installed("univention-samba4")
    s3_file_and_print_server_installed = utils.package_installed(
        "univention-samba")
    smb_server = s3_file_and_print_server_installed or s4_dc_installed
    if smb_server:
        delay = 1
        time.sleep(delay)
        cmd = [
            'smbclient',
            '//localhost/%s' % properties['sambaName'], '-U',
            '%'.join([admin_name, password]), '-c', 'print /etc/hosts'
        ]
        print('\nRunning: %s' % ' '.join(cmd))
        p = subprocess.Popen(cmd, close_fds=True)
        p.wait()
        if p.returncode:
            share_definition = '/etc/samba/printers.conf.d/%s' % properties[
                'sambaName']
            with open(share_definition) as f:
                print('### Samba share file %s :' % share_definition)
                print(f.read())
            print('### testpam for that smb.conf section:')
            p = subprocess.Popen(
                ['testparm', '-s', '--section-name', properties['sambaName']],
                close_fds=True)
            p.wait()
            assert False, 'Samba printer share {} not accessible'.format(
                properties['sambaName'])

    p = subprocess.Popen(['lprm', '-P', properties['name'], '-'],
                         close_fds=True)
    p.wait()