#!/usr/share/ucs-test/runner python3
## desc: Create dns/host with all attributes set
## tags: [udm]
## roles: [domaincontroller_master]
## exposure: careful
## packages:
##   - univention-config
##   - univention-directory-manager-tools

import univention.testing.utils as utils
import univention.testing.udm as udm_test
import univention.testing.strings as uts

if __name__ == '__main__':
	with udm_test.UCSTestUDM() as udm:
		forward_zone = udm.create_object('dns/forward_zone', zone='%s.%s' % (uts.random_name(), uts.random_name()), nameserver=uts.random_dns_record())

		# IPv4 case:
		host_record_properties = {
			'name': uts.random_name(),
			'zonettl': '128',
			'a': '10.20.30.40',
			'mx': '50 %s' % uts.random_string(),
			'txt': uts.random_string()
		}
		host_record = udm.create_object('dns/host_record', superordinate=forward_zone, **host_record_properties)

		utils.verify_ldap_object(host_record, {
			'dNSTTL': [host_record_properties['zonettl']],
			'aRecord': [host_record_properties['a']],
			'tXTRecord': [host_record_properties['txt']],
			'mXRecord': [host_record_properties['mx']]
		})

		# IPv6 case:
		host_record_properties.update({
			'name': uts.random_name(),
			'a': '2011:06f8:13dc:0002:19b7:d592:09dd:1041',
			'mx': '50 %s' % uts.random_string(),
			'txt': uts.random_string()
		})
		host_record = udm.create_object('dns/host_record', superordinate=forward_zone, **host_record_properties)

		utils.verify_ldap_object(host_record, {
			'dNSTTL': [host_record_properties['zonettl']],
			'aAAARecord': [host_record_properties['a']],
			'tXTRecord': [host_record_properties['txt']],
			'mXRecord': [host_record_properties['mx']]
		})
