summaryrefslogtreecommitdiff
path: root/tests/all.rs
blob: a8d50af2d5e2ab10cae89ed4e2cb77d0cabc9c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![deny(warnings)]
#![feature(io, core, path, env, net, fs)]

extern crate ssh2;
extern crate libc;

use std::env;
use std::net::TcpStream;

mod agent;
mod session;
mod channel;
mod knownhosts;
mod sftp;
mod tempdir;

pub fn socket() -> TcpStream {
    TcpStream::connect("127.0.0.1:22").unwrap()
}

pub fn authed_session() -> (TcpStream, ssh2::Session) {
    let user = env::var("USER").unwrap();
    let socket = socket();
    let mut sess = ssh2::Session::new().unwrap();
    sess.handshake(&socket).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)
}