Skip to content

Commit 04dfd15

Browse files
author
Test User
committed
Add cmd test arguments
1 parent a8223f5 commit 04dfd15

File tree

2 files changed

+225
-39
lines changed

2 files changed

+225
-39
lines changed

scripts/cmd_test/cmd-test-common.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ use_default_provider() {
5555

5656
# Verify that we are using the default provider
5757
if ${OPENSSL_BIN} list -providers | grep -q "wolfprov"; then
58+
if [ "${WOLFPROV_DEBIAN}" = "1" ]; then
59+
if [ "${WOLFPROV_REPLACE_DEFAULT}" = "1" ]; then
60+
echo "WARNING: wolfProvider is configured as replace-default, cannot switch to default provider"
61+
return 0
62+
fi
63+
else
64+
echo "WARNING: wolfProvider is configured as debian, cannot switch to default provider"
65+
return 0
66+
fi
5867
echo "FAIL: unable to switch to default provider, wolfProvider is still active"
5968
exit 1
6069
fi
@@ -66,12 +75,21 @@ use_wolf_provider() {
6675
export OPENSSL_MODULES=$WOLFPROV_PATH
6776
export OPENSSL_CONF=${WOLFPROV_CONFIG}
6877

69-
# Verify that we are using wolfProvider
70-
if ! ${OPENSSL_BIN} list -providers | grep -q "wolfprov"; then
71-
echo "FAIL: unable to switch to wolfProvider, default provider is still active"
78+
# Verify that we are using the default provider
79+
if ${OPENSSL_BIN} list -providers | grep -q "wolfprov"; then
80+
if [ "${WOLFPROV_DEBIAN}" = "1" ]; then
81+
if [ "${WOLFPROV_REPLACE_DEFAULT}" = "1" ]; then
82+
echo "WARNING: wolfProvider is configured as replace-default, cannot switch to default provider"
83+
return 0
84+
fi
85+
else
86+
echo "WARNING: wolfProvider is configured as debian, cannot switch to default provider"
87+
return 0
88+
fi
89+
echo "FAIL: unable to switch to default provider, wolfProvider is still active"
7290
exit 1
7391
fi
74-
echo "Switched to wolfProvider"
92+
echo "Switched to default provider"
7593
}
7694

7795
# Helper function to handle force fail checks

scripts/cmd_test/do-cmd-tests.sh

Lines changed: 203 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,124 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
2424
REPO_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
2525
UTILS_DIR="${REPO_ROOT}/scripts"
2626

27+
# Parse command-line arguments
28+
RUN_HASH=0
29+
RUN_AES=0
30+
RUN_RSA=0
31+
RUN_ECC=0
32+
RUN_REQ=0
33+
RUN_ALL=1
34+
35+
show_help() {
36+
cat << EOF
37+
Usage: $0 [OPTIONS] [TESTS]
38+
39+
Run wolfProvider command-line tests with optional configuration flags.
40+
41+
OPTIONS:
42+
--fips Enable FIPS mode (sets WOLFSSL_ISFIPS=1)
43+
--replace-default Indicate that wolfProvider is configured as replace-default
44+
(requires --debian to be specified)
45+
--force-fail Enable force-fail mode (sets WOLFPROV_FORCE_FAIL=1)
46+
--debian Specify if using Debian packages (required with --replace-default)
47+
--help Show this help message
48+
49+
TESTS (if none specified, all tests run):
50+
hash Run hash comparison test
51+
aes Run AES comparison test
52+
rsa Run RSA key generation test
53+
ecc Run ECC key generation test
54+
req Run certificate request test
55+
56+
EXAMPLES:
57+
$0 # Run all tests
58+
$0 --fips # Run all tests in FIPS mode
59+
$0 --debian --replace-default rsa ecc # Run RSA and ECC tests with replace-default
60+
$0 --fips --force-fail hash # Run hash test in FIPS mode with force-fail
61+
62+
ENVIRONMENT VARIABLES:
63+
OPENSSL_BIN Path to OpenSSL binary (auto-detected if not set)
64+
WOLFPROV_PATH Path to wolfProvider modules directory
65+
WOLFPROV_CONFIG Path to wolfProvider config file
66+
WOLFSSL_ISFIPS Set to 1 for FIPS mode (or use --fips flag)
67+
WOLFPROV_FORCE_FAIL Set to 1 for force-fail mode (or use --force-fail flag)
68+
69+
EOF
70+
exit 0
71+
}
72+
73+
# Parse arguments
74+
while [[ $# -gt 0 ]]; do
75+
case $1 in
76+
--fips)
77+
export WOLFSSL_ISFIPS=1
78+
shift
79+
;;
80+
--replace-default)
81+
export WOLFPROV_REPLACE_DEFAULT=1
82+
shift
83+
;;
84+
--force-fail)
85+
export WOLFPROV_FORCE_FAIL=1
86+
shift
87+
;;
88+
--debian)
89+
export WOLFPROV_DEBIAN=1
90+
shift
91+
;;
92+
--help|-h)
93+
show_help
94+
;;
95+
hash)
96+
RUN_HASH=1
97+
RUN_ALL=0
98+
shift
99+
;;
100+
aes)
101+
RUN_AES=1
102+
RUN_ALL=0
103+
shift
104+
;;
105+
rsa)
106+
RUN_RSA=1
107+
RUN_ALL=0
108+
shift
109+
;;
110+
ecc)
111+
RUN_ECC=1
112+
RUN_ALL=0
113+
shift
114+
;;
115+
req)
116+
RUN_REQ=1
117+
RUN_ALL=0
118+
shift
119+
;;
120+
*)
121+
echo "Unknown option: $1"
122+
echo "Use --help for usage information"
123+
exit 1
124+
;;
125+
esac
126+
done
127+
128+
# Validate that --debian is specified when --replace-default is used
129+
if [ "${WOLFPROV_REPLACE_DEFAULT:-0}" = "1" ] && [ "${WOLFPROV_DEBIAN:-0}" != "1" ]; then
130+
echo "ERROR: --replace-default requires --debian to be specified"
131+
echo "Replace-default mode is only available with Debian packages"
132+
echo "Use --help for usage information"
133+
exit 1
134+
fi
135+
136+
# If no specific tests were requested, run all tests
137+
if [ $RUN_ALL -eq 1 ]; then
138+
RUN_HASH=1
139+
RUN_AES=1
140+
RUN_RSA=1
141+
RUN_ECC=1
142+
RUN_REQ=1
143+
fi
144+
27145
source "${SCRIPT_DIR}/cmd-test-common.sh"
28146

