#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: "Check for Windows client to macOS transformation"
## exposure: dangerous
## packages:
## - univention-s4-connector

# 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

. "s4connector.sh" || exit 137
test -n "$connector_s4_ldap_host" || exit 137
connector_running_on_this_host || exit 137

SYNCMODE="$(ad_get_sync_mode)"
ad_set_sync_mode "sync"

UDM_computers_windows_name="$(random_chars)"
UDM_computers_windows_description="$(random_chars)"
udm_create "computers/windows" || fail_test 110

ad_wait_for_synchronization; fail_bool 0 110

AD_DN="CN=$UDM_computers_windows_name,CN=computers,$(ad_get_base)"
ad_exists "$AD_DN"; fail_bool 0 110

udm-test 'computers/windows' modify --dn "cn=$UDM_computers_windows_name,cn=computers,$(ucr get ldap/base)" --set operatingSystem="Mac OS X" || fail_test 110  # FIXME: macOS ?

ad_wait_for_synchronization; fail_bool 0 110

udm_exists "computers/windows"; fail_bool 1 110
UDM_computers_macos_name="$UDM_computers_windows_name"
udm_exists "computers/macos"; fail_bool 0 110

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

ad_exists "$AD_DN"; fail_bool 1 110
udm_exists "users/user"; fail_bool 1 110

ad_set_sync_mode "$SYNCMODE"

exit "$RETVAL"
