diff --git a/tests/Makefile.am b/tests/Makefile.am index 23dfa90..59b53d4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -94,17 +94,17 @@ test: check ctest $(MAYPY) $(MAYCPP) $(MAYJSON) ctest: rm -f test* v* stresstest/* - ./unittests.pl unittests.cfg $(CHECK) + ./unittests.sh unittests.cfg $(CHECK) @echo "To run a single test only, type: 'make test CHECK=testname'" pytest: - ./unittests.pl pyunittests.cfg $(CHECK) + ./unittests.sh pyunittests.cfg $(CHECK) docpptest: - ./unittests.pl cppunittests.cfg $(CHECK) + ./unittests.sh cppunittests.cfg $(CHECK) jsontest: - ./unittests.pl jsonunittests.cfg $(CHECK) + ./unittests.sh jsonunittests.cfg $(CHECK) stresstest: check ./unittests.pl stresstests.cfg diff --git a/tests/cppunittests.cfg b/tests/cppunittests.cfg index 37612de..9d62593 100644 --- a/tests/cppunittests.cfg +++ b/tests/cppunittests.cfg @@ -1,26 +1,37 @@ +# -*-sh-*- # # test the c++ api - - cmd = ./cpptest 0 - expect = /ok/ - - - cmd = ./cpptest 1 - expect = /ok/ - +check-cpp-crypto () { + cmd="./cpptest 0" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = ./cpptest 2 - expect = /ok/ - +check-cpp-vault () { + cmd="./cpptest 1" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = ./cpptest 3 - expect = /ok/ - +check-cpp-import-pub () { + cmd="./cpptest 2" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = ./cpptest 4 - expect = /ok/ - +check-cpp-signature () { + cmd="./cpptest 3" + expect=/ok/ + check "$cmd" "$expect" "$input" +} + +check-buffer () { + cmd="./cpptest 4" + expect=/ok/ + check "$cmd" "$expect" "$input" +} + +prepare () { + : +} diff --git a/tests/gentestkeys.sh b/tests/gentestkeys.sh index ac65d84..e2f6a34 100755 --- a/tests/gentestkeys.sh +++ b/tests/gentestkeys.sh @@ -43,12 +43,12 @@ $pcp1 -V unknown3 -l echo hallo | $pcp -e -x a -z | egrep -v "^ " | egrep -v -- "----" | grep . > unknown4 echo blah | $pcp -V vxxxBart -g -x a | egrep -v "^ " | egrep -v -- "----" | grep . > unknown5 -echo "bartid = $ids -bartserial = $ser -idbobby = $idb -idalicia = $ida -mailbobby = bobby@local -mailalicia = alicia@local" > keys.cfg +echo "bartid=$ids +bartserial=$ser +idbobby=$idb +idalicia=$ida +mailbobby=bobby@local +mailalicia=alicia@local" > keys.cfg ./gencheader > static.h diff --git a/tests/jsonunittests.cfg b/tests/jsonunittests.cfg index 22575c1..d6f6f5b 100644 --- a/tests/jsonunittests.cfg +++ b/tests/jsonunittests.cfg @@ -1,4 +1,4 @@ -# -*-html-*- +# -*-sh-*- # # This file is part of Pretty Curved Privacy (pcp1). # @@ -20,66 +20,81 @@ # You can contact me by mail: . # -pcp = ../src/pcp1 -passwd = xxx -verbose = 1 -include keys.cfg +pcp=../src/pcp1 +passwd=xxx +verbose=1 - - prepare = rm -f vja; $pcp -V vja -K -I key-alicia-sec -x a - - cmd = $pcp -V vja -p -j -x a -O testkeyvjapub.json - expect-file testkeyvjapub.json - - - cmd = cat testkeyvjapub.json - expect = /"Alicia"/ - - - cmd = $pcp -V vja -s -j -x a -O testkeyvjasec.json - expect-file testkeyvjasec.json - - - cmd = cat testkeyvjasec.json - expect = /"Alicia"/ - - +. keys.cfg - - prepare = rm -f vjb; $pcp -V vjb -K -I key-bobby-sec -x b - - cmd = $pcp -V vjb -K -I testkeyvjapub.json -j - expect /added/ - - - cmd = $pcp -V vjb -l - expect = /Alicia/ - - +check-json-support () { + cmd="$pcp -V vja -t -j" + expect="\"keyvaultfile\"" + check "$cmd" "$expect" +} - - prepare = rm -f vjc - - cmd = $pcp -V vjc -K -I testkeyvjasec.json -x a -j - expect = /added/ - - - cmd = $pcp -V vjc -l - expect = /Alicia/ - - +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" +} - - - cmd = $pcp -V vjb -t -j - expect = /"Alicia"/ - - - cmd = $pcp -V vjb -t -j -i ${idalicia} - expect = /"Alicia"/ - - - cmd = $pcp -V vjb -t -j -i ${idbobby} - expect = /"Bobby"/ - - +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 () { + cmd="cat testkeyvjasec.json" + expect="/\"Alicia\"/" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-json-import-public () { + cmd="$pcp -V vjb -K -I testkeyvjapub.json -j" + expect="/added/" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-json-import-public-open () { + cmd="$pcp -V vjb -l" + expect="/Alicia/" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-json-import-secret () { + cmd="$pcp -V vjc -K -I testkeyvjasec.json -x a -j" + expect="/added/" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-json-import-secret-open () { + cmd="$pcp -V vjc -l" + expect="/Alicia/" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-json-text-vault () { + cmd="$pcp -V vjb -t -j" + expect="/\"Alicia\"/" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-json-text-public () { + cmd="$pcp -V vjb -t -j -i ${idalicia}" + expect="/\"Alicia\"/" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-json-text-secret () { + cmd="$pcp -V vjb -t -j -i ${idbobby}" + expect="/\"Bobby\"/" + check "$cmd" "$expect" "$input" "$expectfile" +} + + +prepare () { + rm -f vja; $pcp -V vja -K -I key-alicia-sec -x a + rm -f vjb; $pcp -V vjb -K -I key-bobby-sec -x b + rm -f vjc +} diff --git a/tests/pyunittests.cfg b/tests/pyunittests.cfg index 06a92d4..21fe15d 100644 --- a/tests/pyunittests.cfg +++ b/tests/pyunittests.cfg @@ -1,3 +1,4 @@ +# -*-sh-*- # # This file is part of Pretty Curved Privacy (pcp1). # @@ -19,40 +20,49 @@ # You can contact me by mail: . # -py = ./pytest.py +py=./pytest.py - - cmd = $py impkeys - expect = /ok/ - +py-import-keys () { + cmd="$py impkeys" + expect=/ok/ +} +py-encrypt-asym-armor () { + cmd="$py asymarmor" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = $py asymarmor - expect = /ok/ - +py-encrypt-asym-raw () { + cmd="$py asymraw" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = $py asymraw - expect = /ok/ - +py-encrypt-asym-sign () { + cmd="$py asymsign" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = $py asymsign - expect = /ok/ - +py-encrypt-asym-anon () { + cmd="$py asymanon" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = $py asymanon - expect = /ok/ - +py-encrypt-sym-armor () { + cmd="$py symarmor" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = $py symarmor - expect = /ok/ - +py-encrypt-sym-raw () { + cmd="$py symraw" + expect=/ok/ + check "$cmd" "$expect" "$input" +} - - cmd = $py symraw - expect = /ok/ - \ No newline at end of file +prepare () { + : +} diff --git a/tests/unittests.cfg b/tests/unittests.cfg index d744bb6..ce4f605 100644 --- a/tests/unittests.cfg +++ b/tests/unittests.cfg @@ -1,4 +1,4 @@ -# -*-html-*- +# -*-sh-*- # # This file is part of Pretty Curved Privacy (pcp1). # @@ -20,547 +20,587 @@ # You can contact me by mail: . # -pcp = ../src/pcp1 -vault = v1 -passwd = ech9xeiT%CuxuH1ch-is2ies1R -md5msg = 66b8c4ca9e5d2a7e3c0559c3cdea3d50 -mangle = ./mangle -verbose = 1 -include keys.cfg +pcp=../src/pcp1 +vault=v1 +passwd=ech9xeiT%CuxuH1ch-is2ies1R +md5msg=66b8c4ca9e5d2a7e3c0559c3cdea3d50 +mangle=./mangle +verbose=1 +blake2=5baec1cad5bf54287028749d83f2bf3e3ed09f0ee38a233f35dbda1361c6a67fd824e17c86ee3a85181038eb44836c17c42e6beff17fdf997075417914056992 +blake2auth=d7fff04bd63004f7a2ba914d9b2ccff22827230d3c546d97ebaa29cbe9fb2380b7948bc799486d512b4355c24f0cce423e746419098d4455af91898c4a06a5df +key=9U3Dk2s - - - cmd = ls $pcp - expect = /pcp/ - - +. keys.cfg - - - md5 = `./md5 ../COPYING` - cmd = ./pipetest 8 e < ../COPYING | ./pipetest 8 d | ./md5 - expect = /$md5/ - - - md5 = `./md5 ../COPYING` - cmd = ./pipetest 16 e < ../COPYING | ./pipetest 16 d | ./md5 - expect = /$md5/ - - - md5 = `./md5 ../COPYING` - cmd = ./pipetest 32 e < ../COPYING | ./pipetest 32 d | ./md5 - expect = /$md5/ - - - md5 = `./md5 ../COPYING` - cmd = ./pipetest 64 e < ../COPYING | ./pipetest 64 d | ./md5 - expect = /$md5/ - - +check-dependencies-pcp () { + cmd="ls $pcp" + expect="/pcp/" + check "$cmd" "$expect" "$input" +} - - - cmd = ./decodertest 1 - expect = /ok/ - +check-streams-8 () { + md5=`./md5 ../COPYING` + cmd="./pipetest 8 e < ../COPYING | ./pipetest 8 d | ./md5" + expect="/$md5/" + check "$cmd" "$expect" "$input" +} - - cmd = ./decodertest 2 - expect = /ok/ - +check-streams-16 () { + md5=`./md5 ../COPYING` + cmd="./pipetest 16 e < ../COPYING | ./pipetest 16 d | ./md5" + expect="/$md5/" + check "$cmd" "$expect" "$input" +} - - cmd = ./decodertest 3 - expect = /ok/ - +check-streams-32 () { + md5=`./md5 ../COPYING` + cmd="./pipetest 32 e < ../COPYING | ./pipetest 32 d | ./md5" + expect="/$md5/" + check "$cmd" "$expect" "$input" +} - - cmd = ./decodertest 4 - expect = /ok/ - +check-streams-64 () { + md5=`./md5 ../COPYING` + cmd="./pipetest 64 e < ../COPYING | ./pipetest 64 d | ./md5" + expect="/$md5/" + check "$cmd" "$expect" "$input" +} - - cmd = ./decodertest 5 - expect = /ok/ - - +check-z85-1-compliant () { + cmd="./decodertest 1" + expect="/ok/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -h - expect = /export/ - +check-z85-2-compliant-no-newlines () { + cmd="./decodertest 2" + expect="/ok/" + check "$cmd" "$expect" "$input" +} - - prepare = rm -f $vault - cmd = $pcp -V $vault -l - expect = /doesn't contain any keys so far/ - +check-z85-3-compliant-no-begin-header () { + cmd="./decodertest 3" + expect="/ok/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -k -x $passwd - input = < +EOF +) + expect="/Generated new secret key/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -k -x password - input = < +EOF +) + expect="/weak passphrase/" + check "$cmd" "$expect" "$input" +} +check-if-vault-contains-secret () { + cmd="$pcp -V $vault -l" + expect="/Dexter Morgan/" + check "$cmd" "$expect" "$input" +} +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" +} - - cmd = $pcp -V $vault -l - expect = /Dexter Morgan/ - +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" +} - - cmd = $pcp -V $vault -l | tail -1 | cut -d ' ' -f 1 | xargs $pcp -V $vault -t -i - expect = /Serial Number/ - +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" +} - - cmd = $pcp -V $vault -l | tail -1 | cut -d ' ' -f 1 | xargs $pcp -V $vault -p -x $passwd -z -i - expect = /PUBLIC KEY/ - +check-export-public-key-filecontent () { + cmd="strings testkey-self" + expect="Dexter" + check "$cmd" "$expect" "$input" "$expectfile" +} - - cmd = $pcp -V $vault -l | tail -1 | cut -d ' ' -f 1 | xargs $pcp -V $vault -p -x $passwd -O testkey-self -i - expect-file = testkey-self - +check-import-public-key () { + cmd="$pcp -V $vault -K -I bart.pub" + expect="/key $bartid added/" + check "$cmd" "$expect" "$input" +} - - cmd = true # file is already there - expect-file-contains = testkey-self Dexter - +check-imported-public-key-info () { + cmd="$pcp -V $vault -t -i $bartid" + expect="/Serial Number: $bartserial/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -K -I bart.pub - expect = /key $bartid added/ - +check-if-delete-public-key-works () { + cmd="$pcp -V $vault -R -i $bartid" + expect="/Public key deleted/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -t -i $bartid - expect = /Serial Number: $bartserial/ - +check-if-vault-still-valid () { + cmd="$pcp -V $vault -t" + expect="/Vault version: 00000002/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -R -i $bartid - expect = /Public key deleted/ - +check-if-deleted-public-key-is-away () { + cmd="$pcp -V $vault -t" + expect="/Public keys: 0/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -t - expect = /Vault version: 00000002/ - - - - cmd = $pcp -V $vault -t - expect = /Public keys: 0/ - - - -# -# test file determination -/* doesnt work currently, disabled. - - cmd = $pcp -t -I unknown1 - expect = /Niemand/ - - - - cmd = $pcp -t -I unknown2 - expect = /secret key/ - -*/ - - cmd = $pcp -t -I unknown3 - expect = /empty/ - -/* -temporarily disabled - - cmd = $pcp -t -I unknown4 - expect = /encrypted/ - -*/ # # encryption tests - - # alicias part - prepare = echo ${md5msg} > testmessage - - cmd = $pcp -V va -K -I key-alicia-sec -x a - expect = /${idalicia}/ - +# alicias part +check-crypto-alicia-import-secret () { + cmd="$pcp -V va -K -I key-alicia-sec -x a" + expect="/${idalicia}/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V va -K -I key-bobby-pub - expect = /${idbobby}/ - +check-crypto-alicia-import-bobbys-key () { + cmd="$pcp -V va -K -I key-bobby-pub" + expect="/${idbobby}/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V va -e -i ${idbobby} -I testmessage -O testencrypted -x a - expect = /${idbobby} - Bobby/ - +check-crypto-alicia-encrypt () { + cmd="$pcp -V va -e -i ${idbobby} -I testmessage -O testencrypted -x a" + expect="/${idbobby} - Bobby/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V va -e -A -i ${idbobby} -I testmessage -O testencryptedanon -x a - expect = /${idbobby} - Bobby/ - +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 - - cmd = $pcp -V vb -K -I key-bobby-sec -x b - expect = /${idbobby}/ - +# bobbys part +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 () { # decrypt anon, without knowing alicias key - cmd = $pcp -V vb -d -O testdecryptedanon -I testencryptedanon -x b - expect = /successfully/ - + cmd="$pcp -V vb -d -O testdecryptedanon -I testencryptedanon -x b" + expect="/successfully/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V vb -K -I key-alicia-pub - expect = /${idalicia}/ - +check-crypto-alicia-import-alicias-key () { + cmd="$pcp -V vb -K -I key-alicia-pub" + expect="/${idalicia}/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V vb -d -O testdecrypted -I testencrypted -x b - expect = /successfully/ - +check-crypto-bobby-decrypt () { + cmd="$pcp -V vb -d -O testdecrypted -I testencrypted -x b" + expect="/successfully/" + check "$cmd" "$expect" "$input" +} - - cmd = cat testdecrypted - expect = /${md5msg}/ - +check-crypto-alicia-encrypted-file () { + cmd="cat testdecrypted" + expect="/${md5msg}/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V va -e -M -I testmessage -O testencryptedself -x a - expect = /Alicia/ - +check-crypto-alicia-encrypt-self () { + cmd="$pcp -V va -e -M -I testmessage -O testencryptedself -x a" + expect="/Alicia/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V va -d -I testencryptedself -O testdecrypted -x a - expect = /successfully/ - - +check-crypto-alicia-deencrypt-self () { + cmd="$pcp -V va -d -I testencryptedself -O testdecrypted -x a" + expect="/successfully/" + check "$cmd" "$expect" "$input" +} # # symetric encryption test - - cmd = echo HELLOWORLD | $pcp -e -O testsymencrypted -x a - expect = /symetrically/ - - - cmd = $pcp -d -I testsymencrypted -x a - expect = /HELLO/ - +check-sym-encrypt () { + cmd="echo HELLOWORLD | $pcp -e -O testsymencrypted -x a" + expect="/symetrically/" + check "$cmd" "$expect" "$input" +} + +check-sym-decrypt () { + cmd="$pcp -d -I testsymencrypted -x a" + expect="/HELLO/" + check "$cmd" "$expect" "$input" +} # # signature tests - - cmd = $pcp -V va -g -I README -f testsig -x a - expect-file testsig - - - cmd = $pcp -V vb -c -f testsig -I README -i $idalicia - expect = /verified/ - - - cmd = $pcp -V va -c -f testsig -I README - expect = /verified/ - - - prepare = rm -f testsig - cmd = $pcp -V va -g -I README -O testsig -x a -z - expect-file testsig - - - cmd = $pcp -V vb -c -I testsig -i $idalicia -z - expect = /verified/ - - - cmd = $pcp -V va -c -I testsig -z - expect = /verified/ - - - prepare = rm -f testsig - cmd = $pcp -V va -g -I README -O testsig -x a - expect-file testsig - - - cmd = $pcp -V vb -c -I testsig -i $idalicia - expect = /verified/ - - - cmd = $pcp -V va -c -I testsig - expect = /verified/ - +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 () { + cmd="$pcp -V vb -c -f testsig -I README -i $idalicia" + expect="/verified/" + check "$cmd" "$expect" "$input" +} + +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 () { + rm -f testsig + cmd="$pcp -V va -g -I README -O testsig -x a -z" + expectfile="testsig" + expect="" + check "$cmd" "$expect" "$input" "$expectfile" +} + +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 () { + cmd="$pcp -V va -c -I testsig -z" + expect="/verified/" + check "$cmd" "$expect" "$input" +} + +check-sign-bin-to-bobby () { + rm -f testsig + cmd="$pcp -V va -g -I README -O testsig -x a" + expectfile="testsig" + expect="" + check "$cmd" "$expect" "$input" "$expectfile" +} + +check-verify-bin-signature () { + cmd="$pcp -V vb -c -I testsig -i $idalicia" + expect="/verified/" + check "$cmd" "$expect" "$input" +} + +check-verify-bin-signature-self () { + cmd="$pcp -V va -c -I testsig " + expect="/verified/" + check "$cmd" "$expect" "$input" +} # # sign+encrypt tests - - cmd = $pcp -V va -g -e -I README -O testsig -r Bobby -x a - expect = /Encrypted/ - - - cmd = $pcp -V vb -c -d -I testsig -x b - expect = /Verified/s - - - cmd = $pcp -V vb -d -I testsig -x b - expect = /Verified/s - +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 () { + cmd="$pcp -V vb -c -d -I testsig -x b" + expect="/Verified/" + check "$cmd" "$expect" "$input" +} + +check-verify-decrypt-from-alicia-determine () { + cmd="$pcp -V vb -d -I testsig -x b" + expect="/Verified/" + check "$cmd" "$expect" "$input" +} # # raw C test with prepared keys, message and cipher - - cmd = ./statictest - expect = /ok/ - +check-raw-decrypt () { + cmd="./statictest" + expect="/ok/" + check "$cmd" "$expect" "$input" +} # # negative tests, check for error handling - - cmd = $pcp -V $vault -K -K - expect = /invalid combination of commandline parameters/ - +check-if-catch-conflicting-params () { + cmd="$pcp -V $vault -K -K" + expect="/invalid combination of commandline parameters/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -I nonexist -K - expect = /Could not open input file nonexist/ - +check-infile-error () { + cmd="$pcp -V $vault -I nonexist -K" + expect="/Could not open input file nonexist/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -R - expect = /You need to specify a key id/ - +check-import-without-id-error () { + cmd="$pcp -V $vault -R" + expect="/You need to specify a key id/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -R -i 0x1 - expect = /is too short/ - +check-catch-invalid-short-keyid () { + cmd="$pcp -V $vault -R -i 0x1" + expect="/is too short/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -R -i 0x1111111111111111111111111 - expect = /is too long/ - +check-catch-invalid-long-keyid () { + cmd="$pcp -V $vault -R -i 0x1111111111111111111111111" + expect="/is too long/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -R -i 11111111111111111 - expect = /is too long/ - +check-catch-invalid-long-keyid-without-0x () { + cmd="$pcp -V $vault -R -i 11111111111111111" + expect="/is too long/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -R -i 0x0101010101010101 - expect = /No key with id 0x010101/ - +check-catch-delete-nonexist () { + cmd="$pcp -V $vault -R -i 0x0101010101010101" + expect="/No key with id 0x010101/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -s -i 0x0101010101010101 - expect = /Could not find a secret key with id 0x010101/ - +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" +} - - prepare = $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-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" +} - - 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-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" +} - - cmd = $pcp -V $vault -p -i 0x0101010101010101 - expect = /Could not find a key with id 0x010101/ - +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" +} - - prepare = $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-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" +} - - prepare = $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-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" +} - - prepare = touch testfile-empty - cmd = $pcp -V $vault -K -I testfile-empty - expect = /file is empty/ - +check-if-catch-empty-input () { + touch testfile-empty + cmd="$pcp -V $vault -K -I testfile-empty" + expect="/file is empty/" + check "$cmd" "$expect" "$input" +} - - prepare = perl -e 'print "X" x 5000; print "\n"' > testfile-toolong - cmd = $pcp -V $vault -K -I testfile-toolong -x x - expect = /failed/ - +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" +} -/* - * Currently disabled, because ZeroMQ's zmq_z85_decode() doesn't really - * catch invalid z85, it only checks the input length and not the actual - * encoding. Re-enable, once that bug is fixed. - - prepare = ./jot 30 | while read ignore; do \ - echo XXXXXXXXXXXXXXXXXX; done > testfile-noz85 - cmd = $pcp -V $vault -K -I testfile-noz85 - expect = /could not decode input/ - -*/ +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" +} - - prepare = ./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-if-sanity-catch-keyexists () { + cmd="$pcp -V $vault -K -I bart.pub" + expect="/there already exists a key/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -K -I bart.pub - expect = /there already exists a key/ - +check-if-catch-nokeys () { + $pcp -V v3 -l + cmd="$pcp -V v3 -l" + expect="/contain any keys so far/" + check "$cmd" "$expect" "$input" +} - - prepare = $pcp -V v3 -l - cmd = $pcp -V v3 -l - expect = /contain any keys so far/ - +check-testkey-wrong-version () { + cmd="$pcp -V $vault -K -I testkey-wrong-version -x xxx" + expect="/unknown key version/" + check "$cmd" "$expect" "$input" +} - - prepare = ./invalidkeys +check-testkey-wrong-serial () { + cmd="$pcp -V $vault -K -I testkey-wrong-serial -x xxx" + expect="/invalid serial number/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -K -I testkey-wrong-version -x xxx - expect = /unknown key version/ - +check-testkey-wrong-ctime () { + cmd="$pcp -V $vault -K -I testkey-invalid-ctime -x xxx" + expect="/invalid creation timestamp/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -K -I testkey-wrong-serial -x xxx - expect = /invalid serial number/ - - - cmd = $pcp -V $vault -K -I testkey-invalid-ctime -x xxx - expect = /invalid creation timestamp/ - - /* - - cmd = $pcp -V $vault -K -I testpubkey-wrong-type - expect = /key type is not PUBLIC/ - +check-vault-invalid-header () { + cmd="$pcp -V testvault-invalidheader -l" + expect="/Unexpected vault file format/" + check "$cmd" "$expect" "$input" +} - - cmd = $pcp -V $vault -K -I testpubkey-wrong-version - expect = /unknown key version/ - - */ - - - - prepare = ./invalidkeys - cmd = $pcp -V testvault-invalidheader -l - expect = /Unexpected vault file format/ - - - - cmd = $pcp -V testvault-invalidversion -l - expect = /Unexpected vault file format/ - - - - cmd = $pcp -V testvault-invaliditemtype -l - expect = /invalid key type/ - - - - cmd = $pcp -V testvault-invalidkeytype -l - expect = /contain any keys so far./ - +check-vault-invalid-version () { + cmd="$pcp -V testvault-invalidversion -l" + expect="/Unexpected vault file format/" + check "$cmd" "$expect" "$input" +} +check-vault-invalid-itemtype () { + cmd="$pcp -V testvault-invaliditemtype -l" + expect="/invalid key type/" + check "$cmd" "$expect" "$input" +} +check-vault-invalid-keytype () { + cmd="$pcp -V testvault-invalidkeytype -l" + expect="/contain any keys so far./" + check "$cmd" "$expect" "$input" +} # # input handling tests - - 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-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" +} # # fuzz tests - - prepare = (echo F; echo F) | $pcp -V vfz -k -x $passwd; \ - $pcp -V vfz -p -O testfuzzP.orig -x $passwd; \ - $pcp -V vfz -s -O testfuzzS.orig -x $passwd; - - loop = 30 - prepare = while :; do \ - cp testfuzzP.orig testfuzzP.pub; \ - $mangle testfuzzP.pub; \ - if ! diff testfuzzP.* > /dev/null 2>&1; then \ - break; \ - fi; \ - done - cmd = echo no | $pcp -V vf -K -I testfuzzP.pub -x $passwd - expect = !/added/ - - - loop = 30 - prepare = while :; do \ - cp testfuzzS.orig testfuzzS.sec; \ - $mangle testfuzzS.sec; \ - if ! diff testfuzzS.* > /dev/null 2>&1; then \ - break; \ - fi; \ - done - cmd = echo no | $pcp -V vf -K -I testfuzzS.sec -x $passwd - expect = !/added/ - - +check-fuzz-binary-pubkey () { + expect="!/added/" + cmd="echo no | $pcp -V vf -K -I testfuzzP.pub -x $passwd" + + for N in `./jot 30`; do + cp testfuzzP.orig testfuzzP.pub + $mangle testfuzzP.pub + if ! diff testfuzzP.* > /dev/null 2>&1; then + check "$cmd" "$expect" "$input" + break + fi + done +} + +check-fuzz-binary-seckey () { + cmd="echo no | $pcp -V vf -K -I testfuzzS.sec -x $passwd" + expect="!/added/" + for N in `./jot 30`; do + cp testfuzzS.orig testfuzzS.sec + $mangle testfuzzS.sec + if ! diff testfuzzS.* > /dev/null 2>&1; then + expect="!/added/" + check "$cmd" "$expect" "$input" + fi + done +} # checksum tests - - blake2 = 5baec1cad5bf54287028749d83f2bf3e3ed09f0ee38a233f35dbda1361c6a67fd824e17c86ee3a85181038eb44836c17c42e6beff17fdf997075417914056992 - blake2auth = d7fff04bd63004f7a2ba914d9b2ccff22827230d3c546d97ebaa29cbe9fb2380b7948bc799486d512b4355c24f0cce423e746419098d4455af91898c4a06a5df - key = 9U3Dk2s - - cmd = $pcp -C ../COPYING - expect = /$blake2/ - - - cmd = $pcp -x $key -C ../COPYING - expect = /$blake2auth/ - - - cmd = $pcp -C < ../COPYING - expect = /$blake2/ - - - cmd = $pcp -C ../COPYING ../README - expect = /README/ - - +check-checksum-copying () { + cmd="$pcp -C ../COPYING" + expect="/$blake2/" + check "$cmd" "$expect" "$input" +} + +check-checksum-authenticated-copying () { + cmd="$pcp -x $key -C ../COPYING" + expect="/$blake2auth/" + check "$cmd" "$expect" "$input" +} + +check-checksum-copying-stdin () { + cmd="$pcp -C < ../COPYING" + expect="/$blake2/" + check "$cmd" "$expect" "$input" +} + +check-checksum-multiple () { + cmd="$pcp -C ../COPYING ../README" + expect="/README/" + check "$cmd" "$expect" "$input" +} + +prepare () { + # global preparations + rm -f v* + ./invalidkeys + echo ${md5msg} > testmessage + (echo F; echo F) | $pcp -V vfz -k -x $passwd + $pcp -V vfz -p -O testfuzzP.orig -x $passwd + $pcp -V vfz -s -O testfuzzS.orig -x $passwd +} diff --git a/tests/unittests.sh b/tests/unittests.sh new file mode 100755 index 0000000..587f972 --- /dev/null +++ b/tests/unittests.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +errout () { + log="$1" + expect="$2" + echo " EXPECTED: $expect" + echo -n " GOT: " + cat $log | head -1 + cat $log | tail +2 | sed 's/^/ /' +} + + +lookup () { + log="$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" + return 1 + else + echo " OK" + return 0 + fi + else + expect=`echo "$expect" | sed -e 's#^/##' -e 's#/$##'` + if cat $log | grep "$expect" > /dev/null 2>&1; then + echo " OK" + return 0 + else + errout "$log" "$expect" + return 1 + fi + fi +} + +check() { + cmd="$1" + expect="$2" + input="$3" + file="$4" + log=".log-$$" + fail='' + + echo " executing $cmd" + + echo "$input" | eval "$cmd" > $log 2>&1 + + if test -n "$file"; then + # ignore result, check output file + if test -n "$expect"; then + # look for string in output + if ! lookup "$log" "$expect"; then + fail=y + fi + else + # just check for existence + if test -e "$file"; then + echo " OK" + else + echo " Failed: $file doesnt exist" + fail=y + fi + fi + else + # check output + if ! lookup "$log" "$expect"; then + fail=y + fi + fi + + rm -f $log + + if test -n "$fail"; then + return 1 + else + return 0 + fi +} + +checkdump () { + F="$1" + if test -e "pcp1.core"; then + echo "Test $F dumped core!" + gdb -x .gdb -batch $pcp pcp1.core + exit 1 + fi +} + +callcheck () { + F="$1" + rm -f pcp1.core + echo "--- test $F result:" + if ! $F; then + echo + echo "Test $F failed!" + checkdump $F + exit 1 + else + checkdump $F + fi +} + +cfg="$1" +check="$2" + +if test -z "$cfg"; then + echo "Usage: $0 [check]" + exit 1 +fi + +if ! test -e "$cfg"; then + echo "$cfg doesn't exist!" + exit 1 +fi + +. $cfg + +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 + callcheck $F + done + echo "All Tests OK" +fi +