]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: Add check_string_in_log and generate self-signed certificate
authorfrancisco.garcia <francisco.garcia@baculasystems.com>
Mon, 31 Jul 2023 11:11:21 +0000 (13:11 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:01 +0000 (13:57 +0200)
regress/scripts/regress-utils.sh

index bbd1da8dcc570ed1bf6074d8c8c82d4f56ab6f90..674e39a7d26eb0d8569d8bb731f9cc7fd3147556 100755 (executable)
@@ -36,6 +36,34 @@ fi
 export LPLUG
 }
 
+#
+# Create self-signed certificate.
+#
+# in:
+# $1 (optional): Directory to save the csr, key and pem.
+# $2 (optional): Name of csr, key and pem
+#
+setup_self_signed_cert()
+{
+   cert_dir="/tmp/"
+   cert_name="snakeoil"
+   if [ "x$1" != "x" ]
+   then
+      if [ "${1:(-1)}" != "/" ]
+      then
+         cert_dir=${1}/
+      fi
+   fi
+   if [ "x${2}" != "x" ]
+   then
+      cert_name=${2}
+   fi
+   echo "[INIT] CREATE OPENSSL CERTS"
+   `openssl req -nodes -newkey rsa:2048 -keyout ${cert_dir}${cert_name}.key -out ${cert_dir}${cert_name}.csr -subj "/C=CH/ST=Vaud/L=Yverdon-les-Bains/O=Backup Security/OU=R&D Department/CN=baculasystems.com"`
+   `openssl x509 -req -sha256 -days 365 -in ${cert_dir}${cert_name}.csr -signkey ${cert_dir}${cert_name}.key -out ${cert_dir}${cert_name}.pem`
+   echo "[END] CREATE OPENSSL CERTS"
+}
+
 #
 # common check if test pass by checking input param
 #
@@ -284,6 +312,31 @@ else
 fi
 }
 
+#
+# Check the expected string on any log file
+#
+# in:
+# $1 - type of log. Values allowed: b,r,e,l
+# $2 - the string to seach into logfile
+# $3 - a test number to examine which means we will check log${ltest}.out logfile
+check_regress_string_in_log()
+{
+   type_log=$1
+   to_search=$2
+   n_test=$3
+   log_file=${tmp}/${type_log}log${n_test}.out
+   grep "${to_search}" ${log_file}
+   F=$?
+   if [ $F -ne 0 ]
+   then
+      error_stat="${type_log}stat"
+      declare -g "${error_stat}"=$((${!error_stat}+1))
+      return 1
+   else
+      return 0
+   fi
+}
+
 #
 # This is a simple common function which start a fresh, new local slapd
 # available on ldap://localhost:3890