Skip to content

Commit

Permalink
Add some basic tests around URIs
Browse files Browse the repository at this point in the history
Signed-off-by: Simo Sorce <simo@redhat.com>
  • Loading branch information
simo5 committed Apr 19, 2023
1 parent dd6c532 commit 85b25e4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tmp.softhsm:
dist_check_SCRIPTS = \
helpers.sh setup-softhsm.sh setup-softokn.sh softhsm-proxy.sh \
test-wrapper tbasic tcerts tecc tecdh tedwards tdemoca thkdf \
toaepsha2 trsapss tdigest ttls tpubkey tfork
toaepsha2 trsapss tdigest ttls tpubkey tfork turi

test_LIST = \
basic-softokn basic-softhsm \
Expand All @@ -70,7 +70,8 @@ test_LIST = \
genkey-softokn genkey-softhsm \
session-softokn session-softhsm \
readkeys-softokn readkeys-softhsm \
tls-softokn tls-softhsm
tls-softokn tls-softhsm \
uri-softokn uri-softhsm

.PHONY: $(test_LIST)

Expand Down
47 changes: 47 additions & 0 deletions tests/turi
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash -e
# Copyright (C) 2023 Simo Sorce <simo@redhat.com>
# SPDX-License-Identifier: Apache-2.0

source ${TESTSSRCDIR}/helpers.sh

title PARA "Check that storeutl returns URIs"
ossl 'storeutl -text pkcs11:' $helper_emit
output="$helper_output"
FAIL=0
echo "$output" | grep "URI pkcs11:" > /dev/null 2>&1 || FAIL=1
if [ $FAIL -ne 0 ]; then
echo "no URIs returned by storeutl"
exit 1
fi

URISonly=$(echo "$helper_output" | grep "^URI")
URIS=(${URISonly//URI / })

title PARA "Check returned URIs work to find objects"
for uri in "${URIS[@]#URI }"; do
echo "\$uri=${uri}"
ossl 'storeutl -text "$uri"' $helper_emit
output="$helper_output"
matchURI=`echo "$output" | grep "URI pkcs11:" | cut -d ' ' -f 2`
if [[ "${uri}" != "${matchURI}" ]]; then
echo "Unmatched URI returned by storeutl"
echo "Expected $uri"
echo "Received $matchURI"
exit 1
fi
done

firstURI=${URIS[0]#URI pkcs11:}
firstCMPS=(${firstURI//;/ })

title PARA "Check each URI component is tested"

for cmp in "${firstCMPS[@]}"; do
echo "\$cmp=${cmp}"
ossl 'storeutl -text "pkcs11:${cmp}"' $helper_emit
output="$helper_output"
echo "$output" | grep "URI pkcs11:" > /dev/null 2>&1 || FAIL=1
if [ $FAIL -ne 0 ]; then
echo "Failed to get an object with URI \"pkcs11:${cmp}\""
fi
done

0 comments on commit 85b25e4

Please sign in to comment.