summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-09-18 13:17:24 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-09-18 13:17:24 -0700
commitc95e6ea1e74f82f1a889302978e37a7baf4073cf (patch)
tree4c09a436ede27b29c712e7151cc17917cd3a9e4f /tests
parent547e6c2679e8c686a51367b95a2bab272c51beb0 (diff)
downloadssh2-rs-c95e6ea1e74f82f1a889302978e37a7baf4073cf.zip
Split things up and write some docs
Diffstat (limited to 'tests')
-rw-r--r--tests/agent.rs16
-rw-r--r--tests/all.rs20
-rw-r--r--tests/session.rs42
3 files changed, 78 insertions, 0 deletions
diff --git a/tests/agent.rs b/tests/agent.rs
new file mode 100644
index 0000000..8feee06
--- /dev/null
+++ b/tests/agent.rs
@@ -0,0 +1,16 @@
+use ssh2::Session;
+
+#[test]
+fn smoke() {
+ let sess = Session::new().unwrap();
+ let mut agent = sess.agent().unwrap();
+ agent.connect().unwrap();
+ agent.list_identities().unwrap();
+ {
+ let mut a = agent.identities();
+ let i1 = a.next().unwrap().unwrap();
+ a.count();
+ assert!(agent.userauth("foo", &i1).is_err());
+ }
+ agent.disconnect().unwrap();
+}
diff --git a/tests/all.rs b/tests/all.rs
new file mode 100644
index 0000000..90473a3
--- /dev/null
+++ b/tests/all.rs
@@ -0,0 +1,20 @@
+extern crate ssh2;
+extern crate native;
+extern crate rustrt;
+
+use rustrt::rtio::{SocketAddr, Ipv4Addr};
+use native::io::net::TcpStream;
+
+mod agent;
+mod session;
+
+pub fn socket() -> TcpStream {
+ let stream = TcpStream::connect(SocketAddr {
+ ip: Ipv4Addr(127, 0, 0, 1),
+ port: 22,
+ }, None);
+ match stream {
+ Ok(s) => s,
+ Err(e) => fail!("no socket: [{}]: {}", e.code, e.detail),
+ }
+}
diff --git a/tests/session.rs b/tests/session.rs
new file mode 100644
index 0000000..5c91cff
--- /dev/null
+++ b/tests/session.rs
@@ -0,0 +1,42 @@
+use std::os;
+
+use ssh2::{mod, Session};
+
+#[test]
+fn smoke() {
+ let sess = Session::new().unwrap();
+ assert!(sess.banner_bytes().is_none());
+ sess.set_banner("foo").unwrap();
+ assert!(sess.is_blocking());
+ assert_eq!(sess.timeout(), 0);
+ sess.flag(ssh2::Compress, true).unwrap();
+ assert!(sess.host_key().is_none());
+ sess.method_pref(ssh2::MethodKex, "diffie-hellman-group14-sha1").unwrap();
+ assert!(sess.methods(ssh2::MethodKex).is_none());
+ sess.set_blocking(true);
+ sess.set_timeout(0);
+ sess.supported_algs(ssh2::MethodKex).unwrap();
+ sess.supported_algs(ssh2::MethodHostKey).unwrap();
+ sess.channel_session().err().unwrap();
+}
+
+#[test]
+fn smoke_handshake() {
+ let user = os::getenv("USER").unwrap();
+ let sess = Session::new().unwrap();
+ let socket = ::socket();
+ sess.handshake(socket.fd()).unwrap();
+ sess.host_key().unwrap();
+ let methods = sess.auth_methods(user.as_slice()).unwrap();
+ assert!(methods.contains("publickey"), "{}", methods);
+ 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());
+}