#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: Checking ldap group to file hooks
## tags:
##  - basic
## roles-not: [basesystem]
## packages:
##  - univention-ldap-server
## exposure: dangerous

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

f="$(mktemp)"
rm -f "$f"

remove_hook_dir_on_cleanup=false
if [ ! -d /var/lib/ldap-group-to-file-hooks.d ]; then
	mkdir -p /var/lib/ldap-group-to-file-hooks.d
	remove_hook_dir_on_cleanup=true
fi

echo -e '#!/bin/sh\necho "TEST" >'$f'' >>/var/lib/ldap-group-to-file-hooks.d/62ldap_group_to_file_hook

chmod +x /var/lib/ldap-group-to-file-hooks.d/62ldap_group_to_file_hook

/usr/lib/univention-pam/ldap-group-to-file.py

if [ ! -e "$f" ]; then
	fail_test 110 "$f was not created"
fi

rm -f "$f" /var/lib/ldap-group-to-file-hooks.d/62ldap_group_to_file_hook

if "$remove_hook_dir_on_cleanup"
then
	rmdir /var/lib/ldap-group-to-file-hooks.d
fi

exit "$RETVAL"
