summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/all.rs36
-rw-r--r--tests/session.rs8
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();
}