#!/usr/share/ucs-test/runner python
## desc: Remove A and AAAA during dns/host record modification
## 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_string())

		# IPv4 case:
		ips = ['10.20.30.40', '10.20.30.41', '10.20.30.42', '10.20.30.43']
		host_record = udm.create_object('dns/host_record', superordinate = forward_zone, name = uts.random_name(), append = {'a': ips})

		udm.modify_object('dns/host_record', dn = host_record, superordinate = forward_zone, remove = {'a': ips[:2]})
		utils.verify_ldap_object(host_record, {'aRecord': ips[2:]})

		# IPv6 case:
		ips = ['2011:06f8:13dc:0002:19b7:d592:09dd:1041', '2011:06f8:13dc:0002:19b7:d592:09dd:1042', '2011:06f8:13dc:0002:19b7:d592:09dd:1043', '2011:06f8:13dc:0002:19b7:d592:09dd:1044']
		host_record = udm.create_object('dns/host_record', superordinate = forward_zone, name = uts.random_name(), append = {'a': ips})

		udm.modify_object('dns/host_record', dn = host_record, superordinate = forward_zone, remove = {'a': ips[:2]})
		utils.verify_ldap_object(host_record, {'aAAARecord': ips[2:]})
