try to make keytrans test useful again.
[monkeysphere.git] / tests / keytrans
1 #!/usr/bin/env bash
2
3 # Tests to ensure that the monkeysphere is working
4
5 # Authors: 
6 #   Daniel Kahn Gillmor <dkg@fifthhorseman.net>
7 #   Jameson Rollins <jrollins@fifthhorseman.net>
8 #   Micah Anderson <micah@riseup.net> 
9 #
10 # Copyright: 2008-2009
11 # License: GPL v3 or later
12
13 # these tests should all be able to run as a non-privileged user.
14
15 # all subcommands in this script should complete without failure:
16 set -e
17 # piped commands should return the code of the first non-zero return
18 set -o pipefail
19
20 export TESTDIR=$(dirname "$0")
21
22 source "$TESTDIR"/common
23
24 ## setup trap
25 trap failed_cleanup EXIT
26
27 ######################################################################
28 ### SETUP VARIABLES
29
30 ## set up some variables to ensure that we're operating strictly in
31 ## the tests, not system-wide:
32
33 mkdir -p "$TESTDIR"/tmp
34 TEMPDIR=$(mktemp -d "${TMPDIR:-$TESTDIR/tmp}/monkeyspheretest.XXXXXXX")
35
36 mkdir "$TEMPDIR"/bin
37 ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/openpgp2ssh
38 ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/pem2openpgp
39
40 # Use the local copy of executables first, instead of system ones.
41 # This should help us test without installing.
42 export PATH="$TEMPDIR"/bin:"$PATH"
43
44 ######################################################################
45 ### TEST KEYTRANS
46
47 echo "##################################################"
48 echo "### generating openpgp key..."
49 export GNUPGHOME="$TEMPDIR"
50 chmod 700 "$TEMPDIR"
51 # generate a key
52 gpg --batch --$(get_gpg_prng_arg) --gen-key <<EOF
53 Key-Type: RSA
54 Key-Length: 1024
55 Key-Usage: sign
56 Name-Real: testtest
57 Expire-Date: 0
58
59 %commit
60 %echo done
61 EOF
62
63 echo "##################################################"
64 echo "### retrieving key timestamp..."
65 timestamp=$(gpg --list-key --with-colons --fixed-list-mode | \
66     grep ^pub: | cut -d: -f6)
67
68 echo "##################################################"
69 echo "### exporting key to ssh file..."
70 gpg --export-secret-key | openpgp2ssh > \
71     "$TEMPDIR"/test.pem
72
73 echo "##################################################"
74 echo "### reconvert key, and compare to key in gpg keyring..."
75 diff -u \
76     <(gpg --export-secret-key | hd) \
77     <(PEM2OPENPGP_USAGE_FLAGS=sign,certify \
78     PEM2OPENPGP_TIMESTAMP="$timestamp" pem2openpgp testtest < \
79     "$TEMPDIR"/test.pem | hd )
80
81 trap - EXIT
82
83 echo "##################################################"
84 echo " Monkeysphere keytrans test completed successfully!"
85 echo "##################################################"
86
87 cleanup