From 5be622fb563c89341a7dd5da4e65e2c225cb2c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 11 Aug 2013 01:37:44 +0200 Subject: [PATCH] Test SSH in travis Set up the ssh credentials so we are able to talk to localhost and issue git commands. Move to use a script, as the command list is getting somewhat long. While here, delay installing valgrind until we need it, as it and its dependencies are by far the largest downloads and this allows us to start compiling (and failing) faster and we only incur this cost when the test suite runs successfully. --- .travis.yml | 19 +++++-------------- CMakeLists.txt | 4 +++- script/cibuild.sh | 32 ++++++++++++++++++++++++++++++++ tests-clar/online/push.c | 10 ++++++++++ 4 files changed, 50 insertions(+), 15 deletions(-) create mode 100755 script/cibuild.sh diff --git a/.travis.yml b/.travis.yml index 0d5746f2e..71f8406fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ # Travis-CI Build for libgit2 # see travis-ci.org for details -# As CMake is not officially supported we use erlang VMs language: c compiler: @@ -18,25 +17,17 @@ matrix: - compiler: i586-mingw32msvc-gcc env: OPTIONS="-DBUILD_CLAR=OFF -DWIN32=ON -DMINGW=ON" -# Make sure CMake is installed install: - - sudo apt-get update >/dev/null - - sudo apt-get -q install cmake valgrind + - sudo apt-get -qq update + - sudo apt-get -qq install cmake libssh2-1-dev openssh-client openssh-server -# Run the Build script +# Run the Build script and tests script: - - mkdir _temp - - git init --bare _temp/test.git - - git daemon --listen=localhost --export-all --enable=receive-pack --base-path=_temp _temp 2>/dev/null & - - export GITTEST_REMOTE_URL="git://localhost/test.git" - - mkdir _build - - cd _build - - cmake .. -DCMAKE_INSTALL_PREFIX=../_install $OPTIONS - - cmake --build . --target install - - ctest -V . + - script/cibuild.sh # Run Tests after_success: + - sudo apt-get -qq install valgrind - valgrind --leak-check=full --show-reachable=yes --suppressions=../libgit2_clar.supp ./libgit2_clar -ionline # Only watch the development branch diff --git a/CMakeLists.txt b/CMakeLists.txt index 1500a3a68..1c70ec2d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,7 +148,9 @@ ELSE() FILE(GLOB SRC_ZLIB deps/zlib/*.c deps/zlib/*.h) ENDIF() -FIND_PACKAGE(LIBSSH2 QUIET) +IF (NOT MINGW) + FIND_PACKAGE(LIBSSH2 QUIET) +ENDIF() IF (LIBSSH2_FOUND) ADD_DEFINITIONS(-DGIT_SSH) INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIR}) diff --git a/script/cibuild.sh b/script/cibuild.sh new file mode 100755 index 000000000..722b3349d --- /dev/null +++ b/script/cibuild.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# Create a test repo which we can use for the online::push tests +mkdir $HOME/_temp +git init --bare $HOME/_temp/test.git +git daemon --listen=localhost --export-all --enable=receive-pack --base-path=$HOME/_temp $HOME/_temp 2>/dev/null & +export GITTEST_REMOTE_URL="git://localhost/test.git" + +mkdir _build +cd _build +cmake .. -DCMAKE_INSTALL_PREFIX=../_install $OPTIONS +cmake --build . --target install +ctest -V . + +# Now that we've tested the raw git protocol, let's set up ssh to we +# can do the push tests over it + +killall git-daemon +sudo start ssh +ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" -q +cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys +ssh-keyscan -t rsa localhost >>~/.ssh/known_hosts + +export GITTEST_REMOTE_URL="ssh://localhost/$HOME/_temp/test.git" +export GITTEST_REMOTE_USER=$USER +export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa" +export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub" +export GITTEST_REMOTE_SSH_PASSPHRASE="" + +if [ -e ./libgit2_clar ]; then + ./libgit2_clar -sonline::push +fi diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c index 5dc7974c7..8b9602b45 100644 --- a/tests-clar/online/push.c +++ b/tests-clar/online/push.c @@ -9,6 +9,10 @@ static git_repository *_repo; +static char *_remote_ssh_key; +static char *_remote_ssh_pubkey; +static char *_remote_ssh_passphrase; + static char *_remote_url; static char *_remote_user; static char *_remote_pass; @@ -42,6 +46,9 @@ static int cred_acquire_cb( *((bool*)payload) = true; + if (GIT_CREDTYPE_SSH_PUBLICKEY & allowed_types) + return git_cred_ssh_keyfile_passphrase_new(cred, _remote_user, _remote_ssh_pubkey, _remote_ssh_key, _remote_ssh_passphrase); + if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 || git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass) < 0) return -1; @@ -277,6 +284,9 @@ void test_online_push__initialize(void) _remote_url = cl_getenv("GITTEST_REMOTE_URL"); _remote_user = cl_getenv("GITTEST_REMOTE_USER"); _remote_pass = cl_getenv("GITTEST_REMOTE_PASS"); + _remote_ssh_key = cl_getenv("GITTEST_REMOTE_SSH_KEY"); + _remote_ssh_pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY"); + _remote_ssh_passphrase = cl_getenv("GITTEST_REMOTE_SSH_PASSPHRASE"); _remote = NULL; if (_remote_url) {