#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: "Display samba Groups as normal user"
## exposure: safe
## packages:
##  - univention-samba | univention-samba4
## roles-not:
## - basesystem
## - memberserver
## tags: [basic, skip_admember]

# shellcheck source=../../lib/user.sh
. "$TESTLIBPATH/user.sh" || exit 137
# shellcheck source=../../lib/samba.sh
. "$TESTLIBPATH/samba.sh" || exit 137

SAMBA="true"
MAIL="false"
KERBEROS="true"
PERSON="false"
POSIX="true"

username="$(user_randomname)"
password="univention"

trap 'user_remove "$username"' INT TERM EXIT
if ! user_create "$username"; then
	fail_fast 1 "Failed to create user"
fi

if checkpkg "univention-samba4"; then
	# wait for user replication
	wait_for_LDAP_replication_of_domain_sambaSid "$username"

	# force_drs_replication  ## $ldap_master $samba4_ldap_base
	wait_for_drs_replication "(sAMAccountName=$username)" objectSid
else
	wait_for_replication
fi


echo "----print samba groups as a user"
if checkpkg "univention-samba4"; then
	output="$(samba-tool group list -U "$username%$password" | grep -q "Domain Users")"
else
	output="$(net rpc group -U "$username%$password" | grep "Domain Users")"
fi
if [ "$?" != 0 ]; then
	echo "$output"
	fail_test 1 "The test trying to display samba-Groups as a user failed"
fi
exit $RETVAL
