#!/usr/share/ucs-test/runner python
## desc: Univention-s4-connector dns pointer record syncronisation
## exposure: dangerous
## packages:
##   - univention-config
##   - univention-directory-manager-tools
##   - univention-s4-connector
##   - dnsutils

import univention.testing.udm as udm_test
import univention.testing.utils as utils
import univention.testing.strings as uts
import random
import dnstests
import s4connector


if __name__ == '__main__':
	with udm_test.UCSTestUDM() as udm:

		s4connector.exit_if_connector_not_running()
		revzone = dnstests.random_reverse_zone()
		host = dnstests.get_hostname()
		ptr_record = uts.random_name()
		random_address = random.randrange(1, 254)
		zone_ip_parts = revzone.split('.')
		reverse_ip = '{2}.{1}.{0}.in-addr.arpa'.format(zone_ip_parts[0], zone_ip_parts[1], zone_ip_parts[2])
		reverse_zone = udm.create_object('dns/reverse_zone', subnet = revzone, nameserver = host)
		dnstests.check_ldap_object(reverse_zone, 'Reverse Zone', '', '')
		ptr = udm.create_object('dns/ptr_record', address = random_address, superordinate = reverse_zone, ptr_record = ptr_record)
		dnstests.check_ldap_object(ptr, 'Pointer Record', 'pTRRecord', ptr_record)
		s4connector.wait_for_sync(30)
		dnstests.test_dns_pointer_record(reverse_ip, random_address, ptr_record)
		dnstests.check_ldap_object(reverse_zone, 'Reverse Zone', '', '')
		dnstests.check_ldap_object(ptr, 'Pointer Record', 'pTRRecord', ptr_record + '.')
	s4connector.wait_for_sync()
