summaryrefslogtreecommitdiff
path: root/tests/all.rs
blob: 74c38b1b23045dc20c9f5a3a9453d2bca786471e (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(core)]

extern crate ssh2;
extern crate libc;
extern crate tempdir;

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

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

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)
}