summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWez Furlong <wez@wezfurlong.org>2019-07-23 22:28:10 -0700
committerWez Furlong <wez@wezfurlong.org>2019-07-29 08:55:06 -0700
commit13c3dc1de08e4be6c0b62f842e87f029ba1ab2ec (patch)
treef75e83adabaac8877d1975052139cb252b8ea435 /tests
parentdfcba59b6a77d9a730ed8d6b6728d8812ece424b (diff)
downloadssh2-rs-13c3dc1de08e4be6c0b62f842e87f029ba1ab2ec.zip
Add script for running integration tests
This makes it possible to run the integration tests without requiring that the user change their local ssh configuration. This is desirable because some sites have strict controls over the local ssh configuration files. This commit adds a script that spawns a local copy of the ssh daemon running on an alternate port with a specific configuration that is known to successfully pass the test suite. This has only been tested on my local macos machine so far.
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