move keytrans test to a separate test script, and move functions common to all test...
[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 # make temp dir
34 TEMPDIR="$TESTDIR"/tmp
35 if [ -e "$TEMPDIR" ] ; then
36     echo "tempdir '$TEMPDIR' already exists."
37     exit 1
38 fi
39 mkdir -p "$TEMPDIR"
40
41 # Use the local copy of executables first, instead of system ones.
42 # This should help us test without installing.
43 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
44
45 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
46 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
47 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src/share
48 export MONKEYSPHERE_MONKEYSPHERE_USER=$(whoami)
49 export MONKEYSPHERE_CHECK_KEYSERVER=false
50 export MONKEYSPHERE_LOG_LEVEL=DEBUG
51
52
53 ######################################################################
54 ### TEST KEYTRANS
55
56 echo "##################################################"
57 echo "### test key conversion..."
58 export GNUPGHOME="$TEMPDIR"
59 chmod 700 "$TEMPDIR"
60 # generate a key
61 gpg --batch --$(get_gpg_prng_arg) --gen-key <<EOF
62 Key-Type: RSA
63 Key-Length: 1024
64 Key-Usage: sign
65 Name-Real: testtest
66 Expire-Date: 0
67
68 %commit
69 %echo done
70 EOF
71 # get the the key timestamp
72 timestamp=$(gpg --list-key --with-colons --fixed-list-mode | \
73     grep ^pub: | cut -d: -f6)
74 # export the key to a file
75 gpg --export-secret-key | openpgp2ssh > \
76     "$TEMPDIR"/test.pem
77 # reconvert key, and compare to key in gpg keyring
78 diff -u \
79     <(gpg --export-secret-key | hd) \
80     <(PEM2OPENPGP_USAGE_FLAGS=sign,certify \
81     PEM2OPENPGP_TIMESTAMP="$timestamp" pem2openpgp testtest < \
82     "$TEMPDIR"/test.pem | hd )
83
84 # clear out the temp dir
85 rm -rf "$TEMPDIR"
86 mkdir -p "$TEMPDIR"