diff --git a/common/test-init.sh.in b/common/test-init.sh.in index 384fb250..517905ee 100644 --- a/common/test-init.sh.in +++ b/common/test-init.sh.in @@ -32,14 +32,14 @@ assert_fail() assert_contains() { - if ! grep -qF $2 $1; then + if ! grep -qF "$2" "$1"; then assert_fail "$1 does not contain $2" fi } assert_not_contains() { - if grep -qF $2 $1; then + if grep -qF "$2" "$1"; then assert_fail "$1 contains $2" fi } diff --git a/p11-kit/test-objects.sh b/p11-kit/test-objects.sh index 8d7e2039..876e20c9 100755 --- a/p11-kit/test-objects.sh +++ b/p11-kit/test-objects.sh @@ -258,5 +258,38 @@ EOF fi } +test_generate_keypair_nonexistent_token() { + cat > list.exp < list.out 2> err.out; then + assert_fail "expected to fail: p11-kit generate-keypair" + fi + + : ${DIFF=diff} + if ! ${DIFF} list.exp list.out > list.diff; then + sed 's/^/# /' list.diff + assert_fail "output contains wrong result" + fi + assert_contains err.out "no matching token" +} + +test_delete_nonexistent_token() { + cat > list.exp < list.out 2> err.out; then + assert_fail "expected to fail: p11-kit delete-object" + fi + + : ${DIFF=diff} + if ! ${DIFF} list.exp list.out > list.diff; then + sed 's/^/# /' list.diff + assert_fail "output contains wrong result" + fi + assert_contains err.out "no matching object" +} + run test_list_all test_list_with_type test_list_exact test_list_nonexistent \ - test_export_cert test_export_pubkey test_generate_keypair + test_export_cert test_export_pubkey test_generate_keypair test_generate_keypair_nonexistent_token \ + test_delete_nonexistent_token diff --git a/p11-kit/test-profiles.sh b/p11-kit/test-profiles.sh index 46f0cb69..4b26b01e 100755 --- a/p11-kit/test-profiles.sh +++ b/p11-kit/test-profiles.sh @@ -33,4 +33,21 @@ EOF fi } -run test_list_profiles +test_add_profile_nonexistent_token() { + cat > list.exp < list.out 2> err.out; then + assert_fail "expected to fail: p11-kit add-profile" + fi + + : ${DIFF=diff} + if ! ${DIFF} list.exp list.out > list.diff; then + sed 's/^/# /' list.diff + assert_fail "output contains wrong results" + fi + assert_contains err.out "no matching token" +} + +run test_list_profiles \ + test_add_profile_nonexistent_token