#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: "Make concurrent changes in AD"
## exposure: dangerous
## packages:
## - univention-ad-connector
## bugs:
##  - 33621
##  - 33466
##  - 18501
## tags:
##  - skip_admember

# skip test, see https://forge.univention.org/bugzilla/show_bug.cgi?id=18501#c21
exit 131

# 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
ad_is_connector_running || exit 137

for((i=0;i<10;i++)); do

  echo "********************************************"
  echo "* Round $((i+1)) of 10"
  echo "********************************************"

  username="$(random_chars)"
  ad_createuser "$username" || fail_test 110
  AD_DN="CN=$username,CN=users,$(ad_get_base)"

  ad_wait_for_synchronization; fail_bool 0 110

  ad_set_attribute "$AD_DN" "description" "univention"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "homePhone" "1"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "telephoneNumber" "2"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "company" "Test"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "streetAddress" "Street"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "l" "Bremen"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "postalCode" "28359"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "mobile" "3"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "pager" "4"; fail_bool 0 110

  sleep $i
  ad_set_attribute "$AD_DN" "userWorkstations" "pc01"; fail_bool 0 110

  ad_wait_for_synchronization; fail_bool 0 110

  ad_verify_attribute "$AD_DN" "description" "univention"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "homePhone" "1"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "telephoneNumber" "2"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "company" "Test"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "streetAddress" "Street"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "l" "Bremen"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "postalCode" "28359"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "mobile" "3"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "pager" "4"; fail_bool 0 110
  ad_verify_attribute "$AD_DN" "userWorkstations" "pc01"; fail_bool 0 110

  ad_delete "$AD_DN" || fail_test 110

  if [ "$RETVAL" != 100 ]; then
    break
  fi
done

exit $RETVAL
