#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: "Create an UCS-Ou and remove the corresponding AD-Ou in sync mode"
## exposure: dangerous
## packages:
## - univention-ad-connector
## tags:
##  - skip_admember

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

. "adconnector.sh" || exit 137
test -n "$connector_ad_ldap_host" || exit 137


UDM_container_ou_name="$(random_chars)"
AD_OU_DN="OU=$UDM_container_ou_name,$(ad_get_base)"

SYNCMODE="$(ad_get_sync_mode)"

ad_set_sync_mode "sync"

udm_create "container/ou" || fail_test 110
ad_wait_for_synchronization; fail_bool 0 110

udm_exists "container/ou"; fail_bool 0 110
ad_exists "$AD_OU_DN"; fail_bool 0 110

ad_delete "$AD_OU_DN" || fail_test 110
ad_wait_for_synchronization; fail_bool 0 110

ad_exists "$AD_OU_DN"; fail_bool 1 110
udm_exists "container/ou"; fail_bool 1 110

ad_set_sync_mode "$SYNCMODE"

exit "$RETVAL"
