From 9c78f3ad6393520557a8bdaf67876908e7b0f3eb Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Tue, 25 Oct 2016 21:33:16 +0200 Subject: [PATCH] last perl tests migrated to unittests.sh --- INSTALL | 6 +- TODO | 2 + include/pcp/config.h.in | 3 - tests/Makefile.am | 4 +- tests/cppunittests.cfg | 10 +-- tests/iotests.cfg | 46 +++++------ tests/jsonunittests.cfg | 41 +++++----- tests/pyunittests.cfg | 14 ++-- tests/stresstests.cfg | 53 +++++++------ tests/unittests.cfg | 168 ++++++++++++++++++++-------------------- tests/unittests.sh | 24 +++--- 11 files changed, 188 insertions(+), 183 deletions(-) diff --git a/INSTALL b/INSTALL index 6e90e07..2099840 100644 --- a/INSTALL +++ b/INSTALL @@ -1,7 +1,7 @@ Installation Instructions ************************* -Copyright (C) 1994-1996, 1999-2002, 2004-2012 Free Software Foundation, +Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, @@ -12,8 +12,8 @@ without warranty of any kind. Basic Installation ================== - Briefly, the shell commands `./configure; make; make install' should -configure, build, and install this package. The following + Briefly, the shell command `./configure && make && make install' +should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented diff --git a/TODO b/TODO index 027c73e..50f3dc5 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +JSON output has \0 always appended check from where this comes + pcpstream.c: use static tmp buffers, avoid alloc mem during each iteration detach keysig generation from pub key export, so that an existing diff --git a/include/pcp/config.h.in b/include/pcp/config.h.in index cd45cda..88f26bc 100644 --- a/include/pcp/config.h.in +++ b/include/pcp/config.h.in @@ -148,9 +148,6 @@ */ #undef LT_OBJDIR -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -#undef NO_MINUS_C_MINUS_O - /* Name of package */ #undef PACKAGE diff --git a/tests/Makefile.am b/tests/Makefile.am index 59b53d4..dd84d1c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -107,8 +107,8 @@ jsontest: ./unittests.sh jsonunittests.cfg $(CHECK) stresstest: check - ./unittests.pl stresstests.cfg + ./unittests.sh stresstests.cfg iotest: check - ./unittests.pl iotests.cfg + ./unittests.sh iotests.cfg sudo umount -f env diff --git a/tests/cppunittests.cfg b/tests/cppunittests.cfg index 9d62593..5bca8dc 100644 --- a/tests/cppunittests.cfg +++ b/tests/cppunittests.cfg @@ -2,31 +2,31 @@ # # test the c++ api -check-cpp-crypto () { +check_cpp_crypto () { cmd="./cpptest 0" expect=/ok/ check "$cmd" "$expect" "$input" } -check-cpp-vault () { +check_cpp_vault () { cmd="./cpptest 1" expect=/ok/ check "$cmd" "$expect" "$input" } -check-cpp-import-pub () { +check_cpp_import_pub () { cmd="./cpptest 2" expect=/ok/ check "$cmd" "$expect" "$input" } -check-cpp-signature () { +check_cpp_signature () { cmd="./cpptest 3" expect=/ok/ check "$cmd" "$expect" "$input" } -check-buffer () { +check_buffer () { cmd="./cpptest 4" expect=/ok/ check "$cmd" "$expect" "$input" diff --git a/tests/iotests.cfg b/tests/iotests.cfg index 84efabc..6146aa3 100644 --- a/tests/iotests.cfg +++ b/tests/iotests.cfg @@ -1,8 +1,8 @@ -# -*-html-*- +# -*-sh-*- # # This file is part of Pretty Curved Privacy (pcp1). # -# Copyright (C) 2013 T.Linden. +# Copyright (C) 2013-2016 T.v.Dein. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,27 +20,29 @@ # You can contact me by mail: . # -pcp = ../src/pcp1 -vault = v1 -passwd = xxx -md5msg = 66b8c4ca9e5d2a7e3c0559c3cdea3d50 +pcp=../src/pcp1 +vault=v1 +passwd=xxx +md5msg=66b8c4ca9e5d2a7e3c0559c3cdea3d50 -include keys.cfg +. ./keys.cfg - - - cmd = which mdmfs - expect = /mdmfs/ - - - cmd = ls $pcp - expect = /pcp/ - - +check_dependencies_shell () { + cmd="which mdmfs" + expect="/mdmfs/" + check "$cmd" "$expect" "$input" +} + +check_dependencies_pcp () { + cmd="ls $pcp" + expect="/pcp/" + check "$cmd" "$expect" "$input" +} # this one only works on freebsd for my user. sorrry - - prepare = sudo mdmfs -s 1M -w 1001:1001 md env && dd if=/dev/zero of=env/b bs=1024 count=700 - cmd = ./jot 100 | while read N; do if ! (echo a; echo b) | $pcp -V env/v1 -k -x x; then break; fi; done - expect = /Failed to copy/ - +check_vault_disk_full () { + sudo mdmfs -s 1M -w 1001:1001 md env && dd if=/dev/zero of=env/b bs=1024 count=700 + cmd="./jot 100 | while read N; do if ! (echo a; echo b) | $pcp -V env/v1 -k -x x; then break; fi; done" + expect="/Failed to copy/" + check "$cmd" "$expect" "$input" +} diff --git a/tests/jsonunittests.cfg b/tests/jsonunittests.cfg index d6f6f5b..06bc92b 100644 --- a/tests/jsonunittests.cfg +++ b/tests/jsonunittests.cfg @@ -24,72 +24,73 @@ pcp=../src/pcp1 passwd=xxx verbose=1 -. keys.cfg +. ./keys.cfg -check-json-support () { +check_json_support () { cmd="$pcp -V vja -t -j" expect="\"keyvaultfile\"" check "$cmd" "$expect" } -check-json-export-public () { +check_json_export_public () { cmd="$pcp -V vja -p -j -x a -O testkeyvjapub.json" expectfile="testkeyvjapub.json" expect="/\"Alicia\"/" check "$cmd" "$expect" "$input" "$expectfile" } -check-json-export-secret () { +check_json_export_secret () { cmd="$pcp -V vja -s -j -x a -O testkeyvjasec.json" expectfile="testkeyvjasec.json" check "$cmd" "$expect" "$input" "$expectfile" } -check-json-export-secret-isjson () { + +check_json_export_secret_isjson () { cmd="cat testkeyvjasec.json" expect="/\"Alicia\"/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-json-import-public () { +check_json_import_public () { cmd="$pcp -V vjb -K -I testkeyvjapub.json -j" expect="/added/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-json-import-public-open () { +check_json_import_public_open () { cmd="$pcp -V vjb -l" expect="/Alicia/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-json-import-secret () { +check_json_import_secret () { cmd="$pcp -V vjc -K -I testkeyvjasec.json -x a -j" expect="/added/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-json-import-secret-open () { +check_json_import_secret_open () { cmd="$pcp -V vjc -l" expect="/Alicia/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-json-text-vault () { +check_json_text_vault () { cmd="$pcp -V vjb -t -j" expect="/\"Alicia\"/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-json-text-public () { +check_json_text_public () { cmd="$pcp -V vjb -t -j -i ${idalicia}" expect="/\"Alicia\"/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-json-text-secret () { +check_json_text_secret () { cmd="$pcp -V vjb -t -j -i ${idbobby}" expect="/\"Bobby\"/" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } diff --git a/tests/pyunittests.cfg b/tests/pyunittests.cfg index 21fe15d..4d1e266 100644 --- a/tests/pyunittests.cfg +++ b/tests/pyunittests.cfg @@ -22,42 +22,42 @@ py=./pytest.py -py-import-keys () { +py_import_keys () { cmd="$py impkeys" expect=/ok/ } -py-encrypt-asym-armor () { +py_encrypt_asym_armor () { cmd="$py asymarmor" expect=/ok/ check "$cmd" "$expect" "$input" } -py-encrypt-asym-raw () { +py_encrypt_asym_raw () { cmd="$py asymraw" expect=/ok/ check "$cmd" "$expect" "$input" } -py-encrypt-asym-sign () { +py_encrypt_asym_sign () { cmd="$py asymsign" expect=/ok/ check "$cmd" "$expect" "$input" } -py-encrypt-asym-anon () { +py_encrypt_asym_anon () { cmd="$py asymanon" expect=/ok/ check "$cmd" "$expect" "$input" } -py-encrypt-sym-armor () { +py_encrypt_sym_armor () { cmd="$py symarmor" expect=/ok/ check "$cmd" "$expect" "$input" } -py-encrypt-sym-raw () { +py_encrypt_sym_raw () { cmd="$py symraw" expect=/ok/ check "$cmd" "$expect" "$input" diff --git a/tests/stresstests.cfg b/tests/stresstests.cfg index 4376fcb..f735855 100644 --- a/tests/stresstests.cfg +++ b/tests/stresstests.cfg @@ -1,7 +1,8 @@ +# -*-sh-*- # # This file is part of Pretty Curved Privacy (pcp1). # -# Copyright (C) 2013 T.Linden. +# Copyright (C) 2013-2016 T.v.Dein. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,31 +23,33 @@ # # stress tests -confirm = Stress tests will take some time, continue? -pcp = ../src/pcp1 -outdir = stresstest -vault = $outdir/stresstestin -pvault = $outdir/stresstestout -numkeys = 100 -verbose = 1 +confirm=Stress tests will take some time, continue? +pcp=../src/pcp1 +outdir =stresstest +vault=$outdir/stresstestin +pvault=$outdir/stresstestout +numkeys=100 +verbose=1 - - prepare = ./genmasskeys.sh $outdir $numkeys $pcp $vault +prepare () { + ./genmasskeys.sh $outdir $numkeys $pcp $vault +} - - cmd = $pcp -V $vault -l | grep 0x | wc -l - expect = $numkeys - +check_bulk_generate_keys () { + cmd=$pcp -V $vault -l | grep 0x | wc -l + expect=$numkeys +} - - prepare = ./exportmasspubs.sh $outdir $pcp $vault - cmd = ls -1 $outdir/0x* | wc -l - expect = $numkeys - +check_bulk_vault_export_publics () { + ./exportmasspubs.sh $outdir $pcp $vault + cmd="ls -1 $outdir/0x* | wc -l" + expect="$numkeys" + check "$cmd" "$expect" "$input" +} - - prepare = ./importmasspubs.sh $outdir $pcp $pvault - cmd = $pcp -V $pvault -l | grep 0x | wc -l - expect $numkeys - - +check_bulk_import_publics () { + ./importmasspubs.sh $outdir $pcp $pvault + cmd="$pcp -V $pvault -l | grep 0x | wc -l" + expect="$numkeys" + check "$cmd" "$expect" "$input" +} diff --git a/tests/unittests.cfg b/tests/unittests.cfg index ce4f605..6886d05 100644 --- a/tests/unittests.cfg +++ b/tests/unittests.cfg @@ -30,87 +30,87 @@ blake2=5baec1cad5bf54287028749d83f2bf3e3ed09f0ee38a233f35dbda1361c6a67fd824e17c8 blake2auth=d7fff04bd63004f7a2ba914d9b2ccff22827230d3c546d97ebaa29cbe9fb2380b7948bc799486d512b4355c24f0cce423e746419098d4455af91898c4a06a5df key=9U3Dk2s -. keys.cfg +. ./keys.cfg -check-dependencies-pcp () { +check_dependencies_pcp () { cmd="ls $pcp" expect="/pcp/" check "$cmd" "$expect" "$input" } -check-streams-8 () { +check_streams_8 () { md5=`./md5 ../COPYING` cmd="./pipetest 8 e < ../COPYING | ./pipetest 8 d | ./md5" expect="/$md5/" check "$cmd" "$expect" "$input" } -check-streams-16 () { +check_streams_16 () { md5=`./md5 ../COPYING` cmd="./pipetest 16 e < ../COPYING | ./pipetest 16 d | ./md5" expect="/$md5/" check "$cmd" "$expect" "$input" } -check-streams-32 () { +check_streams_32 () { md5=`./md5 ../COPYING` cmd="./pipetest 32 e < ../COPYING | ./pipetest 32 d | ./md5" expect="/$md5/" check "$cmd" "$expect" "$input" } -check-streams-64 () { +check_streams_64 () { md5=`./md5 ../COPYING` cmd="./pipetest 64 e < ../COPYING | ./pipetest 64 d | ./md5" expect="/$md5/" check "$cmd" "$expect" "$input" } -check-z85-1-compliant () { +check_z85_1_compliant () { cmd="./decodertest 1" expect="/ok/" check "$cmd" "$expect" "$input" } -check-z85-2-compliant-no-newlines () { +check_z85_2_compliant_no_newlines () { cmd="./decodertest 2" expect="/ok/" check "$cmd" "$expect" "$input" } -check-z85-3-compliant-no-begin-header () { +check_z85_3_compliant_no_begin_header () { cmd="./decodertest 3" expect="/ok/" check "$cmd" "$expect" "$input" } -check-z85-4-uncompliant-empty-comment () { +check_z85_4_uncompliant_empty_comment () { cmd="./decodertest 4" expect="/ok/" check "$cmd" "$expect" "$input" } -check-z85-5-uncompliant-missing-char () { +check_z85_5_uncompliant_missing_char () { cmd="./decodertest 5" expect="/ok/" check "$cmd" "$expect" "$input" } -check-show-help () { +check_show_help () { cmd="$pcp -h" expect="/export/" check "$cmd" "$expect" "$input" } -check-if-fail-without-vault () { +check_if_fail_without_vault () { rm -f $vault cmd="$pcp -V $vault -l" expect="/doesn.t contain any keys so far/" check "$cmd" "$expect" "$input" } -check-generate-secret-key () { +check_generate_secret_key () { cmd="$pcp -V $vault -k -x $passwd" input=$(cat <<'EOF' Dexter Morgan @@ -121,7 +121,7 @@ EOF check "$cmd" "$expect" "$input" } -check-fail-entropy-generate-secret-key () { +check_fail_entropy_generate_secret_key () { cmd="$pcp -V $vault -k -x password" input=$(cat <<'EOF' Dexter Morgan @@ -133,62 +133,62 @@ EOF check "$cmd" "$expect" "$input" } -check-if-vault-contains-secret () { +check_if_vault_contains_secret () { cmd="$pcp -V $vault -l" expect="/Dexter Morgan/" check "$cmd" "$expect" "$input" } -check-secret-key-info () { +check_secret_key_info () { cmd="$pcp -V $vault -l | tail -1 | cut -d ' ' -f 1 | xargs $pcp -V $vault -t -i" expect="/Serial Number/" check "$cmd" "$expect" "$input" } -check-export-public-key () { +check_export_public_key () { cmd="$pcp -V $vault -l | tail -1 | cut -d ' ' -f 1 | xargs $pcp -V $vault -p -x $passwd -z -i " expect="/PUBLIC KEY/" check "$cmd" "$expect" "$input" } -check-export-public-key-tofile () { +check_export_public_key_tofile () { cmd="$pcp -V $vault -l | tail -1 | cut -d ' ' -f 1 | xargs $pcp -V $vault -p -x $passwd -O testkey-self -i " expectfile="testkey-self" expect="" check "$cmd" "$expect" "$input" "$expectfile" } -check-export-public-key-filecontent () { +check_export_public_key_filecontent () { cmd="strings testkey-self" expect="Dexter" - check "$cmd" "$expect" "$input" "$expectfile" + check "$cmd" "$expect" "$input" "" } -check-import-public-key () { +check_import_public_key () { cmd="$pcp -V $vault -K -I bart.pub" expect="/key $bartid added/" check "$cmd" "$expect" "$input" } -check-imported-public-key-info () { +check_imported_public_key_info () { cmd="$pcp -V $vault -t -i $bartid" expect="/Serial Number: $bartserial/" check "$cmd" "$expect" "$input" } -check-if-delete-public-key-works () { +check_if_delete_public_key_works () { cmd="$pcp -V $vault -R -i $bartid" expect="/Public key deleted/" check "$cmd" "$expect" "$input" } -check-if-vault-still-valid () { +check_if_vault_still_valid () { cmd="$pcp -V $vault -t" expect="/Vault version: 00000002/" check "$cmd" "$expect" "$input" } -check-if-deleted-public-key-is-away () { +check_if_deleted_public_key_is_away () { cmd="$pcp -V $vault -t" expect="/Public keys: 0/" check "$cmd" "$expect" "$input" @@ -198,69 +198,69 @@ check-if-deleted-public-key-is-away () { # # encryption tests # alicias part -check-crypto-alicia-import-secret () { +check_crypto_alicia_import_secret () { cmd="$pcp -V va -K -I key-alicia-sec -x a" expect="/${idalicia}/" check "$cmd" "$expect" "$input" } -check-crypto-alicia-import-bobbys-key () { +check_crypto_alicia_import_bobbys_key () { cmd="$pcp -V va -K -I key-bobby-pub" expect="/${idbobby}/" check "$cmd" "$expect" "$input" } -check-crypto-alicia-encrypt () { +check_crypto_alicia_encrypt () { cmd="$pcp -V va -e -i ${idbobby} -I testmessage -O testencrypted -x a" expect="/${idbobby} - Bobby/" check "$cmd" "$expect" "$input" } -check-crypto-alicia-encrypt-anonymous () { +check_crypto_alicia_encrypt_anonymous () { cmd="$pcp -V va -e -A -i ${idbobby} -I testmessage -O testencryptedanon -x a" expect="/${idbobby} - Bobby/" check "$cmd" "$expect" "$input" } # bobbys part -check-crypto-bobby-import-secret () { +check_crypto_bobby_import_secret () { cmd="$pcp -V vb -K -I key-bobby-sec -x b" expect="/${idbobby}/" check "$cmd" "$expect" "$input" } -check-crypto-bobby-decrypt-anonymous () { +check_crypto_bobby_decrypt_anonymous () { # decrypt anon, without knowing alicias key cmd="$pcp -V vb -d -O testdecryptedanon -I testencryptedanon -x b" expect="/successfully/" check "$cmd" "$expect" "$input" } -check-crypto-alicia-import-alicias-key () { +check_crypto_alicia_import_alicias_key () { cmd="$pcp -V vb -K -I key-alicia-pub" expect="/${idalicia}/" check "$cmd" "$expect" "$input" } -check-crypto-bobby-decrypt () { +check_crypto_bobby_decrypt () { cmd="$pcp -V vb -d -O testdecrypted -I testencrypted -x b" expect="/successfully/" check "$cmd" "$expect" "$input" } -check-crypto-alicia-encrypted-file () { +check_crypto_alicia_encrypted_file () { cmd="cat testdecrypted" expect="/${md5msg}/" check "$cmd" "$expect" "$input" } -check-crypto-alicia-encrypt-self () { +check_crypto_alicia_encrypt_self () { cmd="$pcp -V va -e -M -I testmessage -O testencryptedself -x a" expect="/Alicia/" check "$cmd" "$expect" "$input" } -check-crypto-alicia-deencrypt-self () { +check_crypto_alicia_deencrypt_self () { cmd="$pcp -V va -d -I testencryptedself -O testdecrypted -x a" expect="/successfully/" check "$cmd" "$expect" "$input" @@ -268,13 +268,13 @@ check-crypto-alicia-deencrypt-self () { # # symetric encryption test -check-sym-encrypt () { +check_sym_encrypt () { cmd="echo HELLOWORLD | $pcp -e -O testsymencrypted -x a" expect="/symetrically/" check "$cmd" "$expect" "$input" } -check-sym-decrypt () { +check_sym_decrypt () { cmd="$pcp -d -I testsymencrypted -x a" expect="/HELLO/" check "$cmd" "$expect" "$input" @@ -283,26 +283,26 @@ check-sym-decrypt () { # # signature tests -check-sign-detached-to-bobby () { +check_sign_detached_to_bobby () { cmd="$pcp -V va -g -I README -f testsig -x a" expectfile="testsig" expect="" check "$cmd" "$expect" "$input" "$expectfile" } -check-verify-detached-signature () { +check_verify_detached_signature () { cmd="$pcp -V vb -c -f testsig -I README -i $idalicia" expect="/verified/" check "$cmd" "$expect" "$input" } -check-verify-detached-signature-self () { +check_verify_detached_signature_self () { cmd="$pcp -V va -c -f testsig -I README" expect="/verified/" check "$cmd" "$expect" "$input" } -check-sign-armored-to-bobby () { +check_sign_armored_to_bobby () { rm -f testsig cmd="$pcp -V va -g -I README -O testsig -x a -z" expectfile="testsig" @@ -310,19 +310,19 @@ check-sign-armored-to-bobby () { check "$cmd" "$expect" "$input" "$expectfile" } -check-verify-armored-signature () { +check_verify_armored_signature () { cmd="$pcp -V vb -c -I testsig -i $idalicia -z" expect="/verified/" check "$cmd" "$expect" "$input" } -check-verify-armored-signature-self () { +check_verify_armored_signature_self () { cmd="$pcp -V va -c -I testsig -z" expect="/verified/" check "$cmd" "$expect" "$input" } -check-sign-bin-to-bobby () { +check_sign_bin_to_bobby () { rm -f testsig cmd="$pcp -V va -g -I README -O testsig -x a" expectfile="testsig" @@ -330,13 +330,13 @@ check-sign-bin-to-bobby () { check "$cmd" "$expect" "$input" "$expectfile" } -check-verify-bin-signature () { +check_verify_bin_signature () { cmd="$pcp -V vb -c -I testsig -i $idalicia" expect="/verified/" check "$cmd" "$expect" "$input" } -check-verify-bin-signature-self () { +check_verify_bin_signature_self () { cmd="$pcp -V va -c -I testsig " expect="/verified/" check "$cmd" "$expect" "$input" @@ -344,19 +344,19 @@ check-verify-bin-signature-self () { # # sign+encrypt tests -check-sign-crypt-to-bobby () { +check_sign_crypt_to_bobby () { cmd="$pcp -V va -g -e -I README -O testsig -r Bobby -x a" expect="/Encrypted/" check "$cmd" "$expect" "$input" } -check-verify-decrypt-from-alicia () { +check_verify_decrypt_from_alicia () { cmd="$pcp -V vb -c -d -I testsig -x b" expect="/Verified/" check "$cmd" "$expect" "$input" } -check-verify-decrypt-from-alicia-determine () { +check_verify_decrypt_from_alicia_determine () { cmd="$pcp -V vb -d -I testsig -x b" expect="/Verified/" check "$cmd" "$expect" "$input" @@ -364,7 +364,7 @@ check-verify-decrypt-from-alicia-determine () { # # raw C test with prepared keys, message and cipher -check-raw-decrypt () { +check_raw_decrypt () { cmd="./statictest" expect="/ok/" check "$cmd" "$expect" "$input" @@ -373,159 +373,159 @@ check-raw-decrypt () { # # negative tests, check for error handling -check-if-catch-conflicting-params () { +check_if_catch_conflicting_params () { cmd="$pcp -V $vault -K -K" expect="/invalid combination of commandline parameters/" check "$cmd" "$expect" "$input" } -check-infile-error () { +check_infile_error () { cmd="$pcp -V $vault -I nonexist -K" expect="/Could not open input file nonexist/" check "$cmd" "$expect" "$input" } -check-import-without-id-error () { +check_import_without_id_error () { cmd="$pcp -V $vault -R" expect="/You need to specify a key id/" check "$cmd" "$expect" "$input" } -check-catch-invalid-short-keyid () { +check_catch_invalid_short_keyid () { cmd="$pcp -V $vault -R -i 0x1" expect="/is too short/" check "$cmd" "$expect" "$input" } -check-catch-invalid-long-keyid () { +check_catch_invalid_long_keyid () { cmd="$pcp -V $vault -R -i 0x1111111111111111111111111" expect="/is too long/" check "$cmd" "$expect" "$input" } -check-catch-invalid-long-keyid-without-0x () { +check_catch_invalid_long_keyid_without_0x () { cmd="$pcp -V $vault -R -i 11111111111111111" expect="/is too long/" check "$cmd" "$expect" "$input" } -check-catch-delete-nonexist () { +check_catch_delete_nonexist () { cmd="$pcp -V $vault -R -i 0x0101010101010101" expect="/No key with id 0x010101/" check "$cmd" "$expect" "$input" } -check-if-export-secret-catch-nonexistent-keyid () { +check_if_export_secret_catch_nonexistent_keyid () { cmd="$pcp -V $vault -s -i 0x0101010101010101" expect="/Could not find a secret key with id 0x010101/" check "$cmd" "$expect" "$input" } -check-if-export-secret-catch-no-primary () { +check_if_export_secret_catch_no_primary () { $pcp -V v2 -l # so we've got just an empty vault cmd="$pcp -V v2 -s" expect="/no primary secret key in the vault/" check "$cmd" "$expect" "$input" } -check-if-export-secret-catch-outfile-error () { +check_if_export_secret_catch_outfile_error () { cmd=" $pcp -V $vault -l | grep primary |cut -d ' ' -f 1 | xargs $pcp -V $vault -s -O nonexistentdir/keyfile -i" expect="/Could not create output file nonexistentdir/" check "$cmd" "$expect" "$input" } -check-if-export-public-catch-nonexistent-keyid () { +check_if_export_public_catch_nonexistent_keyid () { cmd="$pcp -V $vault -p -i 0x0101010101010101" expect="/Could not find a key with id 0x010101/" check "$cmd" "$expect" "$input" } -check-if-export-public-catch-no-primary () { +check_if_export_public_catch_no_primary () { $pcp -V v3 -l # so we've got just an empty vault cmd="$pcp -V v3 -p" expect="/no primary secret key in the vault/" check "$cmd" "$expect" "$input" } -check-if-export-public-catch-outfile-error () { +check_if_export_public_catch_outfile_error () { $pcp -V $vault -K -I bart.pub cmd="$pcp -V $vault -l | grep public | cut -d ' ' -f 1 | tail -1 | xargs $pcp -V $vault -p -O nonexistentdir/keyfile" expect="/Could not create output file nonexistentdir/" check "$cmd" "$expect" "$input" } -check-if-catch-empty-input () { +check_if_catch_empty_input () { touch testfile-empty cmd="$pcp -V $vault -K -I testfile-empty" expect="/file is empty/" check "$cmd" "$expect" "$input" } -check-if-catch-missing-newlines () { +check_if_catch_missing_newlines () { perl -e 'print "X" x 5000; print "\n"' > testfile-toolong cmd="$pcp -V $vault -K -I testfile-toolong -x x" expect="/failed/" check "$cmd" "$expect" "$input" } -check-if-catch-nokey-behind-z85 () { +check_if_catch_nokey_behind_z85 () { ./jot 30 | while read ignore; do echo XXXXX; done | $pcp -z > testfile-nokey cmd="$pcp -V $vault -K -I testfile-nokey -x x" expect="/failed/" check "$cmd" "$expect" "$input" } -check-if-sanity-catch-keyexists () { +check_if_sanity_catch_keyexists () { cmd="$pcp -V $vault -K -I bart.pub" expect="/there already exists a key/" check "$cmd" "$expect" "$input" } -check-if-catch-nokeys () { +check_if_catch_nokeys () { $pcp -V v3 -l cmd="$pcp -V v3 -l" expect="/contain any keys so far/" check "$cmd" "$expect" "$input" } -check-testkey-wrong-version () { +check_testkey_wrong_version () { cmd="$pcp -V $vault -K -I testkey-wrong-version -x xxx" expect="/unknown key version/" check "$cmd" "$expect" "$input" } -check-testkey-wrong-serial () { +check_testkey_wrong_serial () { cmd="$pcp -V $vault -K -I testkey-wrong-serial -x xxx" expect="/invalid serial number/" check "$cmd" "$expect" "$input" } -check-testkey-wrong-ctime () { +check_testkey_wrong_ctime () { cmd="$pcp -V $vault -K -I testkey-invalid-ctime -x xxx" expect="/invalid creation timestamp/" check "$cmd" "$expect" "$input" } -check-vault-invalid-header () { +check_vault_invalid_header () { cmd="$pcp -V testvault-invalidheader -l" expect="/Unexpected vault file format/" check "$cmd" "$expect" "$input" } -check-vault-invalid-version () { +check_vault_invalid_version () { cmd="$pcp -V testvault-invalidversion -l" expect="/Unexpected vault file format/" check "$cmd" "$expect" "$input" } -check-vault-invalid-itemtype () { +check_vault_invalid_itemtype () { cmd="$pcp -V testvault-invaliditemtype -l" expect="/invalid key type/" check "$cmd" "$expect" "$input" } -check-vault-invalid-keytype () { +check_vault_invalid_keytype () { cmd="$pcp -V testvault-invalidkeytype -l" expect="/contain any keys so far./" check "$cmd" "$expect" "$input" @@ -534,7 +534,7 @@ check-vault-invalid-keytype () { # # input handling tests -check-large-meta () { +check_large_meta () { cmd="(./jot 300 | while read m; do echo -n m; done; echo $passwd) | $pcp -V $vault -k -x $passwd" expect="/Generated new secret key/" check "$cmd" "$expect" "$input" @@ -542,7 +542,7 @@ check-large-meta () { # # fuzz tests -check-fuzz-binary-pubkey () { +check_fuzz_binary_pubkey () { expect="!/added/" cmd="echo no | $pcp -V vf -K -I testfuzzP.pub -x $passwd" @@ -556,7 +556,7 @@ check-fuzz-binary-pubkey () { done } -check-fuzz-binary-seckey () { +check_fuzz_binary_seckey () { cmd="echo no | $pcp -V vf -K -I testfuzzS.sec -x $passwd" expect="!/added/" for N in `./jot 30`; do @@ -571,25 +571,25 @@ check-fuzz-binary-seckey () { # checksum tests -check-checksum-copying () { +check_checksum_copying () { cmd="$pcp -C ../COPYING" expect="/$blake2/" check "$cmd" "$expect" "$input" } -check-checksum-authenticated-copying () { +check_checksum_authenticated_copying () { cmd="$pcp -x $key -C ../COPYING" expect="/$blake2auth/" check "$cmd" "$expect" "$input" } -check-checksum-copying-stdin () { +check_checksum_copying_stdin () { cmd="$pcp -C < ../COPYING" expect="/$blake2/" check "$cmd" "$expect" "$input" } -check-checksum-multiple () { +check_checksum_multiple () { cmd="$pcp -C ../COPYING ../README" expect="/README/" check "$cmd" "$expect" "$input" diff --git a/tests/unittests.sh b/tests/unittests.sh index 587f972..1d54e07 100755 --- a/tests/unittests.sh +++ b/tests/unittests.sh @@ -1,24 +1,24 @@ #!/bin/sh errout () { - log="$1" + logout="$1" expect="$2" echo " EXPECTED: $expect" echo -n " GOT: " - cat $log | head -1 - cat $log | tail +2 | sed 's/^/ /' + cat $logout | head -1 + cat $logout | tail -n +2 | sed 's/^/ /' } lookup () { - log="$1" + logfile="$1" expect="$2" if echo "$expect" | grep '!' > /dev/null 2>&2; then # negate expect=`echo "$expect" | sed -e 's/^\!//' -e 's#^/##' -e 's#/$##'` - if cat $log | grep "$expect" > /dev/null 2>&1; then - errout "$log" "NOT $expect" + if cat $logfile | grep -i "$expect" > /dev/null 2>&1; then + errout "$logfile" "NOT $expect" return 1 else echo " OK" @@ -26,11 +26,11 @@ lookup () { fi else expect=`echo "$expect" | sed -e 's#^/##' -e 's#/$##'` - if cat $log | grep "$expect" > /dev/null 2>&1; then + if cat $logfile | grep -i "$expect" > /dev/null 2>&1; then echo " OK" return 0 else - errout "$log" "$expect" + errout "$logfile" "$expect" return 1 fi fi @@ -52,7 +52,7 @@ check() { # ignore result, check output file if test -n "$expect"; then # look for string in output - if ! lookup "$log" "$expect"; then + if ! lookup "$file" "$expect"; then fail=y fi else @@ -116,16 +116,16 @@ if ! test -e "$cfg"; then exit 1 fi -. $cfg +. ./$cfg -count=`grep -E -- "^check-" "$cfg" | wc -l` +count=`grep -E -- "^check_" "$cfg" | wc -l` callcheck prepare if test -n "$check"; then callcheck $check else - for F in `grep -E -- "^check-" "$cfg" | cut -d' ' -f1`; do + for F in `grep -E -- "^check_" "$cfg" | cut -d' ' -f1`; do callcheck $F done echo "All Tests OK"