|
2 | 2 |
|
3 | 3 | echo "Running all wolfSSHd tests" |
4 | 4 |
|
5 | | -if [ -z "$1" ]; then |
6 | | - USER=$USER |
7 | | -else |
8 | | - USER=$1 |
9 | | -fi |
| 5 | +# Define an array of test cases |
| 6 | +test_cases=( |
| 7 | + "sshd_exec_test.sh" |
| 8 | + "sshd_term_size_test.sh" |
| 9 | + "sshd_large_sftp_test.sh" |
| 10 | + "sshd_bad_sftp_test.sh" |
| 11 | + "sshd_term_close_test.sh" |
| 12 | + "ssh_kex_algos.sh" |
| 13 | +) |
| 14 | + |
| 15 | +# Set defaults |
| 16 | +USER=$USER |
| 17 | + |
| 18 | +# Parse arguments |
| 19 | +MATCH="" |
| 20 | +EXCLUDE="" |
| 21 | +while [[ "$#" -gt 0 ]]; do |
| 22 | + case "$1" in |
| 23 | + --match) |
| 24 | + MATCH="$2" |
| 25 | + shift 2 |
| 26 | + ;; |
| 27 | + |
| 28 | + --exclude) |
| 29 | + EXCLUDE="$2" |
| 30 | + shift 2 |
| 31 | + ;; |
| 32 | + |
| 33 | + --user) |
| 34 | + USER="$2" |
| 35 | + shift 2 |
| 36 | + ;; |
10 | 37 |
|
11 | | -TEST_HOST=$2 |
12 | | -TEST_PORT=$3 |
| 38 | + --host) |
| 39 | + TEST_HOST="$2" |
| 40 | + shift 2 |
| 41 | + ;; |
| 42 | + |
| 43 | + --port) |
| 44 | + TEST_PORT="$2" |
| 45 | + shift 2 |
| 46 | + ;; |
| 47 | + |
| 48 | + *) |
| 49 | + echo "Unknown option: $1" |
| 50 | + echo "Expecting --host <host> | --port <port> | --user <user> | --match <test case> | --exclude <test case>" |
| 51 | + echo "All test cases:" |
| 52 | + for test in "${test_cases[@]}"; do |
| 53 | + echo " $test" |
| 54 | + done |
| 55 | + exit 1 |
| 56 | + ;; |
| 57 | + esac |
| 58 | +done |
13 | 59 |
|
14 | 60 | TOTAL=0 |
15 | 61 | SKIPPED=0 |
@@ -57,41 +103,62 @@ run_test() { |
57 | 103 | fi |
58 | 104 | } |
59 | 105 |
|
60 | | -run_test "sshd_exec_test.sh" |
61 | | -run_test "sshd_term_size_test.sh" |
62 | | -run_test "sshd_large_sftp_test.sh" |
63 | | -run_test "sshd_bad_sftp_test.sh" |
64 | | -run_test "sshd_term_close_test.sh" |
| 106 | +# Run the tests |
| 107 | +if [[ -n "$MATCH" ]]; then |
| 108 | + if [[ " ${test_cases[*]} " =~ " $MATCH " ]]; then |
| 109 | + echo "Running test: $MATCH" |
| 110 | + run_test "$MATCH" |
| 111 | + else |
| 112 | + echo "Error: Test '$MATCH' not found." |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | + |
| 116 | + if [ "$USING_LOCAL_HOST" == 1 ]; then |
| 117 | + printf "Shutting down test wolfSSHd\n" |
| 118 | + stop_wolfsshd |
| 119 | + fi |
| 120 | +else |
| 121 | + echo "Running all tests..." |
| 122 | + for test in "${test_cases[@]}"; do |
| 123 | + if [[ "$test" != "$EXCLUDE" ]]; then |
| 124 | + echo "Running test: $test" |
| 125 | + run_test "$test" |
| 126 | + else |
| 127 | + echo "Test '$test' is excluded. Skipping." |
| 128 | + SKIPPED=$((SKIPPED+1)) |
| 129 | + fi |
| 130 | + done |
65 | 131 |
|
66 | | -#Github actions needs resolved for these test cases |
67 | | -#run_test "error_return.sh" |
68 | | -#run_test "sshd_login_grace_test.sh" |
| 132 | + #Github actions needs resolved for these test cases |
| 133 | + #run_test "error_return.sh" |
| 134 | + #run_test "sshd_login_grace_test.sh" |
69 | 135 |
|
70 | | -# add aditional tests here, check on var USING_LOCAL_HOST if can make sshd |
71 | | -# server start/restart with changes |
| 136 | + # add aditional tests here, check on var USING_LOCAL_HOST if can make sshd |
| 137 | + # server start/restart with changes |
72 | 138 |
|
73 | | -if [ "$USING_LOCAL_HOST" == 1 ]; then |
74 | | - printf "Shutting down test wolfSSHd\n" |
75 | | - stop_wolfsshd |
76 | | -fi |
| 139 | + if [ "$USING_LOCAL_HOST" == 1 ]; then |
| 140 | + printf "Shutting down test wolfSSHd\n" |
| 141 | + stop_wolfsshd |
| 142 | + fi |
77 | 143 |
|
78 | | -# these tests require setting up an sshd |
79 | | -if [ "$USING_LOCAL_HOST" == 1 ]; then |
80 | | - run_test "sshd_forcedcmd_test.sh" |
81 | | - run_test "sshd_window_full_test.sh" |
82 | | -else |
83 | | - printf "Skipping tests that need to setup local SSHD\n" |
84 | | - SKIPPED=$((SKIPPED+2)) |
85 | | -fi |
| 144 | + # these tests require setting up an sshd |
| 145 | + if [ "$USING_LOCAL_HOST" == 1 ]; then |
| 146 | + run_test "sshd_forcedcmd_test.sh" |
| 147 | + run_test "sshd_window_full_test.sh" |
| 148 | + else |
| 149 | + printf "Skipping tests that need to setup local SSHD\n" |
| 150 | + SKIPPED=$((SKIPPED+2)) |
| 151 | + fi |
86 | 152 |
|
87 | | -# these tests run with X509 sshd-config loaded |
88 | | -if [ "$USING_LOCAL_HOST" == 1 ]; then |
89 | | - start_wolfsshd "sshd_config_test_x509" |
90 | | -fi |
91 | | -run_test "sshd_x509_test.sh" |
92 | | -if [ "$USING_LOCAL_HOST" == 1 ]; then |
93 | | - printf "Shutting down test wolfSSHd\n" |
94 | | - stop_wolfsshd |
| 153 | + # these tests run with X509 sshd-config loaded |
| 154 | + if [ "$USING_LOCAL_HOST" == 1 ]; then |
| 155 | + start_wolfsshd "sshd_config_test_x509" |
| 156 | + fi |
| 157 | + run_test "sshd_x509_test.sh" |
| 158 | + if [ "$USING_LOCAL_HOST" == 1 ]; then |
| 159 | + printf "Shutting down test wolfSSHd\n" |
| 160 | + stop_wolfsshd |
| 161 | + fi |
95 | 162 | fi |
96 | 163 |
|
97 | 164 | printf "All tests ran, $TOTAL passed, $SKIPPED skipped\n" |
|
0 commit comments