Files
pcp/tests/unittests.cfg

607 lines
15 KiB
INI
Raw Normal View History

# -*-sh-*-
2013-11-04 17:43:22 +01:00
#
# This file is part of Pretty Curved Privacy (pcp1).
#
# Copyright (C) 2013-2015 T.v.Dein.
2013-11-04 17:43:22 +01:00
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# You can contact me by mail: <tlinden AT cpan DOT org>.
#
2013-10-28 22:50:05 +01:00
pcp=../src/pcp1
vault=v1
passwd=ech9xeiT%CuxuH1ch-is2ies1R
md5msg=66b8c4ca9e5d2a7e3c0559c3cdea3d50
mangle=./mangle
verbose=1
blake2=5baec1cad5bf54287028749d83f2bf3e3ed09f0ee38a233f35dbda1361c6a67fd824e17c86ee3a85181038eb44836c17c42e6beff17fdf997075417914056992
blake2auth=d7fff04bd63004f7a2ba914d9b2ccff22827230d3c546d97ebaa29cbe9fb2380b7948bc799486d512b4355c24f0cce423e746419098d4455af91898c4a06a5df
key=9U3Dk2s
. keys.cfg
check-dependencies-pcp () {
cmd="ls $pcp"
expect="/pcp/"
check "$cmd" "$expect" "$input"
}
check-streams-8 () {
md5=`./md5 ../COPYING`
cmd="./pipetest 8 e < ../COPYING | ./pipetest 8 d | ./md5"
expect="/$md5/"
check "$cmd" "$expect" "$input"
}
check-streams-16 () {
md5=`./md5 ../COPYING`
cmd="./pipetest 16 e < ../COPYING | ./pipetest 16 d | ./md5"
expect="/$md5/"
check "$cmd" "$expect" "$input"
}
check-streams-32 () {
md5=`./md5 ../COPYING`
cmd="./pipetest 32 e < ../COPYING | ./pipetest 32 d | ./md5"
expect="/$md5/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="./decodertest 1"
expect="/ok/"
check "$cmd" "$expect" "$input"
}
check-z85-2-compliant-no-newlines () {
cmd="./decodertest 2"
expect="/ok/"
check "$cmd" "$expect" "$input"
}
check-z85-3-compliant-no-begin-header () {
cmd="./decodertest 3"
expect="/ok/"
check "$cmd" "$expect" "$input"
}
check-z85-4-uncompliant-empty-comment () {
cmd="./decodertest 4"
expect="/ok/"
check "$cmd" "$expect" "$input"
}
check-z85-5-uncompliant-missing-char () {
cmd="./decodertest 5"
expect="/ok/"
check "$cmd" "$expect" "$input"
}
check-show-help () {
cmd="$pcp -h"
expect="/export/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V $vault -k -x $passwd"
input=$(cat <<'EOF'
2013-10-28 22:50:05 +01:00
Dexter Morgan
dxmorg@florida.cops.gov
EOF
)
expect="/Generated new secret key/"
check "$cmd" "$expect" "$input"
}
check-fail-entropy-generate-secret-key () {
cmd="$pcp -V $vault -k -x password"
input=$(cat <<'EOF'
Dexter Morgan
dxmorg@florida.cops.gov
no
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"
}
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 () {
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 () {
cmd="strings testkey-self"
expect="Dexter"
check "$cmd" "$expect" "$input" "$expectfile"
}
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 () {
cmd="$pcp -V $vault -t -i $bartid"
expect="/Serial Number: $bartserial/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V $vault -t"
expect="/Vault version: 00000002/"
check "$cmd" "$expect" "$input"
}
check-if-deleted-public-key-is-away () {
cmd="$pcp -V $vault -t"
expect="/Public keys: 0/"
check "$cmd" "$expect" "$input"
}
2013-10-28 22:50:05 +01:00
2013-10-28 22:50:05 +01:00
#
# encryption tests
# alicias part
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 () {
cmd="$pcp -V va -K -I key-bobby-pub"
expect="/${idbobby}/"
check "$cmd" "$expect" "$input"
}
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 () {
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 () {
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/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V vb -d -O testdecrypted -I testencrypted -x b"
expect="/successfully/"
check "$cmd" "$expect" "$input"
}
check-crypto-alicia-encrypted-file () {
cmd="cat testdecrypted"
expect="/${md5msg}/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V va -d -I testencryptedself -O testdecrypted -x a"
expect="/successfully/"
check "$cmd" "$expect" "$input"
}
2013-10-28 22:50:05 +01:00
2014-01-22 23:29:28 +01:00
#
# symetric encryption test
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"
}
2014-01-22 23:29:28 +01:00
#
# signature tests
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"
}
2014-02-05 14:04:55 +01:00
#
# sign+encrypt tests
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"
}
2014-02-05 14:04:55 +01:00
#
# raw C test with prepared keys, message and cipher
check-raw-decrypt () {
cmd="./statictest"
expect="/ok/"
check "$cmd" "$expect" "$input"
}
2013-10-28 22:50:05 +01:00
#
# negative tests, check for error handling
check-if-catch-conflicting-params () {
cmd="$pcp -V $vault -K -K"
expect="/invalid combination of commandline parameters/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V $vault -R"
expect="/You need to specify a key id/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V $vault -R -i 0x1111111111111111111111111"
expect="/is too long/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V $vault -R -i 0x0101010101010101"
expect="/No key with id 0x010101/"
check "$cmd" "$expect" "$input"
}
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 () {
$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 () {
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 () {
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 () {
$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 () {
$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 () {
touch testfile-empty
cmd="$pcp -V $vault -K -I testfile-empty"
expect="/file is empty/"
check "$cmd" "$expect" "$input"
}
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 () {
./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 () {
cmd="$pcp -V $vault -K -I bart.pub"
expect="/there already exists a key/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V $vault -K -I testkey-wrong-version -x xxx"
expect="/unknown key version/"
check "$cmd" "$expect" "$input"
}
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 () {
cmd="$pcp -V $vault -K -I testkey-invalid-ctime -x xxx"
expect="/invalid creation timestamp/"
check "$cmd" "$expect" "$input"
}
check-vault-invalid-header () {
cmd="$pcp -V testvault-invalidheader -l"
expect="/Unexpected vault file format/"
check "$cmd" "$expect" "$input"
}
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"
}
2013-11-16 13:45:28 +01:00
#
# input handling tests
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"
}
2013-12-02 22:54:04 +01:00
#
# fuzz tests
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
}
2013-12-02 22:54:04 +01:00
2015-07-17 17:40:07 +02:00
# checksum tests
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
}