Merge commit 'jrollins/master'
[monkeysphere.git] / tests / basic
index 5ba7a250b948affc504378ee09f2dce4ba79d76f..bf6a364942d0fcbfb6b664609a19567dc368f6d6 100755 (executable)
@@ -5,11 +5,12 @@
 # Authors: 
 #   Daniel Kahn Gillmor <dkg@fifthhorseman.net>
 #   Jameson Rollins <jrollins@fifthhorseman.net>
-# Copyright: 2008
+#   Micah Anderson <micah@riseup.net> 
+#
+# Copyright: 2008-2009
 # License: GPL v3 or later
 
-# these tests should all be able to
-# as a non-privileged user.
+# these tests should all be able to run as a non-privileged user.
 
 # all subcommands in this script should complete without failure:
 set -e
@@ -18,7 +19,7 @@ set -o pipefail
 
 ## make sure that the right tools are installed to run the test.  the
 ## test has *more* requirements than plain ol' monkeysphere:
-which socat || { echo "You must have socat installed to run this test." ; exit 1; }
+which socat >/dev/null || { echo "You must have socat installed to run this test." ; exit 1; }
 
 ## FIXME: other checks?
 
@@ -106,7 +107,7 @@ trap failed_cleanup EXIT
 ## set up some variables to ensure that we're operating strictly in
 ## the tests, not system-wide:
 
-export TESTDIR=$(pwd)
+export TESTDIR=$(dirname "$0")
 
 # make temp dir
 TEMPDIR="$TESTDIR"/tmp
@@ -122,7 +123,7 @@ export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
 
 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
-export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
+export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src/share
 export MONKEYSPHERE_MONKEYSPHERE_USER=$(whoami)
 export MONKEYSPHERE_CHECK_KEYSERVER=false
 export MONKEYSPHERE_LOG_LEVEL=DEBUG
@@ -160,53 +161,61 @@ get_gpg_prng_arg >> "$GNUPGHOME"/gpg.conf
 
 # set up sshd
 echo "### configuring sshd..."
-cp etc/ssh/sshd_config "$SSHD_CONFIG"
+cp "$TESTDIR"/etc/ssh/sshd_config "$SSHD_CONFIG"
 # write the sshd_config
 cat <<EOF >> "$SSHD_CONFIG"
 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
-AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
+AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authentication/authorized_keys/%u
 EOF
 
-# set up monkeysphere-server
-echo "### configuring monkeysphere..."
-mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
-mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
-mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
-mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/tmp
-cp etc/monkeysphere/monkeysphere-server.conf "$TEMPDIR"/monkeysphere-server.conf
-cat <<EOF >> "$TEMPDIR"/monkeysphere-server.conf
-AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authorized_user_ids"
-EOF
-cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
-primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
-EOF
 
+### SERVER HOST SETUP
 
-### SERVER TESTS
+# set up monkeysphere host
+echo "### configuring monkeysphere host..."
+mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/host
 
 # create a new host key
-echo "### generating server key..."
+echo "### generating server host key..."
 # add gpg.conf with quick-random
-get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
-echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
+get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/host/gpg.conf
+echo | monkeysphere-host expert gen-key --length 1024 --expire 0 testhost
 # remove the gpg.conf
-rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
+rm "$MONKEYSPHERE_SYSCONFIGDIR"/host/gpg.conf
 
-HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\  )
+HOSTKEYID=$( monkeysphere-host show-key | grep '^OpenPGP fingerprint: ' | cut -f3 -d\  )
 
 # certify it with the "Admin's Key".
 # (this would normally be done via keyservers)
-echo "### certifying server key..."
-monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
+echo "### certifying server host key..."
+GNUPGHOME="$MONKEYSPHERE_SYSCONFIGDIR"/host gpg --armor --export "$HOSTKEYID" | gpgadmin --import
 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
 
 # FIXME: how can we test publish-key without flooding junk into the
 # keyservers?
 
+
+### SERVER AUTHENTICATION TESTS
+
+# set up monkeysphere authentication
+echo "### configuring monkeysphere authentication..."
+mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authentication/{authorized_keys,core,sphere,tmp}
+cp "$TESTDIR"/etc/monkeysphere/monkeysphere-authentication.conf "$TEMPDIR"/
+cat <<EOF >> "$TEMPDIR"/monkeysphere-authentication.conf
+AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authentication/authorized_user_ids"
+EOF
+cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/authentication/sphere/gpg.conf
+primary-keyring ${MONKEYSPHERE_SYSDATADIR}/authentication/sphere/pubring.gpg
+keyring ${MONKEYSPHERE_SYSDATADIR}/authentication/core/pubring.gpg
+EOF
+
+# setup server authentication
+echo "### setting up server authentication..."
+monkeysphere-authentication setup
+
 # add admin as identity certifier for testhost
 echo "### adding admin as certifier..."
-echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
+echo y | monkeysphere-authentication add-id-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
 
 
 ### TESTUSER TESTS
@@ -221,9 +230,9 @@ gpgadmin --armor --export "$HOSTKEYID" | gpg --import
 
 # teach the "server" about the testuser's key
 echo "### export testuser key to server..."
-gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
+gpg --export testuser | monkeysphere-authentication gpg-cmd --import
 echo "### update server authorized_keys file for this testuser..."
-monkeysphere-server update-users $(whoami)
+monkeysphere-authentication update-users $(whoami)
 
 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
 # the identity before connection.  This should work in both directions!
@@ -234,7 +243,7 @@ ssh_test
 # sure that the ssh authentication FAILS
 echo "### removing testuser authorized_user_ids and updating..."
 mv "$TESTHOME"/.monkeysphere/authorized_user_ids{,.bak}
-monkeysphere-server update-users $(whoami)
+monkeysphere-authentication update-users $(whoami)
 echo "### ssh connection test for server authentication denial..."
 ssh_test 255
 mv "$TESTHOME"/.monkeysphere/authorized_user_ids{.bak,}
@@ -243,13 +252,13 @@ mv "$TESTHOME"/.monkeysphere/authorized_user_ids{.bak,}
 # make sure ssh authentication FAILS
 echo "### setting group writability on authorized_user_ids and updating..."
 chmod g+w "$TESTHOME"/.monkeysphere/authorized_user_ids
-monkeysphere-server update-users $(whoami)
+monkeysphere-authentication update-users $(whoami)
 echo "### ssh connection test for server authentication denial..."
 ssh_test 255
 chmod g-w "$TESTHOME"/.monkeysphere/authorized_user_ids
 echo "### setting other writability on authorized_user_ids and updating..."
 chmod o+w "$TESTHOME"/.monkeysphere/authorized_user_ids
-monkeysphere-server update-users $(whoami)
+monkeysphere-authentication update-users $(whoami)
 echo "### ssh connection test for server authentication denial..."
 ssh_test 255
 chmod o-w "$TESTHOME"/.monkeysphere/authorized_user_ids