(t *testing.T)
| 130 | } |
| 131 | |
| 132 | func TestPrivilegedHostDevices(t *testing.T) { |
| 133 | // Host devices are linux only. Also it creates host devices, |
| 134 | // so needs to be same host. |
| 135 | skip.If(t, testEnv.IsRemoteDaemon) |
| 136 | skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
| 137 | |
| 138 | ctx := setupTest(t) |
| 139 | apiClient := testEnv.APIClient() |
| 140 | |
| 141 | const ( |
| 142 | devTest = "/dev/test" |
| 143 | devRootOnlyTest = "/dev/root-only/test" |
| 144 | ) |
| 145 | |
| 146 | // Create Null devices. |
| 147 | if err := unix.Mknod(devTest, unix.S_IFCHR|0o600, int(unix.Mkdev(1, 3))); err != nil { |
| 148 | t.Fatal(err) |
| 149 | } |
| 150 | defer os.Remove(devTest) |
| 151 | if err := os.Mkdir(filepath.Dir(devRootOnlyTest), 0o700); err != nil { |
| 152 | t.Fatal(err) |
| 153 | } |
| 154 | defer os.RemoveAll(filepath.Dir(devRootOnlyTest)) |
| 155 | if err := unix.Mknod(devRootOnlyTest, unix.S_IFCHR|0o600, int(unix.Mkdev(1, 3))); err != nil { |
| 156 | t.Fatal(err) |
| 157 | } |
| 158 | defer os.Remove(devRootOnlyTest) |
| 159 | |
| 160 | cID := container.Run(ctx, t, apiClient, container.WithPrivileged(true)) |
| 161 | |
| 162 | // Check test device. |
| 163 | res, err := container.Exec(ctx, apiClient, cID, []string{"ls", devTest}) |
| 164 | assert.NilError(t, err) |
| 165 | assert.Equal(t, 0, res.ExitCode) |
| 166 | assert.Check(t, is.Equal(strings.TrimSpace(res.Stdout()), devTest)) |
| 167 | |
| 168 | // Check root-only test device. |
| 169 | res, err = container.Exec(ctx, apiClient, cID, []string{"ls", devRootOnlyTest}) |
| 170 | assert.NilError(t, err) |
| 171 | if testEnv.IsRootless() { |
| 172 | assert.Equal(t, 1, res.ExitCode) |
| 173 | assert.Check(t, is.Contains(res.Stderr(), "No such file or directory")) |
| 174 | } else { |
| 175 | assert.Equal(t, 0, res.ExitCode) |
| 176 | assert.Check(t, is.Equal(strings.TrimSpace(res.Stdout()), devRootOnlyTest)) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | func TestRunConsoleSize(t *testing.T) { |
| 181 | skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
nothing calls this directly
no test coverage detected
searching dependent graphs…