tests: Add tests for gpgtar and gpg-zip.
authorJustus Winter <justus@g10code.com>
Wed, 25 Nov 2015 17:32:09 +0000 (18:32 +0100)
committerJustus Winter <justus@g10code.com>
Wed, 25 Nov 2015 17:38:45 +0000 (18:38 +0100)
* tests/openpgp/Makefile.am (TESTS): Add new file.
* tests/openpgp/gpgtar.test: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
tests/openpgp/Makefile.am
tests/openpgp/gpgtar.test [new file with mode: 0755]

index 7263cd8..aa13be9 100644 (file)
@@ -46,6 +46,7 @@ TESTS = version.test mds.test \
        multisig.test verify.test armor.test \
        import.test ecc.test 4gb-packet.test \
        $(sqlite3_dependent_tests) \
+       gpgtar.test \
        finish.test
 
 
@@ -108,7 +109,7 @@ CLEANFILES = prepared.stamp x y yy z out err  $(data_files) \
             gnupg-test.stop random_seed gpg-agent.log tofu.db
 
 clean-local:
-       -rm -rf private-keys-v1.d openpgp-revocs.d tofu.d
+       -rm -rf private-keys-v1.d openpgp-revocs.d tofu.d gpgtar.d
 
 
 # We need to depend on a couple of programs so that the tests don't
diff --git a/tests/openpgp/gpgtar.test b/tests/openpgp/gpgtar.test
new file mode 100755 (executable)
index 0000000..7d55862
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+#set -x
+
+# Make sure $srcdir is set.
+if test "x$srcdir" = x
+then
+    echo srcdir environment variable not set!
+    exit 1
+fi
+
+. $srcdir/defs.inc || exit 3
+
+set -e
+
+# Make sure $GNUPGHOME is set.
+if test "x$GNUPGHOME" = x
+then
+    echo "GNUPGHOME not set."
+    exit 1
+fi
+
+TESTFILES="$plain_files $data_files"
+
+TESTDIR=gpgtar.d
+FILELIST="${TESTDIR}/filelist"
+GPG=../../g10/gpg2
+GPGTAR="../../tools/gpgtar"
+GPGZIP="sh ../../tools/gpg-zip --gpg-args --trust-model=always"
+
+for TOOL in "$GPGTAR" "$GPGZIP"
+do
+    rm -rf -- "${TESTDIR}"
+    mkdir "${TESTDIR}"
+
+    $TOOL --gpg "$GPG" --encrypt --recipient "$usrname2" \
+         --output "${TESTDIR}/test.tar.pgp" $TESTFILES
+
+    $TOOL --gpg "$GPG" --list-archive "${TESTDIR}/test.tar.pgp" >"$FILELIST"
+    for F in $TESTFILES
+    do
+       grep -qe "\\b${F}\\b" "$FILELIST"
+    done
+
+    EXTRACT_FLAGS="--directory=${TESTDIR}"
+    if [ "$TOOL" = "$GPGZIP" ]
+    then
+       EXTRACT_FLAGS="--tar-args $EXTRACT_FLAGS"
+    fi
+    $TOOL --gpg "$GPG" $EXTRACT_FLAGS --decrypt "${TESTDIR}/test.tar.pgp"
+    for F in $TESTFILES
+    do
+       diff -q "$F" "${TESTDIR}/$F"
+    done
+done
+
+# Success!
+
+exit 0