#!/bin/sh

# Checking if stunnel works with the configuration placed in a few files.
# All configuration file parts are located in the directory specified with include.

. $(dirname $0)/../test_library

set_config() {
  mkdir -p "${result_path}/conf.d"
  echo "
  debug = debug
  syslog = no
  pid = ${result_path}/stunnel.pid
  output = ${result_path}/stunnel.log" > "${result_path}/conf.d/00-global.conf"
  echo "
  [client]
  client = yes
  accept = 127.0.0.1:${http1}
  connect = 127.0.0.1:${https1}" > "${result_path}/conf.d/01-service.conf"
  echo "
  [server]
  accept = 127.0.0.1:${https1}
  connect = 127.0.0.1:${http_nc}
  cert = ${script_path}/certs/server_cert.pem" > "${result_path}/conf.d/02-service.conf"
}

start() {
  set_config
  ../../src/stunnel -fd 0 <<EOT
  include = ${result_path}/conf.d
EOT
}

test_log_for "045_include" "success" "0" "$1" "$2" "$3" 2>> "stderr.log"
result=$?
if [ $result -eq 0 ]
  then
    rm -f -r "${result_path}/conf.d"
  fi
exit $result
