#!/bin/sh
. $(dirname $0)/../test_library

set_config() {
  echo "
  debug = debug
  syslog = no
  pid = ${result_path}/stunnel.pid
  output = ${result_path}/stunnel.log

  [client_1]
  client = yes
  accept = 127.0.0.1:${http2}
  connect = 127.0.0.1:${https1}

  [server_1]
  accept = 127.0.0.1:${https1}
  connect = 127.0.0.1:${http_nc}
  cert = ../certs/server_cert.pem" > "stunnel.conf"
}

change_config() {
#  accept = 127.0.0.1:${http2} -> accept = 127.0.0.1:${http1}
  echo "
  debug = debug
  syslog = no
  pid = ${result_path}/stunnel.pid
  output = ${result_path}/stunnel.log

  [client_2]
  client = yes
  accept = 127.0.0.1:${http1}
  connect = 127.0.0.1:${https1}

  [server_2]
  accept = 127.0.0.1:${https1}
  connect = 127.0.0.1:${http_nc}
  cert = ../certs/server_cert.pem" > "stunnel.conf"
}

start() {
  set_config
  ../../src/stunnel stunnel.conf
}

myglobal "$1" "$2" "$3"
check_ports "040_reload"
start_stunnel "040_reload" 2> "error.log"
reload_stunnel "040_reload" 2>> "error.log"
test_log_for "040_reload" "success" "0" "$1" "$2" "$3" 2>> "stderr.log"
exit $?
