Skip to content

Commit 82cd834

Browse files
committed
Add test for is_terminal_for_pgrp usage
1 parent 162395c commit 82cd834

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

test-framework/sudo-compliance-tests/src/sudo/use_pty.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,42 @@ fn stderr_pipe() {
172172

173173
assert_eq!(stdout, "hello world");
174174
}
175+
176+
#[test]
177+
fn stdout_foreign_pty() {
178+
let env = Env([SUDOERS_ALL_ALL_NOPASSWD, "Defaults use_pty"]).build();
179+
180+
// Everything is put in a single command with separators to keep the pts numbers predictable
181+
let output = Command::new("sh")
182+
.args([
183+
"-c",
184+
"socat - SYSTEM:'ls -l /proc/self/fd; echo @@@@; sudo ls -l /proc/self/fd',pty,setsid,ctty,stderr;
185+
echo ====;
186+
socat - SYSTEM:'ls -l /proc/self/fd; echo @@@@; sudo ls -l /proc/self/fd',pty,stderr",
187+
])
188+
.tty(true)
189+
.output(&env);
190+
191+
let stdout = output.stdout();
192+
let (own_term, foreign_term) = stdout.split_once("====").unwrap();
193+
194+
let (own_term_in, own_term_sudo) = own_term.split_once("@@@@").unwrap();
195+
assert_contains!(own_term_in, " 0 -> /dev/pts/1");
196+
assert_contains!(own_term_in, " 1 -> /dev/pts/1");
197+
assert_contains!(own_term_in, " 2 -> /dev/pts/0");
198+
// pts/1 is our controlling tty, so it gets proxied.
199+
// pts/0 is a foreign pty, so it gets inherited
200+
assert_contains!(own_term_sudo, " 0 -> /dev/pts/2");
201+
assert_contains!(own_term_sudo, " 1 -> /dev/pts/2");
202+
assert_contains!(own_term_sudo, " 2 -> /dev/pts/0");
203+
204+
let (foreign_term_in, foreign_term_sudo) = foreign_term.split_once("@@@@").unwrap();
205+
assert_contains!(foreign_term_in, " 0 -> /dev/pts/1");
206+
assert_contains!(foreign_term_in, " 1 -> /dev/pts/1");
207+
assert_contains!(foreign_term_in, " 2 -> /dev/pts/0");
208+
// pts/1 is not our controlling tty, so it gets inherited.
209+
// pts/0 is our controlling tty, so it gets proxied
210+
assert_contains!(foreign_term_sudo, " 0 -> /dev/pts/1");
211+
assert_contains!(foreign_term_sudo, " 1 -> /dev/pts/1");
212+
assert_contains!(foreign_term_sudo, " 2 -> /dev/pts/2");
213+
}

test-framework/sudo-test/src/ours.freebsd.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM dougrabson/freebsd14.1-small:latest
2-
RUN IGNORE_OSVERSION=yes pkg install -y sshpass rsyslog bash vim pidof dash
2+
RUN IGNORE_OSVERSION=yes pkg install -y sshpass rsyslog bash vim pidof dash socat
33
WORKDIR /usr/src/sudo
44
COPY target/build build
55
# set setuid on install

test-framework/sudo-test/src/ours.linux.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM rust:1-slim-trixie
22
RUN apt-get update && \
3-
apt-get install -y --no-install-recommends apparmor libpam0g-dev libapparmor1 procps sshpass rsyslog ca-certificates tzdata
3+
apt-get install -y --no-install-recommends apparmor libpam0g-dev libapparmor1 procps sshpass rsyslog ca-certificates tzdata socat
44
# cache the crates.io index in the image for faster local testing
55
RUN cargo search sudo
66
WORKDIR /usr/src/sudo

test-framework/sudo-test/src/theirs.freebsd.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM dougrabson/freebsd14.1-small:latest
2-
RUN IGNORE_OSVERSION=yes pkg install -y sudo pidof sshpass rsyslog bash vim dash FreeBSD-libbsm && \
2+
RUN IGNORE_OSVERSION=yes pkg install -y sudo pidof sshpass rsyslog bash vim dash FreeBSD-libbsm socat && \
33
rm /usr/local/etc/sudoers
44
# Ensure we use the same shell across OSes
55
RUN chsh -s /bin/sh

test-framework/sudo-test/src/theirs.linux.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM debian:trixie-slim
22
RUN apt-get update && \
3-
apt-get install -y --no-install-recommends sudo procps sshpass rsyslog && \
3+
apt-get install -y --no-install-recommends sudo procps sshpass rsyslog socat && \
44
rm /etc/sudoers
55
# Ensure we use the same shell across OSes
66
RUN chsh -s /bin/sh

0 commit comments

Comments
 (0)