1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 13:52:55 +03:00
wezterm/wezterm-ssh/tests/e2e/agent_forward.rs
Wez Furlong 6ad0da98d8
deps: remove smol-potat, update futures-lite
smol-potat hasn't had updates in 4 years and was bifurcating some
big deps.  It wasn't necessary; it was trivially easy to replace
with smol::block_on with no meaningful increase in boilerplate,
and the result is much more understandable in purpose and effect.
2024-05-13 11:43:10 -07:00

56 lines
1.8 KiB
Rust

use crate::sshd::*;
use portable_pty::{MasterPty, PtySize};
use rstest::*;
use std::io::Read;
use wezterm_ssh::Config;
#[fixture]
async fn session_with_agent_forward(
#[future]
#[with({ let mut config = Config::new(); config.set_option("forwardagent", "yes"); config })]
session: SessionWithSshd,
) -> SessionWithSshd {
session.await
}
#[rstest]
#[cfg_attr(not(any(target_os = "macos", target_os = "linux")), ignore)]
#[cfg_attr(not(feature = "libssh-rs"), ignore)]
fn ssh_add_should_be_able_to_list_identities_with_agent_forward(
#[future] session_with_agent_forward: SessionWithSshd,
) {
smol::block_on(async {
let session: SessionWithSshd = session_with_agent_forward.await;
let (pty, _child_process) = session
.request_pty("dumb", PtySize::default(), Some("ssh-add -l"), None)
.await
.unwrap();
let mut reader = pty.try_clone_reader().unwrap();
let mut output: String = String::new();
reader.read_to_string(&mut output).unwrap();
assert_eq!(output, "The agent has no identities.\r\n");
})
}
#[rstest]
#[cfg_attr(not(any(target_os = "macos", target_os = "linux")), ignore)]
#[cfg_attr(not(feature = "libssh-rs"), ignore)]
fn no_agent_forward_should_happen_when_disabled(#[future] session: SessionWithSshd) {
smol::block_on(async {
let session: SessionWithSshd = session.await;
let (pty, _child_process) = session
.request_pty("dumb", PtySize::default(), Some("ssh-add -l"), None)
.await
.unwrap();
let mut reader = pty.try_clone_reader().unwrap();
let mut output: String = String::new();
reader.read_to_string(&mut output).unwrap();
assert_eq!(
output,
"Could not open a connection to your authentication agent.\r\n"
);
})
}