#!/bin/bash
#   BAREOS® - Backup Archiving REcovery Open Sourced
#
#   Copyright (C) 2026-2026 Bareos GmbH & Co. KG
#
#   This program is Free Software; you can redistribute it and/or
#   modify it under the terms of version three of the GNU Affero General Public
#   License as published by the Free Software Foundation and included
#   in the file LICENSE.
#
#   This program is distributed 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
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
#   02110-1301, USA.

#CTEST nolock
set -e
set -o pipefail
set -u
#
# test some ACL restrictions
#
TestName="$(basename "$(pwd)")"
export TestName

#shellcheck source=../../environment.in
. ./environment

#shellcheck source=../../scripts/functions
. "${BAREOS_SCRIPTS_DIR}"/functions

start_test

echo "status conf" | "${BAREOS_BCONSOLE_BINARY}" -c etc/bareos/bconsole-acl-none.conf >${logdir}/acl-none.log
echo "status conf" | "${BAREOS_BCONSOLE_BINARY}" -c etc/bareos/bconsole-acl-status.conf >${logdir}/acl-status.log
echo "status conf" | "${BAREOS_BCONSOLE_BINARY}" -c etc/bareos/bconsole-acl-status-conf.conf >${logdir}/acl-status-conf.log

export estat=0

set_error()
{
  estat=1
  echo "ACL-test failed, see ${logdir}/$1 for details"
}

grep -q "status: is an invalid command" ${logdir}/acl-none.log \
  || set_error "acl-none.log"

grep -q "status conf: is an invalid command" ${logdir}/acl-status.log \
  || set_error "acl-status.log"

# this will match "No deprecated.." and "Deprecated ..."
# which matches for all database types
grep -q "eprecated configuration settings detected" ${logdir}/acl-status-conf.log \
  || set_error "acl-status-conf.log"

end_test
