mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-14 08:25:05 +01:00
Add tests
This commit is contained in:
parent
26cdcd0524
commit
688394cac9
5 changed files with 72 additions and 2 deletions
|
|
@ -222,6 +222,8 @@ struct SessionState {
|
|||
process_exit_send: mpsc::Sender<Result<ExitStatus, io::Error>>,
|
||||
process_exit_recv: mpsc::Receiver<Result<ExitStatus, io::Error>>,
|
||||
|
||||
envs: Vec<(String, String)>,
|
||||
|
||||
writer: Option<File>,
|
||||
reader: Option<File>,
|
||||
}
|
||||
|
|
@ -235,6 +237,7 @@ async fn handle_session_channel(user: String, channel: Channel) -> Result<()> {
|
|||
channel,
|
||||
process_exit_send,
|
||||
process_exit_recv,
|
||||
envs: Vec::new(),
|
||||
writer: None,
|
||||
reader: None,
|
||||
};
|
||||
|
|
@ -338,8 +341,25 @@ impl SessionState {
|
|||
ChannelRequest::Exec { .. } => {
|
||||
todo!()
|
||||
}
|
||||
ChannelRequest::ExitStatus { .. } => {}
|
||||
ChannelRequest::Env { .. } => {}
|
||||
ChannelRequest::Env {
|
||||
name,
|
||||
value,
|
||||
want_reply,
|
||||
} => match String::from_utf8(value) {
|
||||
Ok(value) => {
|
||||
self.envs.push((name, value));
|
||||
if want_reply {
|
||||
self.channel.send(ChannelOperationKind::Success).await?;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
debug!("Trying to set");
|
||||
if want_reply {
|
||||
self.channel.send(ChannelOperationKind::Failure).await?;
|
||||
}
|
||||
}
|
||||
},
|
||||
ChannelRequest::ExitStatus { .. } => unreachable!("forbidden"),
|
||||
};
|
||||
}
|
||||
ChannelUpdateKind::OpenFailed { .. } => todo!(),
|
||||
|
|
@ -389,6 +409,10 @@ impl SessionState {
|
|||
cmd.uid(user.uid());
|
||||
cmd.gid(user.primary_group_id());
|
||||
|
||||
for (k, v) in &self.envs {
|
||||
cmd.env(k, v);
|
||||
}
|
||||
|
||||
debug!(cmd = %shell.display(), uid = %user.uid(), gid = %user.primary_group_id(), "Executing process");
|
||||
|
||||
let mut shell = cmd.spawn()?;
|
||||
|
|
|
|||
12
bin/cluelesshd/tests/openssh-client/different-algorithms.sh
Normal file
12
bin/cluelesshd/tests/openssh-client/different-algorithms.sh
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# KEX
|
||||
printf $"exit\r" | ssh -oKexAlgorithms=curve25519-sha256 -p "$PORT" "$HOST"
|
||||
printf $"exit\r" | ssh -oKexAlgorithms=ecdh-sha2-nistp256 -p "$PORT" "$HOST"
|
||||
|
||||
# Encryption
|
||||
printf $"exit\r" | ssh -oCiphers=chacha20-poly1305@openssh.com -p "$PORT" "$HOST"
|
||||
printf $"exit\r" | ssh -oCiphers=aes256-gcm@openssh.com -p "$PORT" "$HOST"
|
||||
|
||||
# Host Key
|
||||
printf $"exit\r" | ssh -oHostKeyAlgorithms=ssh-ed25519 -p "$PORT" "$HOST"
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# disabled, TODO
|
||||
exit 0
|
||||
|
||||
echo | ssh -p "$PORT" "$HOST"
|
||||
3
bin/cluelesshd/tests/openssh-client/interactive-pty.sh
Normal file
3
bin/cluelesshd/tests/openssh-client/interactive-pty.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
printf $"exit\r" | ssh -oRequestTTY=force -p "$PORT" "$HOST"
|
||||
25
bin/cluelesshd/tests/run.sh
Executable file
25
bin/cluelesshd/tests/run.sh
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
script_dir=$(realpath "$(dirname "$0")")
|
||||
|
||||
cd "$script_dir/.."
|
||||
|
||||
cargo build
|
||||
|
||||
"../../target/debug/cluelesshd" &
|
||||
|
||||
pid=$!
|
||||
|
||||
kill_server() {
|
||||
echo "Killing server"
|
||||
kill "$pid"
|
||||
}
|
||||
|
||||
trap kill_server EXIT
|
||||
|
||||
for script in "$script_dir"/openssh-client/*.sh; do
|
||||
echo "-------------- Running $script"
|
||||
PORT=2223 HOST=localhost bash -euo pipefail "$script"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue