test.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh -ue
  2. REDIS_SERVER=${REDIS_SERVER:-redis-server}
  3. REDIS_PORT=${REDIS_PORT:-56379}
  4. REDIS_SSL_PORT=${REDIS_SSL_PORT:-56443}
  5. TEST_SSL=${TEST_SSL:-0}
  6. SSL_TEST_ARGS=
  7. tmpdir=$(mktemp -d)
  8. PID_FILE=${tmpdir}/hiredis-test-redis.pid
  9. SOCK_FILE=${tmpdir}/hiredis-test-redis.sock
  10. if [ "$TEST_SSL" = "1" ]; then
  11. SSL_CA_CERT=${tmpdir}/ca.crt
  12. SSL_CA_KEY=${tmpdir}/ca.key
  13. SSL_CERT=${tmpdir}/redis.crt
  14. SSL_KEY=${tmpdir}/redis.key
  15. openssl genrsa -out ${tmpdir}/ca.key 4096
  16. openssl req \
  17. -x509 -new -nodes -sha256 \
  18. -key ${SSL_CA_KEY} \
  19. -days 3650 \
  20. -subj '/CN=Hiredis Test CA' \
  21. -out ${SSL_CA_CERT}
  22. openssl genrsa -out ${SSL_KEY} 2048
  23. openssl req \
  24. -new -sha256 \
  25. -key ${SSL_KEY} \
  26. -subj '/CN=Hiredis Test Cert' | \
  27. openssl x509 \
  28. -req -sha256 \
  29. -CA ${SSL_CA_CERT} \
  30. -CAkey ${SSL_CA_KEY} \
  31. -CAserial ${tmpdir}/ca.txt \
  32. -CAcreateserial \
  33. -days 365 \
  34. -out ${SSL_CERT}
  35. SSL_TEST_ARGS="--ssl-host 127.0.0.1 --ssl-port ${REDIS_SSL_PORT} --ssl-ca-cert ${SSL_CA_CERT} --ssl-cert ${SSL_CERT} --ssl-key ${SSL_KEY}"
  36. fi
  37. cleanup() {
  38. set +e
  39. kill $(cat ${PID_FILE})
  40. rm -rf ${tmpdir}
  41. }
  42. trap cleanup INT TERM EXIT
  43. cat > ${tmpdir}/redis.conf <<EOF
  44. daemonize yes
  45. pidfile ${PID_FILE}
  46. port ${REDIS_PORT}
  47. bind 127.0.0.1
  48. unixsocket ${SOCK_FILE}
  49. EOF
  50. if [ "$TEST_SSL" = "1" ]; then
  51. cat >> ${tmpdir}/redis.conf <<EOF
  52. tls-port ${REDIS_SSL_PORT}
  53. tls-ca-cert-file ${SSL_CA_CERT}
  54. tls-cert-file ${SSL_CERT}
  55. tls-key-file ${SSL_KEY}
  56. EOF
  57. fi
  58. cat ${tmpdir}/redis.conf
  59. ${REDIS_SERVER} ${tmpdir}/redis.conf
  60. ${TEST_PREFIX:-} ./hiredis-test -h 127.0.0.1 -p ${REDIS_PORT} -s ${SOCK_FILE} ${SSL_TEST_ARGS}