summaryrefslogtreecommitdiffstats
path: root/tests/openpgp/gpgtar.test
blob: 124ba404c0a3841b4516a0711ea0fe197ee84d2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/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"
PPFILE="${TESTDIR}/passphrase"
GPG=../../g10/gpg2
GPGARGS="$opt_always --no-permission-warning"

GPGTAR="../../tools/gpgtar"
GPGZIP="sh ../../tools/gpg-zip"

# Create, inspect, and extract an archive with the given options.
#
# $1 the tool to test
# $2 options used to create the archive
# $3 options used to inspect the archive
# $4 options used to extract the archive
do_test()
{
  (
    TOOL="$1"
    CREATE_FLAGS="$2"
    INSPECT_FLAGS="$3"
    EXTRACT_FLAGS="$4"

    rm -rf -- "${TESTDIR}"
    mkdir "${TESTDIR}"
    echo frob >"$PPFILE"

    $TOOL --gpg "$GPG" --gpg-args "$GPGARGS" $CREATE_FLAGS \
	  --output "${TESTDIR}/test.tar.pgp" $TESTFILES

    $TOOL --gpg "$GPG" --gpg-args "$GPGARGS" $INSPECT_FLAGS \
          "${TESTDIR}/test.tar.pgp" \
          >"$FILELIST"
    for F in $TESTFILES
    do
	grep -qe "\\b${F}\\b" "$FILELIST"
    done

    $TOOL --gpg "$GPG"  --gpg-args "$GPGARGS" $EXTRACT_FLAGS \
          --tar-args --directory="${TESTDIR}" \
          "${TESTDIR}/test.tar.pgp"
    for F in $TESTFILES
    do
	diff -q "$F" "${TESTDIR}/$F"
    done
  )
}

for TOOL in "$GPGTAR" "$GPGZIP"
#for TOOL in "$GPGZIP"
do
    do_test "$TOOL" \
	    "--encrypt --recipient $usrname2" \
	    "--list-archive" \
	    "--decrypt"

    do_test "$TOOL" \
	    "--encrypt --recipient $usrname2 --sign --local-user $usrname3" \
	    "--list-archive" \
	    "--decrypt"

    do_test "$TOOL" \
	    "--sign --local-user $usrname3" \
	    "--list-archive" \
	    "--decrypt"

    do_test "$TOOL" \
	    "--gpg-args --passphrase-file=$PPFILE --symmetric" \
	    "--gpg-args --passphrase-file=$PPFILE --list-archive" \
	    "--gpg-args --passphrase-file=$PPFILE --decrypt"
done

# Success!

exit 0