#!/bin/sh
# -*- coding: utf-8 -*-
#
# Univention UCS@School
#
# Copyright 2013-2014 Univention GmbH
#
# http://www.univention.de/
#
# All rights reserved.
#
# The source code of this program is made available
# under the terms of the GNU Affero General Public License version 3
# (GNU AGPL V3) as published by the Free Software Foundation.
#
# Binary versions of this program provided by Univention to you as
# well as other copyrighted, protected or trademarked materials like
# Logos, graphics, fonts, specific documentations and configurations,
# cryptographic keys etc. are subject to a license agreement between
# you and Univention and not subject to the GNU AGPL V3.
#
# In the case you use this program under the terms of the GNU AGPL V3,
# the program is provided in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License with the Debian GNU/Linux or Univention distribution in file
# /usr/share/common-licenses/AGPL-3; if not, see
# <http://www.gnu.org/licenses/>.

if [ -z "$1" -o "$1" = "-h" -o "$1" = "--help" ] ; then
	echo "$0 --run"
	echo "small test script for move_domaincontroller_to_ou"
	echo "WARNING: it creates a lot of OU and does not clean up!"
	exit 1
fi

eval "$(ucr shell)"

./create_ou test1 dctest1

./create_ou test2

./create_ou test4 dctest4
udm computers/domaincontroller_slave create --position "cn=computers,$ldap_base" --set name=dctest4zwo

./create_ou test5 dctest5
./create_ou test6 dctest5

udm computers/domaincontroller_slave create --position "cn=computers,$ldap_base" --set name=dctest7-01
./create_ou test7
udm computers/domaincontroller_slave modify --dn "cn=dctest7-01,cn=computers,$ldap_base" --append groups="cn=OUtest7-DC-Edukativnetz,cn=ucsschool,cn=groups,$ldap_base"

echo "TEST: DC is unknown"
./move_domaincontroller_to_ou --dcname UnKnOwN --ou test1
echo "EXITCODE: $?"

echo "TEST: OU is unknown"
./move_domaincontroller_to_ou --dcname dctest1 --ou KennIchNicht
echo "EXITCODE: $?"

echo "TEST: DC has no read access to OU"
./move_domaincontroller_to_ou --dcname dctest4zwo --ou test4
echo "EXITCODE: $?"

echo "TEST: DC is already in given OU"
./move_domaincontroller_to_ou --dcname dctest2-01 --ou test2
echo "EXITCODE: $?"

echo "TEST: DC is located in another OU"
./move_domaincontroller_to_ou --dcname dctest5 --ou test6
echo "EXITCODE: $?"

echo "TEST: DC is located in another OU --force"
./move_domaincontroller_to_ou --dcname dctest5 --ou test6 --force
echo "EXITCODE: $?"

echo "TEST: successful move"
./move_domaincontroller_to_ou --dcname dctest7-01 --ou test7
echo "EXITCODE: $?"