29147
# If OPENSSL_BIN is not set, assume we are using a local build
@@ -59,63 +177,113 @@ echo "=== Running wolfProvider Command-Line Tests ==="
59177
echo "Using OPENSSL_BIN: ${OPENSSL_BIN}"
60178
echo "Using WOLFPROV_PATH: ${WOLFPROV_PATH}"
61179
echo "Using WOLFPROV_CONFIG: ${WOLFPROV_CONFIG}"
180+
if [ "${WOLFSSL_ISFIPS}" = "1" ]; then
181+
echo "FIPS mode: ENABLED"
182+
fi
183+
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
184+
echo "Force-fail mode: ENABLED"
185+
fi
186+
if [ "${WOLFPROV_REPLACE_DEFAULT}" = "1" ]; then
187+
echo "Replace-default mode: ENABLED"
188+
fi
62189

63190
# Ensure we can switch providers before proceeding
64191
use_default_provider
65192
use_wolf_provider
66193

194+
# Initialize result variables
195+
HASH_RESULT=0
196+
AES_RESULT=0
197+
RSA_RESULT=0
198+
ECC_RESULT=0
199+
REQ_RESULT=0
200+
67201
# Run the hash comparison test
68-
echo -e "\n=== Running Hash Comparison Test ==="
69-
"${REPO_ROOT}/scripts/cmd_test/hash-cmd-test.sh"
70-
HASH_RESULT=$?
202+
if [ $RUN_HASH -eq 1 ]; then
203+
echo -e "\n=== Running Hash Comparison Test ==="
204+
"${REPO_ROOT}/scripts/cmd_test/hash-cmd-test.sh"
205+
HASH_RESULT=$?
206+
fi
71207

72208
# Run the AES comparison test
73-
echo -e "\n=== Running AES Comparison Test ==="
74-
"${REPO_ROOT}/scripts/cmd_test/aes-cmd-test.sh"
75-
AES_RESULT=$?
209+
if [ $RUN_AES -eq 1 ]; then
210+
echo -e "\n=== Running AES Comparison Test ==="
211+
"${REPO_ROOT}/scripts/cmd_test/aes-cmd-test.sh"
212+
AES_RESULT=$?
213+
fi
76214

77215
# Run the RSA key generation test
78-
echo -e "\n=== Running RSA Key Generation Test ==="
79-
"${REPO_ROOT}/scripts/cmd_test/rsa-cmd-test.sh"
80-
RSA_RESULT=$?
216+
if [ $RUN_RSA -eq 1 ]; then
217+
echo -e "\n=== Running RSA Key Generation Test ==="
218+
"${REPO_ROOT}/scripts/cmd_test/rsa-cmd-test.sh"
219+
RSA_RESULT=$?
220+
fi
81221

