Debian Codegraph @

testcases/unit/pintest.sh

raw
1 #!/bin/bash
2 #
3 # COPYRIGHT (c) International Business Machines Corp. 2022
4 #
5 # This program is provided under the terms of the Common Public License,
6 # version 1.0 (CPL-1.0). Any use, reproduction or distribution for this software
7 # constitutes recipient's acceptance of CPL-1.0 terms which can be found
8 # in the file LICENSE file or at https://opensource.org/licenses/cpl1.0.php
9
10 PINTEST=testcases/unit/pintest
11
12 # functions
13 print_test_result() {
14 local msg=$1
15 local result=$2
16 local result_exp=$3
17
18 if [ "${result}" = "${result_exp}" ]; then
19 printf "${msg}: PASS result: \"${result}\", expected: \"${result_exp}\"\n"
20 RC=0
21 else
22 printf "${msg}: FAIL result: ${result}, expected: ${result_exp}\n"
23 RC=1
24 fi
25 return $RC
26 }
27
28 unset PKCS11_USER_PIN
29 unset PKCS11_SO_PIN
30
31 TEST_PIN=12345678
32 RESULT_PIN="pin: ${TEST_PIN}"
33 RESULT_ERR="pin: (null)"
34
35 # prompt
36 RESULT=$(printf "${TEST_PIN}\n" | ${PINTEST} -p | tail -n1 )
37 print_test_result "pin prompt" "${RESULT}" "${RESULT_PIN}" || exit 99
38
39 RESULT=$(printf "${TEST_PIN}\n${TEST_PIN}\n" | ${PINTEST} -n | tail -n1 )
40 print_test_result "pin prompt-new" "${RESULT}" "${RESULT_PIN}" || exit 99
41
42 RESULT=$(printf "\n\n" | ${PINTEST} -n | tail -n1 )
43 print_test_result "pin prompt-new" "${RESULT}" "${RESULT_ERR}" || exit 99
44
45 RESULT=$(${PINTEST} -p <&- | tail -n1 )
46 print_test_result "pin prompt-user" "${RESULT}" "${RESULT_ERR}" || exit 99
47
48 RESULT=$(${PINTEST} -n <&- | tail -n1 )
49 print_test_result "pin prompt-new" "${RESULT}" "${RESULT_ERR}" || exit 99
50
51 exit 0