resume.test 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. ./examples/server/server -r -R "$ready_file" -p $resume_port &
  61. server_pid=$!
  62. while [ ! -s "$ready_file" -a "$counter" -lt 20 ]; do
  63. echo -e "waiting for ready file..."
  64. sleep 0.1
  65. counter=$((counter+ 1))
  66. done
  67. if test -e "$ready_file"; then
  68. echo -e "found ready file, starting client..."
  69. else
  70. echo -e "NO ready file ending test..."
  71. do_cleanup
  72. exit 1
  73. fi
  74. # sleep for an additional 0.1 to mitigate race on write/read of $ready_file:
  75. sleep 0.1
  76. # get created port 0 ephemeral port
  77. resume_port=`cat "$ready_file"`
  78. capture_out=$(./examples/client/client $1 -r -p $resume_port 2>&1)
  79. client_result=$?
  80. if [ $client_result != 0 ]
  81. then
  82. echo -e "client failed!\ncapture_out=$capture_out\nclient_result=$client_result"
  83. do_cleanup
  84. exit 1
  85. fi
  86. wait $server_pid
  87. server_result=$?
  88. remove_ready_file
  89. if [ $server_result != 0 ]
  90. then
  91. echo -e "client failed!"
  92. exit 1
  93. fi
  94. case "$capture_out" in
  95. *$resume_string*)
  96. echo "resumed session" ;;
  97. *)
  98. echo "did NOT resume session as expected"
  99. exit 1
  100. ;;
  101. esac
  102. }
  103. trap do_trap INT TERM
  104. ./examples/client/client '-?' 2>&1 | grep -- 'Client not compiled in!'
  105. if [ $? -ne 0 ]; then
  106. ./examples/server/server '-?' 2>&1 | grep -- 'Server not compiled in!'
  107. if [ $? -ne 0 ]; then
  108. RUN_TEST="Y"
  109. fi
  110. fi
  111. ./examples/client/client '-?' 2>&1 | grep -- 'Resume session'
  112. if [ $? -ne 0 ]; then
  113. RUN_TEST="Y"
  114. fi
  115. if [ "$RUN_TEST" = "Y" ]; then
  116. do_test
  117. # Check the client for the extended master secret disable option. If
  118. # present we need to run the test twice.
  119. options_check=`./examples/client/client -?`
  120. case "$options_check" in
  121. *$ems_string*)
  122. echo -e "\nRepeating resume test without extended master secret..."
  123. do_test -n ;;
  124. *)
  125. ;;
  126. esac
  127. fi
  128. echo -e "\nSuccess!\n"
  129. exit 0