#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: "Perform a 'net rpc/ads testjoin' on memberserver"
## exposure: safe
## roles: [memberserver]
## bugs: [35590]
## packages:
##  - winbind
##  - univention-samba

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


security="$(ucr get samba/domain/security)"

if [ "$security" = "ads" ]; then
    # a case when it is a Samba 4 domain, use ADS:
    echo "Initiating a net ads testjoin"

    if [ ! "$(net ads testjoin)" = "Join is OK" ] ; then
       fail_fast 110 "The ADS testjoin did not report that join is OK"
    fi

else
    # else use RPC:
    echo "Initiating a net rpc testjoin"
    win_dom="$(ucr get windows/domain)"

    if [ ! "$(net rpc testjoin)" = "Join to '$win_dom' is OK" ] ; then
       fail_fast 110 "The RPC testjoin did not report that join to $win_dom is OK"
    fi

fi

exit $RETVAL
