resume.test 3.8 KB

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