82222
# Run the ECC key generation test
83-
echo -e "\n=== Running ECC Key Generation Test ==="
84-
"${REPO_ROOT}/scripts/cmd_test/ecc-cmd-test.sh"
85-
ECC_RESULT=$?
223+
if [ $RUN_ECC -eq 1 ]; then
224+
echo -e "\n=== Running ECC Key Generation Test ==="
225+
"${REPO_ROOT}/scripts/cmd_test/ecc-cmd-test.sh"
226+
ECC_RESULT=$?
227+
fi
86228

87229
# Run the Certificate Request test
88-
echo -e "\n=== Running Certificate Request Test ==="
89-
"${REPO_ROOT}/scripts/cmd_test/req-cmd-test.sh"
90-
REQ_RESULT=$?
230+
if [ $RUN_REQ -eq 1 ]; then
231+
echo -e "\n=== Running Certificate Request Test ==="
232+
"${REPO_ROOT}/scripts/cmd_test/req-cmd-test.sh"
233+
REQ_RESULT=$?
234+
fi
91235

92236
# Check results
93-
if [ $HASH_RESULT -eq 0 ] && [ $AES_RESULT -eq 0 ] && [ $RSA_RESULT -eq 0 ] && [ $ECC_RESULT -eq 0 ] && [ $REQ_RESULT -eq 0 ]; then
237+
ALL_PASSED=1
238+
if [ $RUN_HASH -eq 1 ] && [ $HASH_RESULT -ne 0 ]; then
239+
ALL_PASSED=0
240+
fi
241+
if [ $RUN_AES -eq 1 ] && [ $AES_RESULT -ne 0 ]; then
242+
ALL_PASSED=0
243+
fi
244+
if [ $RUN_RSA -eq 1 ] && [ $RSA_RESULT -ne 0 ]; then
245+
ALL_PASSED=0
246+
fi
247+
if [ $RUN_ECC -eq 1 ] && [ $ECC_RESULT -ne 0 ]; then
248+
ALL_PASSED=0
249+
fi
250+
if [ $RUN_REQ -eq 1 ] && [ $REQ_RESULT -ne 0 ]; then
251+
ALL_PASSED=0
252+
fi
253+
254+
if [ $ALL_PASSED -eq 1 ]; then
94255
echo -e "\n=== All Command-Line Tests Passed ==="
95-
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
96-
echo "Force fail mode was enabled"
97-
fi
98-
if [ "${WOLFSSL_ISFIPS}" = "1" ]; then
99-
echo "FIPS mode was enabled"
100-
fi
101-
echo "Hash Test Result: $HASH_RESULT (0=success)"
102-
echo "AES Test Result: $AES_RESULT (0=success)"
103-
echo "RSA Test Result: $RSA_RESULT (0=success)"
104-
echo "ECC Test Result: $ECC_RESULT (0=success)"
105-
echo "REQ Test Result: $REQ_RESULT (0=success)"
106-
exit 0
107256
else
108257
echo -e "\n=== Command-Line Tests Failed ==="
109-
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
110-
echo "Force fail mode was enabled"
111-
fi
112-
if [ "${WOLFSSL_ISFIPS}" = "1" ]; then
113-
echo "FIPS mode was enabled"
114-
fi
258+
fi
259+
260+
# Print configuration
261+
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
262+
echo "Force fail mode was enabled"
263+
fi
264+
if [ "${WOLFSSL_ISFIPS}" = "1" ]; then
265+
echo "FIPS mode was enabled"
266+
fi
267+
if [ "${WOLFPROV_REPLACE_DEFAULT}" = "1" ]; then
268+
echo "Replace-default mode was enabled"
269+
fi
270+
271+
# Print test results (only for tests that were run)
272+
echo ""
273+
if [ $RUN_HASH -eq 1 ]; then
115274
echo "Hash Test Result: $HASH_RESULT (0=success)"
275+
fi
276+
if [ $RUN_AES -eq 1 ]; then
116277
echo "AES Test Result: $AES_RESULT (0=success)"
278+
fi
279+
if [ $RUN_RSA -eq 1 ]; then
117280
echo "RSA Test Result: $RSA_RESULT (0=success)"
281+
fi
282+
if [ $RUN_ECC -eq 1 ]; then
118283
echo "ECC Test Result: $ECC_RESULT (0=success)"
284+
fi
285+
if [ $RUN_REQ -eq 1 ]; then
119286
echo "REQ Test Result: $REQ_RESULT (0=success)"
120-
exit 1
121287
fi
288+
289+
exit $((1 - ALL_PASSED))

0 commit comments

Comments
 (0)