diff options
author | Alex Crichton <alex@alexcrichton.com> | 2015-01-18 16:14:08 -0800 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-18 16:14:08 -0800 |
commit | e2f2c5046f6079d80ed21ae21afc55249dff478a (patch) | |
tree | 79b61a47b057d3c8c555417d46402f752e1c26c0 /tests | |
parent | fd5b63c00e83d498a4badcc8cf2a7559ba0f4aa6 (diff) | |
download | ssh2-rs-e2f2c5046f6079d80ed21ae21afc55249dff478a.zip |
Tweak impls/apis
Lots of changes, but largely cosmetic, reorganization, or internal refactorings.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/all.rs | 36 | ||||
-rw-r--r-- | tests/session.rs | 8 |
2 files changed, 8 insertions, 36 deletions
diff --git a/tests/all.rs b/tests/all.rs index 2b194f7..590d7d9 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -4,6 +4,7 @@ extern crate libc; use std::mem; use std::num::Int; use std::os; +use std::io::TcpStream; mod agent; mod session; @@ -11,34 +12,15 @@ mod channel; mod knownhosts; mod sftp; -pub struct TcpStream(libc::c_int); - pub fn socket() -> TcpStream { - unsafe { - let socket = libc::socket(libc::AF_INET, libc::SOCK_STREAM, 0); - assert!(socket != -1, "{} {}", os::errno(), os::last_os_error()); - - let addr = libc::sockaddr_in { - sin_family: libc::AF_INET as libc::sa_family_t, - sin_port: 22.to_be(), - sin_addr: libc::in_addr { - s_addr: 0x7f000001.to_be(), - }, - ..mem::zeroed() - }; - - let r = libc::connect(socket, &addr as *const _ as *const _, - mem::size_of_val(&addr) as libc::c_uint); - assert!(r != -1, "{} {}", os::errno(), os::last_os_error()); - TcpStream(socket) - } + TcpStream::connect("127.0.0.1:22").unwrap() } pub fn authed_session() -> (TcpStream, ssh2::Session) { let user = os::getenv("USER").unwrap(); - let mut sess = ssh2::Session::new().unwrap(); let socket = socket(); - sess.handshake(socket.fd()).unwrap(); + let mut sess = ssh2::Session::new().unwrap(); + sess.handshake(&socket).unwrap(); assert!(!sess.authenticated()); { @@ -51,13 +33,3 @@ pub fn authed_session() -> (TcpStream, ssh2::Session) { assert!(sess.authenticated()); (socket, sess) } - -impl TcpStream { - fn fd(&self) -> libc::c_int { let TcpStream(fd) = *self; fd } -} - -impl Drop for TcpStream { - fn drop(&mut self) { - unsafe { libc::close(self.fd()); } - } -} diff --git a/tests/session.rs b/tests/session.rs index d95eb96..1040dad 100644 --- a/tests/session.rs +++ b/tests/session.rs @@ -10,7 +10,7 @@ fn smoke() { sess.set_banner("foo").unwrap(); assert!(sess.is_blocking()); assert_eq!(sess.timeout(), 0); - sess.flag(ssh2::SessionFlag::Compress, true).unwrap(); + sess.set_compress(true); assert!(sess.host_key().is_none()); sess.method_pref(MethodType::Kex, "diffie-hellman-group14-sha1").unwrap(); assert!(sess.methods(MethodType::Kex).is_none()); @@ -24,9 +24,9 @@ fn smoke() { #[test] fn smoke_handshake() { let user = os::getenv("USER").unwrap(); - let mut sess = Session::new().unwrap(); let socket = ::socket(); - sess.handshake(socket.fd()).unwrap(); + let mut sess = Session::new().unwrap(); + sess.handshake(&socket).unwrap(); sess.host_key().unwrap(); let methods = sess.auth_methods(user.as_slice()).unwrap(); assert!(methods.contains("publickey"), "{}", methods); @@ -46,7 +46,7 @@ fn smoke_handshake() { #[test] fn keepalive() { let (_tcp, sess) = ::authed_session(); - sess.keepalive_set(false, 10).unwrap(); + sess.set_keepalive(false, 10).unwrap(); sess.keepalive_send().unwrap(); } |