summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/all.rs20
-rw-r--r--tests/channel.rs12
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/all.rs b/tests/all.rs
index 90473a3..f8d427a 100644
--- a/tests/all.rs
+++ b/tests/all.rs
@@ -2,11 +2,13 @@ extern crate ssh2;
extern crate native;
extern crate rustrt;
+use std::os;
use rustrt::rtio::{SocketAddr, Ipv4Addr};
use native::io::net::TcpStream;
mod agent;
mod session;
+mod channel;
pub fn socket() -> TcpStream {
let stream = TcpStream::connect(SocketAddr {
@@ -18,3 +20,21 @@ pub fn socket() -> TcpStream {
Err(e) => fail!("no socket: [{}]: {}", e.code, e.detail),
}
}
+
+pub fn authed_session() -> (TcpStream, ssh2::Session) {
+ let user = os::getenv("USER").unwrap();
+ let sess = ssh2::Session::new().unwrap();
+ let socket = socket();
+ sess.handshake(socket.fd()).unwrap();
+ assert!(!sess.authenticated());
+
+ {
+ let mut agent = sess.agent().unwrap();
+ agent.connect().unwrap();
+ agent.list_identities().unwrap();
+ let identity = agent.identities().next().unwrap().unwrap();
+ agent.userauth(user.as_slice(), &identity).unwrap();
+ }
+ assert!(sess.authenticated());
+ (socket, sess)
+}
diff --git a/tests/channel.rs b/tests/channel.rs
new file mode 100644
index 0000000..22f242a
--- /dev/null
+++ b/tests/channel.rs
@@ -0,0 +1,12 @@
+#[test]
+fn smoke() {
+ let (_tcp, sess) = ::authed_session();
+ let mut channel = sess.channel_session().unwrap();
+ channel.flush().unwrap();
+ channel.exec("true").unwrap();
+ channel.wait_eof().unwrap();
+ assert_eq!(channel.exit_status().unwrap(), 0);
+ channel.close().unwrap();
+ channel.wait_close().unwrap();
+ assert!(channel.eof());
+}