Skip to content

Commit

Permalink
tests: Port shell-script tests to using test-init.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno authored and ZoltanFridrich committed Sep 15, 2023
1 parent ef2e9fd commit 65b2e47
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 175 deletions.
43 changes: 25 additions & 18 deletions p11-kit/test-messages.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/bin/sh

set -e
test "${abs_top_builddir+set}" = set || {
echo "set abs_top_builddir" 1>&2
exit 1
}

testdir=$PWD/test-messages-$$
test -d "$testdir" || mkdir "$testdir"
. "$abs_top_builddir/common/test-init.sh"

cleanup () {
rm -rf "$testdir"
setup() {
testdir=$PWD/test-messages-$$
test -d "$testdir" || mkdir "$testdir"
cd "$testdir"
}
trap cleanup 0

cd "$testdir"
teardown() {
rm -rf "$testdir"
}

cat > messages.exp <<EOF
test_messages() {
cat > messages.exp <<EOF
CKR_CANCEL: The operation was cancelled
CKR_FUNCTION_CANCELED: The operation was cancelled
CKR_HOST_MEMORY: Insufficient memory available
Expand Down Expand Up @@ -96,15 +102,16 @@ CKR_MUTEX_NOT_LOCKED: The data cannot be locked
CKR_FUNCTION_REJECTED: The request was rejected by the user
EOF

${WINE} "$abs_top_builddir"/p11-kit/print-messages | tr -d '\r' > messages.out
: ${WINE=}
if ! ${WINE} "$abs_top_builddir"/p11-kit/print-messages | tr -d '\r' > messages.out; then
assert_fail "unable to run print-messages"
fi

echo 1..1
: ${DIFF=diff}
if ! ${DIFF} messages.exp messages.out > messages.diff; then
sed 's/^/# /' messages.diff
assert_fail "output contains incorrect messages"
fi
}

: ${DIFF=diff}
if ${DIFF} messages.exp messages.out > messages.diff; then
echo "ok 1 /messages/return-code"
else
echo "not ok 1 /messages/return-code"
sed 's/^/# /' messages.diff
exit 1
fi
run test_messages
146 changes: 68 additions & 78 deletions p11-kit/test-objects.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/bin/sh

set -e
test "${abs_top_builddir+set}" = set || {
echo "set abs_top_builddir" 1>&2
exit 1
}

testdir=$PWD/test-objects-$$
test -d "$testdir" || mkdir "$testdir"
. "$abs_top_builddir/common/test-init.sh"

cleanup () {
rm -rf "$testdir"
setup() {
testdir=$PWD/test-objects-$$
test -d "$testdir" || mkdir "$testdir"
cd "$testdir"
}
trap cleanup 0

cd "$testdir"
teardown() {
rm -rf "$testdir"
}

cat > list.exp <<EOF
test_list_all() {
cat > list.exp <<EOF
Object: #0
uri: pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20LABEL;type=data
class: data
Expand Down Expand Up @@ -84,20 +90,17 @@ Object: #14
private: false
EOF

"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:" > list.out

echo 1..6
"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:" > list.out

: ${DIFF=diff}
if ${DIFF} list.exp list.out > list.diff; then
echo "ok 1 /objects/list-objects-all"
else
echo "not ok 1 /objects/list-objects-all"
sed 's/^/# /' list.diff
exit 1
fi
: ${DIFF=diff}
if ! ${DIFF} list.exp list.out > list.diff; then
sed 's/^/# /' list.diff
assert_fail "output contains incorrect result"
fi
}

cat > list.exp <<EOF
test_list_with_type() {
cat > list.exp <<EOF
Object: #0
uri: pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20LABEL;type=data
class: data
Expand All @@ -116,57 +119,48 @@ Object: #3
label: TEST LABEL
EOF

"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:type=data" > list.out

echo 2..6
"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:type=data" > list.out

: ${DIFF=diff}
if ${DIFF} list.exp list.out > list.diff; then
echo "ok 2 /objects/list-objects-data"
else
echo "not ok 2 /objects/list-objects-data"
sed 's/^/# /' list.diff
exit 1
fi
: ${DIFF=diff}
if ! ${DIFF} list.exp list.out > list.diff; then
sed 's/^/# /' list.diff
assert_fail "output contains wrong result"
fi
}

cat > list.exp <<EOF
test_list_exact() {
cat > list.exp <<EOF
Object: #0
uri: pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20CERTIFICATE;type=cert
class: certificate
certificate-type: x-509
label: TEST CERTIFICATE
EOF

"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20CERTIFICATE;type=cert" > list.out
"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20CERTIFICATE;type=cert" > list.out

echo 3..6

: ${DIFF=diff}
if ${DIFF} list.exp list.out > list.diff; then
echo "ok 3 /objects/list-objects-specific"
else
echo "not ok 3 /objects/list-objects-specific"
sed 's/^/# /' list.diff
exit 1
fi
: ${DIFF=diff}
if ! ${DIFF} list.exp list.out > list.diff; then
sed 's/^/# /' list.diff
assert_fail "output contains wrong result"
fi
}

cat > list.exp <<EOF
test_list_nonexistent() {
cat > list.exp <<EOF
EOF

"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:model=NONEXISTENT" > list.out
"$abs_top_builddir"/p11-kit/p11-kit-testable list-objects -q "pkcs11:model=NONEXISTENT" > list.out

echo 4..6

: ${DIFF=diff}
if ${DIFF} list.exp list.out > list.diff; then
echo "ok 4 /objects/list-objects-nonexistent"
else
echo "not ok 4 /objects/list-objects-nonexistent"
sed 's/^/# /' list.diff
exit 1
fi
: ${DIFF=diff}
if ! ${DIFF} list.exp list.out > list.diff; then
sed 's/^/# /' list.diff
assert_fail "output contains wrong result"
fi
}

cat > list.exp <<EOF
test_export_cert() {
cat > list.exp <<EOF
-----BEGIN CERTIFICATE-----
MIIBajCCARSgAwIBAgICA+cwDQYJKoZIhvcNAQEFBQAwKDEmMCQGA1UEAxMdZmFy
LWluLXRoZS1mdXR1cmUuZXhhbXBsZS5jb20wIBcNMTMwMzI3MTY0OTMzWhgPMjA2
Expand All @@ -179,36 +173,32 @@ X4wmG2aWDmRSHACW+4F3ojodSQwD1RnyagEpMfv1
-----END CERTIFICATE-----
EOF

"$abs_top_builddir"/p11-kit/p11-kit-testable export-object -q "pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20CERTIFICATE;type=cert" > list.out
"$abs_top_builddir"/p11-kit/p11-kit-testable export-object -q "pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20CERTIFICATE;type=cert" > list.out

echo 5..6

: ${DIFF=diff}
if ${DIFF} list.exp list.out > list.diff; then
echo "ok 5 /objects/export-object-cert"
else
echo "not ok 5 /objects/export-object-cert"
sed 's/^/# /' list.diff
exit 1
fi
: ${DIFF=diff}
if ! ${DIFF} list.exp list.out > list.diff; then
sed 's/^/# /' list.diff
assert_fail "output contains wrong result"
fi
}

cat > list.exp <<EOF
test_export_pubkey() {
cat > list.exp <<EOF
-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEn1LlwLN/KBYQRVH6HfIMTzfEqJOVztLe
kLchp2hi78cCaMY81FBlYs8J9l7krc+M4aBeCGYFjba+hiXttJWPL7ydlE+5UG4U
Nkn3Eos8EiZByi9DVsyfy9eejh+8AXgp
-----END PUBLIC KEY-----
EOF

"$abs_top_builddir"/p11-kit/p11-kit-testable export-object -q "pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20PUBLIC%20KEY;type=public" > list.out
"$abs_top_builddir"/p11-kit/p11-kit-testable export-object -q "pkcs11:model=TEST%20MODEL;manufacturer=TEST%20MANUFACTURER;serial=TEST%20SERIAL;token=TEST%20LABEL;object=TEST%20PUBLIC%20KEY;type=public" > list.out

echo 6..6
: ${DIFF=diff}
if ! ${DIFF} list.exp list.out > list.diff; then
sed 's/^/# /' list.diff
assert_fail "output contains wrong result"
fi
}

: ${DIFF=diff}
if ${DIFF} list.exp list.out > list.diff; then
echo "ok 6 /objects/export-object-pubkey"
else
echo "not ok 6 /objects/export-object-pubkey"
sed 's/^/# /' list.diff
exit 1
fi
run test_list_all test_list_with_type test_list_exact test_list_nonexistent \
test_export_cert test_export_pubkey
40 changes: 22 additions & 18 deletions p11-kit/test-profiles.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
#!/bin/sh

set -e
test "${abs_top_builddir+set}" = set || {
echo "set abs_top_builddir" 1>&2
exit 1
}

testdir=$PWD/test-profiles-$$
test -d "$testdir" || mkdir "$testdir"
. "$abs_top_builddir/common/test-init.sh"

cleanup () {
rm -rf "$testdir"
setup() {
testdir=$PWD/test-profiles-$$
test -d "$testdir" || mkdir "$testdir"
cd "$testdir"
}
trap cleanup 0

cd "$testdir"
teardown() {
rm -rf "$testdir"
}

cat > list.exp <<EOF
test_list_profiles() {
cat > list.exp <<EOF
public-certificates-token
EOF

"$abs_top_builddir"/p11-kit/p11-kit-testable list-profiles -q pkcs11: > list.out
"$abs_top_builddir"/p11-kit/p11-kit-testable list-profiles -q pkcs11: > list.out

echo 1..1
: ${DIFF=diff}
if ! ${DIFF} list.exp list.out > list.diff; then
sed 's/^/# /' list.diff
assert_fail "output contains wrong results"
fi
}

: ${DIFF=diff}
if ${DIFF} list.exp list.out > list.diff; then
echo "ok 1 /profiles/list"
else
echo "not ok 1 /profiles/list"
sed 's/^/# /' list.diff
exit 1
fi
run test_list_profiles
Loading

0 comments on commit 65b2e47

Please sign in to comment.