summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/all/main.rs5
-rw-r--r--tests/all/session.rs10
-rwxr-xr-xtests/run_integration_tests.sh62
3 files changed, 73 insertions, 4 deletions
diff --git a/tests/all/main.rs b/tests/all/main.rs
index 6f4335d..75f2a29 100644
--- a/tests/all/main.rs
+++ b/tests/all/main.rs
@@ -13,7 +13,10 @@ mod session;
mod sftp;
pub fn socket() -> TcpStream {
- TcpStream::connect("127.0.0.1:22").unwrap()
+ let port = env::var("RUST_SSH2_FIXTURE_PORT")
+ .map(|s| s.parse().unwrap())
+ .unwrap_or(22);
+ TcpStream::connect(&format!("127.0.0.1:{}", port)).unwrap()
}
pub fn authed_session() -> ssh2::Session {
diff --git a/tests/all/session.rs b/tests/all/session.rs
index 77fb824..2c636a2 100644
--- a/tests/all/session.rs
+++ b/tests/all/session.rs
@@ -1,7 +1,7 @@
use std::env;
use std::fs::File;
use std::io::prelude::*;
-use std::path::{Path, PathBuf};
+use std::path::Path;
use tempdir::TempDir;
use ssh2::{HashType, MethodType, Session};
@@ -57,10 +57,14 @@ fn keepalive() {
#[test]
fn scp_recv() {
let sess = ::authed_session();
- let (mut ch, _) = sess.scp_recv(Path::new(".ssh/authorized_keys")).unwrap();
+
+ // Download our own source file; it's the only path that
+ // we know for sure exists on this system.
+ let p = Path::new(file!()).canonicalize().unwrap();
+
+ let (mut ch, _) = sess.scp_recv(&p).unwrap();
let mut data = String::new();
ch.read_to_string(&mut data).unwrap();
- let p = PathBuf::from(env::var("HOME").unwrap()).join(".ssh/authorized_keys");
let mut expected = String::new();
File::open(&p)
.unwrap()
diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh
new file mode 100755
index 0000000..784a734
--- /dev/null
+++ b/tests/run_integration_tests.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+set -e
+set -x
+
+# This script spawns an ssh daemon with a known configuration so that we can
+# test various functionality against it.
+
+# Tell the tests to use the port number we're using to spawn this server
+export RUST_SSH2_FIXTURE_PORT=8022
+
+cleanup() {
+ # Stop the ssh server
+ kill $(< $SSHDIR/sshd.pid)
+ # Stop local ssh agent
+ kill $SSH_AGENT_PID
+}
+trap cleanup EXIT
+
+# Blow away any prior state and re-configure our test server
+SSHDIR=$(pwd)/tests/sshd
+
+rm -rf $SSHDIR
+mkdir -p $SSHDIR
+
+eval $(ssh-agent -s)
+
+ssh-keygen -t rsa -f $SSHDIR/id_rsa -N "" -q
+chmod 0600 $SSHDIR/id_rsa*
+ssh-add $SSHDIR/id_rsa
+cp $SSHDIR/id_rsa.pub $SSHDIR/authorized_keys
+
+ssh-keygen -f $SSHDIR/ssh_host_rsa_key -N '' -t rsa
+
+for p in /usr/lib/openssh/sftp-server /usr/libexec/sftp-server ; do
+ if test -x $p ; then
+ SFTP=$p
+ fi
+done
+
+cat > $SSHDIR/sshd_config <<-EOT
+AuthorizedKeysFile=$SSHDIR/authorized_keys
+HostKey=$SSHDIR/ssh_host_rsa_key
+PidFile=$SSHDIR/sshd.pid
+Subsystem sftp $SFTP
+UsePAM yes
+X11Forwarding yes
+PrintMotd yes
+PermitTunnel yes
+AllowTcpForwarding yes
+MaxStartups 500
+# Relax modes when the repo is under eg: /var/tmp
+StrictModes no
+EOT
+
+# Start an ssh server
+/usr/sbin/sshd -p $RUST_SSH2_FIXTURE_PORT -f $SSHDIR/sshd_config -E $SSHDIR/sshd.log
+# Give it a moment to start up
+sleep 2
+
+# Run the tests against it
+cargo test --all
+cargo test --features vendored-openssl