pash: add basic tests for pash using hgmo Docker cluster
authorGregory Szorc <gps@mozilla.com>
Mon, 09 Mar 2015 23:21:11 -0700
changeset 360516 c55e7bb85db0a0ecc7fe29fa6297c5db51bb20bd
parent 360515 730b73fe730425ff5c016c73fdad98dc69d38cba
child 360517 7671c97d9d96e48316a92eba2dea3ebd01d89a59
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
pash: add basic tests for pash using hgmo Docker cluster Now that we have a Docker cluster for hg.mozilla.org, let's put it to use by testing pash. The implemented test covers basic SSH auth behavior. We have to start somewhere.
run-mercurial-tests.py
scripts/pash/tests/helpers.sh
scripts/pash/tests/hghave
scripts/pash/tests/test-auth.t
--- a/run-mercurial-tests.py
+++ b/run-mercurial-tests.py
@@ -81,16 +81,17 @@ def get_test_files(extensions):
     hooks_test_dir = os.path.join(HERE, 'hghooks', 'tests')
     hook_tests = [os.path.join(hooks_test_dir, f)
                    for f in os.listdir(hooks_test_dir)
                    if is_test_filename(f)]
 
     # Directories containing Python unit tests.
     unit_test_dirs = [
         'autoland/tests',
+        'scripts/pash/tests',
         'pylib',
     ]
 
     # Directories whose Python unit tests we should ignore.
     unit_test_ignores = (
         'pylib/Bugsy',
         'pylib/flake8',
         'pylib/mccabe',
new file mode 100755
--- /dev/null
+++ b/scripts/pash/tests/helpers.sh
@@ -0,0 +1,19 @@
+alias hgmo='$TESTDIR/hgmo'
+alias testssh='ssh -T -F ssh_config'
+
+hgmoenv() {
+  export DOCKER_STATE_FILE=`pwd`/docker-state.json
+  export HGMO_STATE_FILE=`pwd`/hgmo.json
+
+  hgmo start --master-ssh-port $HGPORT > /dev/null
+  export SSH_SERVER=${DOCKER_HOSTNAME}
+
+  cat > ssh_config << EOF
+Host *
+  StrictHostKeyChecking no
+  PasswordAuthentication no
+  PreferredAuthentications publickey
+  UserKnownHostsFile ssh-known-hosts
+  ForwardX11 no
+EOF
+}
copy from hgext/reviewboard/tests/hghave
copy to scripts/pash/tests/hghave
new file mode 100644
--- /dev/null
+++ b/scripts/pash/tests/test-auth.t
@@ -0,0 +1,29 @@
+#require docker
+
+  $ . $TESTDIR/scripts/pash/tests/helpers.sh
+  $ hgmoenv
+
+Attempting to SSH into pash as an unknown user is denied
+
+  $ ssh-keygen -b 2048 -t rsa -f key1 -N '' > /dev/null
+
+  $ testssh -i key1 -l user1@example.com -p $HGPORT $SSH_SERVER
+  Warning: Permanently added '[*]:$HGPORT' (RSA) to the list of known hosts.\r (glob) (esc)
+  Permission denied (publickey).\r (esc)
+  [255]
+
+SSH as a valid user without proper key
+
+  $ hgmo create-ldap-user user1@example.com user1 1000 'Some User'
+  $ testssh -i key1 -l user1@example.com -p $HGPORT $SSH_SERVER
+  Permission denied (publickey).\r (esc)
+  [255]
+
+SSH with a valid key gives us warning about no interactive shells
+
+  $ hgmo add-ssh-key user1@example.com - < key1.pub
+  $ testssh -i key1 -l user1@example.com -p $HGPORT $SSH_SERVER
+  No interactive shells allowed here!
+  [1]
+
+  $ hgmo clean