blob: 590d7d96f4991a26871b04a58751de661b280d8f (
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
|
extern crate ssh2;
extern crate libc;
use std::mem;
use std::num::Int;
use std::os;
use std::io::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 = os::getenv("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)
}
|