-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests to ensure that we always get a proper console (created inside the container). This is done by checking that the /proc/self/fd/[012] "symlinks" are always referencing something in /dev/pts/*. This patch is part of the console rewrite patchset. Signed-off-by: Aleksa Sarai <[email protected]>
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helpers | ||
|
||
function setup() { | ||
teardown_busybox | ||
setup_busybox | ||
} | ||
|
||
function teardown() { | ||
teardown_busybox | ||
} | ||
|
||
@test "runc run [tty ptsname]" { | ||
# Replace sh script with readlink. | ||
sed -i 's|"sh"|"sh", "-c", "for file in /proc/self/fd/[012]; do readlink $file; done"|' config.json | ||
|
||
# run busybox | ||
runc run test_busybox | ||
[ "$status" -eq 0 ] | ||
[[ ${lines[0]} =~ /dev/pts/+ ]] | ||
[[ ${lines[1]} =~ /dev/pts/+ ]] | ||
[[ ${lines[2]} =~ /dev/pts/+ ]] | ||
} | ||
|
||
@test "runc run [tty owner]" { | ||
# Replace sh script with stat. | ||
sed -i 's/"sh"/"sh", "-c", "stat -c %u:%g $(tty) | tr : \\\\\\\\n"/' config.json | ||
|
||
# run busybox | ||
runc run test_busybox | ||
[ "$status" -eq 0 ] | ||
[[ ${lines[0]} =~ 0 ]] | ||
# This is set by the default config.json (it corresponds to the standard tty group). | ||
[[ ${lines[1]} =~ 5 ]] | ||
} | ||
|
||
@test "runc run [tty owner] ({u,g}id != 0)" { | ||
# replace "uid": 0 with "uid": 1000 | ||
# and do a similar thing for gid. | ||
sed -i 's;"uid": 0;"uid": 1000;g' config.json | ||
sed -i 's;"gid": 0;"gid": 100;g' config.json | ||
|
||
# Replace sh script with stat. | ||
sed -i 's/"sh"/"sh", "-c", "stat -c %u:%g $(tty) | tr : \\\\\\\\n"/' config.json | ||
|
||
# run busybox | ||
runc run test_busybox | ||
[ "$status" -eq 0 ] | ||
[[ ${lines[0]} =~ 1000 ]] | ||
# This is set by the default config.json (it corresponds to the standard tty group). | ||
[[ ${lines[1]} =~ 5 ]] | ||
} | ||
|
||
@test "runc exec [tty ptsname]" { | ||
# run busybox detached | ||
runc run -d --console-socket $CONSOLE_SOCKET test_busybox | ||
[ "$status" -eq 0 ] | ||
|
||
# check state | ||
wait_for_container 15 1 test_busybox | ||
|
||
# make sure we're running | ||
testcontainer test_busybox running | ||
|
||
# run the exec | ||
runc exec test_busybox sh -c 'for file in /proc/self/fd/[012]; do readlink $file; done' | ||
[ "$status" -eq 0 ] | ||
[[ ${lines[0]} =~ /dev/pts/+ ]] | ||
[[ ${lines[1]} =~ /dev/pts/+ ]] | ||
[[ ${lines[2]} =~ /dev/pts/+ ]] | ||
} | ||
|
||
@test "runc exec [tty owner]" { | ||
# run busybox detached | ||
runc run -d --console-socket $CONSOLE_SOCKET test_busybox | ||
[ "$status" -eq 0 ] | ||
|
||
# check state | ||
wait_for_container 15 1 test_busybox | ||
|
||
# make sure we're running | ||
testcontainer test_busybox running | ||
|
||
# run the exec | ||
runc exec test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' | ||
[ "$status" -eq 0 ] | ||
[[ ${lines[0]} =~ 0 ]] | ||
[[ ${lines[1]} =~ 5 ]] | ||
} | ||
|
||
@test "runc exec [tty owner] ({u,g}id != 0)" { | ||
# replace "uid": 0 with "uid": 1000 | ||
# and do a similar thing for gid. | ||
sed -i 's;"uid": 0;"uid": 1000;g' config.json | ||
sed -i 's;"gid": 0;"gid": 100;g' config.json | ||
|
||
# run busybox detached | ||
runc run -d --console-socket $CONSOLE_SOCKET test_busybox | ||
[ "$status" -eq 0 ] | ||
|
||
# check state | ||
wait_for_container 15 1 test_busybox | ||
|
||
# make sure we're running | ||
testcontainer test_busybox running | ||
|
||
# run the exec | ||
runc exec test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' | ||
[ "$status" -eq 0 ] | ||
[[ ${lines[0]} =~ 1000 ]] | ||
[[ ${lines[1]} =~ 5 ]] | ||
} |