#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: Test fixedAttributes in UMC policy
## exposure: careful
## tags: [udm]
## bugs:
##  - 38663
##  - 38712

# shellcheck source=../../lib/base.sh
. "$TESTLIBPATH/base.sh" || exit 137
. udm.sh || exit 137

setup () {
	udm-test dhcp/service create \
		--position "$BASE" \
		--set service="$name"
	udm-test dhcp/subnet create \
		--superordinate "cn=$name,$BASE" \
		--set subnet="$NET" \
		--set subnetmask='255.255.255.0'
	udm-test policies/dhcp_routing create \
		--position "cn=$name,$BASE" \
		--set name="p1" \
		--set routers="$router" \
		--set fixedAttributes='univentionDhcpRouters'
	udm-test dhcp/service modify \
		--dn "cn=$name,$BASE" \
		--policy-reference "cn=p1,cn=$name,$BASE"
	udm-test policies/dhcp_routing create \
		--position "cn=$name,$BASE" \
		--set name="p2" \
		--set routers="${NET%.0}.254"
	udm-test dhcp/subnet modify \
		--dn "cn=$NET,cn=$name,$BASE" \
		--policy-reference "cn=p2,cn=$name,$BASE"
}

check () {
	wait_for_replication
	policy "cn=$name,$BASE" -s >"$tmp/service.sh"
	grep -Fx "univentionDhcpRouters=\"$router\"" "$tmp/service.sh" ||
		die "Policy not applied to DHCP-Service"
	pypolicy "cn=$name,$BASE" \
		"{'univentionDhcpRouters': {'policy': 'cn=p1,cn=$name,$BASE', 'fixed': 1, 'value': ['$router']}}" ||
		die "Policy not applied to DHCP-Service"

	policy "cn=$NET,cn=$name,$BASE" -s >"$tmp/subnet.sh"
	grep -Fx "univentionDhcpRouters=\"$router\"" "$tmp/subnet.sh" ||
		die "Policy not applied to DHCP-Subnet"
	pypolicy "cn=$NET,cn=$name,$BASE" \
		"{'univentionDhcpRouters': {'policy': 'cn=p1,cn=$name,$BASE', 'fixed': 1, 'value': ['$router']}}" ||
		die "Policy not applied to DHCP-Subnet"
}

setup
check
:
