|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load helpers |
| 4 | + |
| 5 | +function setup() { |
| 6 | + teardown_busybox |
| 7 | + setup_busybox |
| 8 | +} |
| 9 | + |
| 10 | +function teardown() { |
| 11 | + teardown_busybox |
| 12 | +} |
| 13 | + |
| 14 | +@test "runc run [tty ptsname]" { |
| 15 | + # Replace sh script with readlink. |
| 16 | + sed -i 's|"sh"|"sh", "-c", "for file in /proc/self/fd/[012]; do readlink $file; done"|' config.json |
| 17 | + |
| 18 | + # run busybox |
| 19 | + runc run test_busybox |
| 20 | + [ "$status" -eq 0 ] |
| 21 | + [[ ${lines[0]} =~ /dev/pts/+ ]] |
| 22 | + [[ ${lines[1]} =~ /dev/pts/+ ]] |
| 23 | + [[ ${lines[2]} =~ /dev/pts/+ ]] |
| 24 | +} |
| 25 | + |
| 26 | +@test "runc run [tty owner]" { |
| 27 | + # Replace sh script with stat. |
| 28 | + sed -i 's/"sh"/"sh", "-c", "stat -c %u:%g $(tty) | tr : \\\\\\\\n"/' config.json |
| 29 | + |
| 30 | + # run busybox |
| 31 | + runc run test_busybox |
| 32 | + [ "$status" -eq 0 ] |
| 33 | + [[ ${lines[0]} =~ 0 ]] |
| 34 | + # This is set by the default config.json (it corresponds to the standard tty group). |
| 35 | + [[ ${lines[1]} =~ 5 ]] |
| 36 | +} |
| 37 | + |
| 38 | +@test "runc run [tty owner] ({u,g}id != 0)" { |
| 39 | + # replace "uid": 0 with "uid": 1000 |
| 40 | + # and do a similar thing for gid. |
| 41 | + sed -i 's;"uid": 0;"uid": 1000;g' config.json |
| 42 | + sed -i 's;"gid": 0;"gid": 100;g' config.json |
| 43 | + |
| 44 | + # Replace sh script with stat. |
| 45 | + sed -i 's/"sh"/"sh", "-c", "stat -c %u:%g $(tty) | tr : \\\\\\\\n"/' config.json |
| 46 | + |
| 47 | + # run busybox |
| 48 | + runc run test_busybox |
| 49 | + [ "$status" -eq 0 ] |
| 50 | + [[ ${lines[0]} =~ 1000 ]] |
| 51 | + # This is set by the default config.json (it corresponds to the standard tty group). |
| 52 | + [[ ${lines[1]} =~ 5 ]] |
| 53 | +} |
| 54 | + |
| 55 | +@test "runc exec [tty ptsname]" { |
| 56 | + # run busybox detached |
| 57 | + runc run -d --console-socket $CONSOLE_SOCKET test_busybox |
| 58 | + [ "$status" -eq 0 ] |
| 59 | + |
| 60 | + # check state |
| 61 | + wait_for_container 15 1 test_busybox |
| 62 | + |
| 63 | + # make sure we're running |
| 64 | + testcontainer test_busybox running |
| 65 | + |
| 66 | + # run the exec |
| 67 | + runc exec test_busybox sh -c 'for file in /proc/self/fd/[012]; do readlink $file; done' |
| 68 | + [ "$status" -eq 0 ] |
| 69 | + [[ ${lines[0]} =~ /dev/pts/+ ]] |
| 70 | + [[ ${lines[1]} =~ /dev/pts/+ ]] |
| 71 | + [[ ${lines[2]} =~ /dev/pts/+ ]] |
| 72 | +} |
| 73 | + |
| 74 | +@test "runc exec [tty owner]" { |
| 75 | + # run busybox detached |
| 76 | + runc run -d --console-socket $CONSOLE_SOCKET test_busybox |
| 77 | + [ "$status" -eq 0 ] |
| 78 | + |
| 79 | + # check state |
| 80 | + wait_for_container 15 1 test_busybox |
| 81 | + |
| 82 | + # make sure we're running |
| 83 | + testcontainer test_busybox running |
| 84 | + |
| 85 | + # run the exec |
| 86 | + runc exec test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' |
| 87 | + [ "$status" -eq 0 ] |
| 88 | + [[ ${lines[0]} =~ 0 ]] |
| 89 | + [[ ${lines[1]} =~ 5 ]] |
| 90 | +} |
| 91 | + |
| 92 | +@test "runc exec [tty owner] ({u,g}id != 0)" { |
| 93 | + # replace "uid": 0 with "uid": 1000 |
| 94 | + # and do a similar thing for gid. |
| 95 | + sed -i 's;"uid": 0;"uid": 1000;g' config.json |
| 96 | + sed -i 's;"gid": 0;"gid": 100;g' config.json |
| 97 | + |
| 98 | + # run busybox detached |
| 99 | + runc run -d --console-socket $CONSOLE_SOCKET test_busybox |
| 100 | + [ "$status" -eq 0 ] |
| 101 | + |
| 102 | + # check state |
| 103 | + wait_for_container 15 1 test_busybox |
| 104 | + |
| 105 | + # make sure we're running |
| 106 | + testcontainer test_busybox running |
| 107 | + |
| 108 | + # run the exec |
| 109 | + runc exec test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' |
| 110 | + [ "$status" -eq 0 ] |
| 111 | + [[ ${lines[0]} =~ 1000 ]] |
| 112 | + [[ ${lines[1]} =~ 5 ]] |
| 113 | +} |
0 commit comments