2
0

resume.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash
  2. #resume.test
  3. # if we can, isolate the network namespace to eliminate port collisions.
  4. if [[ -n "$NETWORK_UNSHARE_HELPER" ]]; then
  5. if [[ -z "$NETWORK_UNSHARE_HELPER_CALLED" ]]; then
  6. export NETWORK_UNSHARE_HELPER_CALLED=yes
  7. exec "$NETWORK_UNSHARE_HELPER" "$0" "$@" || exit $?
  8. fi
  9. elif [ "${AM_BWRAPPED-}" != "yes" ]; then
  10. bwrap_path="$(command -v bwrap)"
  11. if [ -n "$bwrap_path" ]; then
  12. export AM_BWRAPPED=yes
  13. exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
  14. fi
  15. unset AM_BWRAPPED
  16. fi
  17. # need a unique resume port since may run the same time as testsuite
  18. # use server port zero hack to get one
  19. resume_string="reused"
  20. resume_sup_string="Resume session"
  21. ems_string="Extended\ Master\ Secret"
  22. resume_port=0
  23. no_pid=-1
  24. server_pid=$no_pid
  25. counter=0
  26. # let's use absolute path to a local dir (make distcheck may be in sub dir)
  27. # also let's add some randomness by adding pid in case multiple 'make check's
  28. # per source tree
  29. ready_file=`pwd`/wolfssl_resume_ready$$
  30. echo "ready file $ready_file"
  31. remove_ready_file() {
  32. if test -e "$ready_file"; then
  33. echo -e "removing existing ready file"
  34. rm "$ready_file"
  35. fi
  36. }
  37. do_cleanup() {
  38. echo "in cleanup"
  39. if [ $server_pid != $no_pid ]
  40. then
  41. echo "killing server"
  42. kill -9 $server_pid
  43. fi
  44. remove_ready_file
  45. }
  46. do_trap() {
  47. echo "got trap"
  48. do_cleanup
  49. exit 1
  50. }
  51. do_test() {
  52. echo -e "\nStarting example server for resume test...\n"
  53. #make sure we support session resumption (!NO_SESSION_CACHE)
  54. # Check the client for the extended master secret disable option. If
  55. # present we need to run the test twice.
  56. options_check=`./examples/client/client '-?'`
  57. case "$options_check" in
  58. *$resume_sup_string*)
  59. echo -e "\nResume test supported";;
  60. *)
  61. echo -e "\nResume test not supported with build"
  62. return;;
  63. esac
  64. remove_ready_file
  65. echo "./examples/server/server -r -R \"$ready_file\" -p $resume_port"
  66. ./examples/server/server -r -R "$ready_file" -p $resume_port &
  67. server_pid=$!
  68. while [ ! -s "$ready_file" -a "$counter" -lt 20 ]; do
  69. echo -e "waiting for ready file..."
  70. sleep 0.1
  71. counter=$((counter+ 1))
  72. done
  73. if test -e "$ready_file"; then
  74. echo -e "found ready file, starting client..."
  75. else
  76. echo -e "NO ready file ending test..."
  77. do_cleanup
  78. exit 1
  79. fi
  80. # sleep for an additional 0.1 to mitigate race on write/read of $ready_file:
  81. sleep 0.1
  82. # get created port 0 ephemeral port
  83. resume_port=`cat "$ready_file"`
  84. echo "./examples/client/client $1 -r -p $resume_port"
  85. capture_out=$(./examples/client/client $1 -r -p $resume_port 2>&1)
  86. client_result=$?
  87. if [ $client_result != 0 ]
  88. then
  89. echo -e "client failed!\ncapture_out=$capture_out\nclient_result=$client_result"
  90. do_cleanup
  91. exit 1
  92. fi
  93. wait $server_pid
  94. server_result=$?
  95. remove_ready_file
  96. if [ $server_result != 0 ]
  97. then
  98. echo -e "client failed!"
  99. exit 1
  100. fi
  101. case "$capture_out" in
  102. *$resume_string*)
  103. echo "resumed session" ;;
  104. *)
  105. echo "did NOT resume session as expected"
  106. exit 1
  107. ;;
  108. esac
  109. }
  110. trap do_trap INT TERM
  111. ./examples/client/client '-?' 2>&1 | grep -- 'Client not compiled in!'
  112. if [ $? -ne 0 ]; then
  113. ./examples/server/server '-?' 2>&1 | grep -- 'Server not compiled in!'
  114. if [ $? -ne 0 ]; then
  115. RUN_TEST="Y"
  116. fi
  117. fi
  118. ./examples/client/client '-?' 2>&1 | grep -- 'Resume session'
  119. if [ $? -ne 0 ]; then
  120. RUN_TEST="Y"
  121. fi
  122. if [ "$RUN_TEST" = "Y" ]; then
  123. do_test
  124. # Check the client for the extended master secret disable option. If
  125. # present we need to run the test twice.
  126. options_check=`./examples/client/client -?`
  127. case "$options_check" in
  128. *$ems_string*)
  129. echo -e "\nRepeating resume test without extended master secret..."
  130. do_test -n ;;
  131. *)
  132. ;;
  133. esac
  134. fi
  135. echo -e "\nSuccess!\n"
  136. exit 0