#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: Check listener case handling
## roles:
##  - domaincontroller_master
##  - domaincontroller_backup
## packages:
##  - univention-directory-listener
## exposure: dangerous
## bugs:
##  - 35334


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

udm-test container/cn create \
	--set name='ŵnvü#ûüΩ?ĵ' || fail_fast 140 "cannot create container/cn with name='ŵnvü#ûüΩ?ĵ'"

udm-test container/cn create \
	--set name='new_ŵnvü#ûüΩ?ĵ' || fail_fast 140 "cannot create container/cn with name='new_ŵnvü#ûüΩ?ĵ'"

undo udm-test container/cn remove --dn "cn=new_ŵnvü#ûüΩ?ĵ,$ldap_base"

udm-test container/cn move --dn "cn=ŵnvü#ûüΩ?ĵ,$ldap_base" \
	--position "cn=new_ŵnvü#ûüΩ?ĵ,$ldap_base"

sleep 10  ## wait_for_replication would wait for 300 seconds if listener crashes

if [ "$(pgrep -cf /usr/sbin/univention-directory-listener)" = 0 ]; then
	systemctl start univention-directory-listener
	udm-test container/cn remove --dn "cn=ŵnvü#ûüΩ?ĵ,$ldap_base"
	fail_fast 1 "The univention-directory-listener crashed. See Bug #35334"
else
	udm-test container/cn remove --dn "cn=ŵnvü#ûüΩ?ĵ,cn=new_ŵnvü#ûüΩ?ĵ,$ldap_base"
fi
