docker_cli_cp_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "os/exec"
  8. "path"
  9. "path/filepath"
  10. "strings"
  11. "testing"
  12. )
  13. const (
  14. cpTestPathParent = "/some"
  15. cpTestPath = "/some/path"
  16. cpTestName = "test"
  17. cpFullPath = "/some/path/test"
  18. cpContainerContents = "holla, i am the container"
  19. cpHostContents = "hello, i am the host"
  20. )
  21. // Test for #5656
  22. // Check that garbage paths don't escape the container's rootfs
  23. func TestCpGarbagePath(t *testing.T) {
  24. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
  25. if err != nil || exitCode != 0 {
  26. t.Fatal("failed to create a container", out, err)
  27. }
  28. cleanedContainerID := stripTrailingCharacters(out)
  29. defer deleteContainer(cleanedContainerID)
  30. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  31. if err != nil || stripTrailingCharacters(out) != "0" {
  32. t.Fatal("failed to set up container", out, err)
  33. }
  34. if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
  35. t.Fatal(err)
  36. }
  37. hostFile, err := os.Create(cpFullPath)
  38. if err != nil {
  39. t.Fatal(err)
  40. }
  41. defer hostFile.Close()
  42. defer os.RemoveAll(cpTestPathParent)
  43. fmt.Fprintf(hostFile, "%s", cpHostContents)
  44. tmpdir, err := ioutil.TempDir("", "docker-integration")
  45. if err != nil {
  46. t.Fatal(err)
  47. }
  48. tmpname := filepath.Join(tmpdir, cpTestName)
  49. defer os.RemoveAll(tmpdir)
  50. path := path.Join("../../../../../../../../../../../../", cpFullPath)
  51. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
  52. if err != nil {
  53. t.Fatalf("couldn't copy from garbage path: %s:%s %s", cleanedContainerID, path, err)
  54. }
  55. file, _ := os.Open(tmpname)
  56. defer file.Close()
  57. test, err := ioutil.ReadAll(file)
  58. if err != nil {
  59. t.Fatal(err)
  60. }
  61. if string(test) == cpHostContents {
  62. t.Errorf("output matched host file -- garbage path can escape container rootfs")
  63. }
  64. if string(test) != cpContainerContents {
  65. t.Errorf("output doesn't match the input for garbage path")
  66. }
  67. logDone("cp - garbage paths relative to container's rootfs")
  68. }
  69. // Check that relative paths are relative to the container's rootfs
  70. func TestCpRelativePath(t *testing.T) {
  71. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
  72. if err != nil || exitCode != 0 {
  73. t.Fatal("failed to create a container", out, err)
  74. }
  75. cleanedContainerID := stripTrailingCharacters(out)
  76. defer deleteContainer(cleanedContainerID)
  77. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  78. if err != nil || stripTrailingCharacters(out) != "0" {
  79. t.Fatal("failed to set up container", out, err)
  80. }
  81. if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
  82. t.Fatal(err)
  83. }
  84. hostFile, err := os.Create(cpFullPath)
  85. if err != nil {
  86. t.Fatal(err)
  87. }
  88. defer hostFile.Close()
  89. defer os.RemoveAll(cpTestPathParent)
  90. fmt.Fprintf(hostFile, "%s", cpHostContents)
  91. tmpdir, err := ioutil.TempDir("", "docker-integration")
  92. if err != nil {
  93. t.Fatal(err)
  94. }
  95. tmpname := filepath.Join(tmpdir, cpTestName)
  96. defer os.RemoveAll(tmpdir)
  97. var relPath string
  98. if path.IsAbs(cpFullPath) {
  99. // normally this is `filepath.Rel("/", cpFullPath)` but we cannot
  100. // get this unix-path manipulation on windows with filepath.
  101. relPath = cpFullPath[1:]
  102. } else {
  103. t.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
  104. }
  105. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+relPath, tmpdir)
  106. if err != nil {
  107. t.Fatalf("couldn't copy from relative path: %s:%s %s", cleanedContainerID, relPath, err)
  108. }
  109. file, _ := os.Open(tmpname)
  110. defer file.Close()
  111. test, err := ioutil.ReadAll(file)
  112. if err != nil {
  113. t.Fatal(err)
  114. }
  115. if string(test) == cpHostContents {
  116. t.Errorf("output matched host file -- relative path can escape container rootfs")
  117. }
  118. if string(test) != cpContainerContents {
  119. t.Errorf("output doesn't match the input for relative path")
  120. }
  121. logDone("cp - relative paths relative to container's rootfs")
  122. }
  123. // Check that absolute paths are relative to the container's rootfs
  124. func TestCpAbsolutePath(t *testing.T) {
  125. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
  126. if err != nil || exitCode != 0 {
  127. t.Fatal("failed to create a container", out, err)
  128. }
  129. cleanedContainerID := stripTrailingCharacters(out)
  130. defer deleteContainer(cleanedContainerID)
  131. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  132. if err != nil || stripTrailingCharacters(out) != "0" {
  133. t.Fatal("failed to set up container", out, err)
  134. }
  135. if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
  136. t.Fatal(err)
  137. }
  138. hostFile, err := os.Create(cpFullPath)
  139. if err != nil {
  140. t.Fatal(err)
  141. }
  142. defer hostFile.Close()
  143. defer os.RemoveAll(cpTestPathParent)
  144. fmt.Fprintf(hostFile, "%s", cpHostContents)
  145. tmpdir, err := ioutil.TempDir("", "docker-integration")
  146. if err != nil {
  147. t.Fatal(err)
  148. }
  149. tmpname := filepath.Join(tmpdir, cpTestName)
  150. defer os.RemoveAll(tmpdir)
  151. path := cpFullPath
  152. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
  153. if err != nil {
  154. t.Fatalf("couldn't copy from absolute path: %s:%s %s", cleanedContainerID, path, err)
  155. }
  156. file, _ := os.Open(tmpname)
  157. defer file.Close()
  158. test, err := ioutil.ReadAll(file)
  159. if err != nil {
  160. t.Fatal(err)
  161. }
  162. if string(test) == cpHostContents {
  163. t.Errorf("output matched host file -- absolute path can escape container rootfs")
  164. }
  165. if string(test) != cpContainerContents {
  166. t.Errorf("output doesn't match the input for absolute path")
  167. }
  168. logDone("cp - absolute paths relative to container's rootfs")
  169. }
  170. // Test for #5619
  171. // Check that absolute symlinks are still relative to the container's rootfs
  172. func TestCpAbsoluteSymlink(t *testing.T) {
  173. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
  174. if err != nil || exitCode != 0 {
  175. t.Fatal("failed to create a container", out, err)
  176. }
  177. cleanedContainerID := stripTrailingCharacters(out)
  178. defer deleteContainer(cleanedContainerID)
  179. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  180. if err != nil || stripTrailingCharacters(out) != "0" {
  181. t.Fatal("failed to set up container", out, err)
  182. }
  183. if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
  184. t.Fatal(err)
  185. }
  186. hostFile, err := os.Create(cpFullPath)
  187. if err != nil {
  188. t.Fatal(err)
  189. }
  190. defer hostFile.Close()
  191. defer os.RemoveAll(cpTestPathParent)
  192. fmt.Fprintf(hostFile, "%s", cpHostContents)
  193. tmpdir, err := ioutil.TempDir("", "docker-integration")
  194. if err != nil {
  195. t.Fatal(err)
  196. }
  197. tmpname := filepath.Join(tmpdir, cpTestName)
  198. defer os.RemoveAll(tmpdir)
  199. path := path.Join("/", "container_path")
  200. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
  201. if err != nil {
  202. t.Fatalf("couldn't copy from absolute path: %s:%s %s", cleanedContainerID, path, err)
  203. }
  204. file, _ := os.Open(tmpname)
  205. defer file.Close()
  206. test, err := ioutil.ReadAll(file)
  207. if err != nil {
  208. t.Fatal(err)
  209. }
  210. if string(test) == cpHostContents {
  211. t.Errorf("output matched host file -- absolute symlink can escape container rootfs")
  212. }
  213. if string(test) != cpContainerContents {
  214. t.Errorf("output doesn't match the input for absolute symlink")
  215. }
  216. logDone("cp - absolute symlink relative to container's rootfs")
  217. }
  218. // Test for #5619
  219. // Check that symlinks which are part of the resource path are still relative to the container's rootfs
  220. func TestCpSymlinkComponent(t *testing.T) {
  221. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
  222. if err != nil || exitCode != 0 {
  223. t.Fatal("failed to create a container", out, err)
  224. }
  225. cleanedContainerID := stripTrailingCharacters(out)
  226. defer deleteContainer(cleanedContainerID)
  227. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  228. if err != nil || stripTrailingCharacters(out) != "0" {
  229. t.Fatal("failed to set up container", out, err)
  230. }
  231. if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
  232. t.Fatal(err)
  233. }
  234. hostFile, err := os.Create(cpFullPath)
  235. if err != nil {
  236. t.Fatal(err)
  237. }
  238. defer hostFile.Close()
  239. defer os.RemoveAll(cpTestPathParent)
  240. fmt.Fprintf(hostFile, "%s", cpHostContents)
  241. tmpdir, err := ioutil.TempDir("", "docker-integration")
  242. if err != nil {
  243. t.Fatal(err)
  244. }
  245. tmpname := filepath.Join(tmpdir, cpTestName)
  246. defer os.RemoveAll(tmpdir)
  247. path := path.Join("/", "container_path", cpTestName)
  248. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
  249. if err != nil {
  250. t.Fatalf("couldn't copy from symlink path component: %s:%s %s", cleanedContainerID, path, err)
  251. }
  252. file, _ := os.Open(tmpname)
  253. defer file.Close()
  254. test, err := ioutil.ReadAll(file)
  255. if err != nil {
  256. t.Fatal(err)
  257. }
  258. if string(test) == cpHostContents {
  259. t.Errorf("output matched host file -- symlink path component can escape container rootfs")
  260. }
  261. if string(test) != cpContainerContents {
  262. t.Errorf("output doesn't match the input for symlink path component")
  263. }
  264. logDone("cp - symlink path components relative to container's rootfs")
  265. }
  266. // Check that cp with unprivileged user doesn't return any error
  267. func TestCpUnprivilegedUser(t *testing.T) {
  268. testRequires(t, UnixCli) // uses chmod/su: not available on windows
  269. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
  270. if err != nil || exitCode != 0 {
  271. t.Fatal("failed to create a container", out, err)
  272. }
  273. cleanedContainerID := stripTrailingCharacters(out)
  274. defer deleteContainer(cleanedContainerID)
  275. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  276. if err != nil || stripTrailingCharacters(out) != "0" {
  277. t.Fatal("failed to set up container", out, err)
  278. }
  279. tmpdir, err := ioutil.TempDir("", "docker-integration")
  280. if err != nil {
  281. t.Fatal(err)
  282. }
  283. defer os.RemoveAll(tmpdir)
  284. if err = os.Chmod(tmpdir, 0777); err != nil {
  285. t.Fatal(err)
  286. }
  287. path := cpTestName
  288. _, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+cleanedContainerID+":"+path+" "+tmpdir))
  289. if err != nil {
  290. t.Fatalf("couldn't copy with unprivileged user: %s:%s %s", cleanedContainerID, path, err)
  291. }
  292. logDone("cp - unprivileged user")
  293. }
  294. func TestCpSpecialFiles(t *testing.T) {
  295. testRequires(t, SameHostDaemon)
  296. outDir, err := ioutil.TempDir("", "cp-test-special-files")
  297. if err != nil {
  298. t.Fatal(err)
  299. }
  300. defer os.RemoveAll(outDir)
  301. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
  302. if err != nil || exitCode != 0 {
  303. t.Fatal("failed to create a container", out, err)
  304. }
  305. cleanedContainerID := stripTrailingCharacters(out)
  306. defer deleteContainer(cleanedContainerID)
  307. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  308. if err != nil || stripTrailingCharacters(out) != "0" {
  309. t.Fatal("failed to set up container", out, err)
  310. }
  311. // Copy actual /etc/resolv.conf
  312. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
  313. if err != nil {
  314. t.Fatalf("couldn't copy from container: %s:%s %v", cleanedContainerID, "/etc/resolv.conf", err)
  315. }
  316. expected, err := ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/resolv.conf")
  317. actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
  318. if !bytes.Equal(actual, expected) {
  319. t.Fatalf("Expected copied file to be duplicate of the container resolvconf")
  320. }
  321. // Copy actual /etc/hosts
  322. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/etc/hosts", outDir)
  323. if err != nil {
  324. t.Fatalf("couldn't copy from container: %s:%s %v", cleanedContainerID, "/etc/hosts", err)
  325. }
  326. expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hosts")
  327. actual, err = ioutil.ReadFile(outDir + "/hosts")
  328. if !bytes.Equal(actual, expected) {
  329. t.Fatalf("Expected copied file to be duplicate of the container hosts")
  330. }
  331. // Copy actual /etc/resolv.conf
  332. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/etc/hostname", outDir)
  333. if err != nil {
  334. t.Fatalf("couldn't copy from container: %s:%s %v", cleanedContainerID, "/etc/hostname", err)
  335. }
  336. expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hostname")
  337. actual, err = ioutil.ReadFile(outDir + "/hostname")
  338. if !bytes.Equal(actual, expected) {
  339. t.Fatalf("Expected copied file to be duplicate of the container resolvconf")
  340. }
  341. logDone("cp - special files (resolv.conf, hosts, hostname)")
  342. }
  343. func TestCpVolumePath(t *testing.T) {
  344. testRequires(t, SameHostDaemon)
  345. tmpDir, err := ioutil.TempDir("", "cp-test-volumepath")
  346. if err != nil {
  347. t.Fatal(err)
  348. }
  349. defer os.RemoveAll(tmpDir)
  350. outDir, err := ioutil.TempDir("", "cp-test-volumepath-out")
  351. if err != nil {
  352. t.Fatal(err)
  353. }
  354. defer os.RemoveAll(outDir)
  355. _, err = os.Create(tmpDir + "/test")
  356. if err != nil {
  357. t.Fatal(err)
  358. }
  359. out, exitCode, err := dockerCmd(t, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar")
  360. if err != nil || exitCode != 0 {
  361. t.Fatal("failed to create a container", out, err)
  362. }
  363. cleanedContainerID := stripTrailingCharacters(out)
  364. defer deleteContainer(cleanedContainerID)
  365. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  366. if err != nil || stripTrailingCharacters(out) != "0" {
  367. t.Fatal("failed to set up container", out, err)
  368. }
  369. // Copy actual volume path
  370. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/foo", outDir)
  371. if err != nil {
  372. t.Fatalf("couldn't copy from volume path: %s:%s %v", cleanedContainerID, "/foo", err)
  373. }
  374. stat, err := os.Stat(outDir + "/foo")
  375. if err != nil {
  376. t.Fatal(err)
  377. }
  378. if !stat.IsDir() {
  379. t.Fatal("expected copied content to be dir")
  380. }
  381. stat, err = os.Stat(outDir + "/foo/bar")
  382. if err != nil {
  383. t.Fatal(err)
  384. }
  385. if stat.IsDir() {
  386. t.Fatal("Expected file `bar` to be a file")
  387. }
  388. // Copy file nested in volume
  389. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/foo/bar", outDir)
  390. if err != nil {
  391. t.Fatalf("couldn't copy from volume path: %s:%s %v", cleanedContainerID, "/foo", err)
  392. }
  393. stat, err = os.Stat(outDir + "/bar")
  394. if err != nil {
  395. t.Fatal(err)
  396. }
  397. if stat.IsDir() {
  398. t.Fatal("Expected file `bar` to be a file")
  399. }
  400. // Copy Bind-mounted dir
  401. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/baz", outDir)
  402. if err != nil {
  403. t.Fatalf("couldn't copy from bind-mounted volume path: %s:%s %v", cleanedContainerID, "/baz", err)
  404. }
  405. stat, err = os.Stat(outDir + "/baz")
  406. if err != nil {
  407. t.Fatal(err)
  408. }
  409. if !stat.IsDir() {
  410. t.Fatal("Expected `baz` to be a dir")
  411. }
  412. // Copy file nested in bind-mounted dir
  413. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/baz/test", outDir)
  414. fb, err := ioutil.ReadFile(outDir + "/baz/test")
  415. if err != nil {
  416. t.Fatal(err)
  417. }
  418. fb2, err := ioutil.ReadFile(tmpDir + "/test")
  419. if err != nil {
  420. t.Fatal(err)
  421. }
  422. if !bytes.Equal(fb, fb2) {
  423. t.Fatalf("Expected copied file to be duplicate of bind-mounted file")
  424. }
  425. // Copy bind-mounted file
  426. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/test", outDir)
  427. fb, err = ioutil.ReadFile(outDir + "/test")
  428. if err != nil {
  429. t.Fatal(err)
  430. }
  431. fb2, err = ioutil.ReadFile(tmpDir + "/test")
  432. if err != nil {
  433. t.Fatal(err)
  434. }
  435. if !bytes.Equal(fb, fb2) {
  436. t.Fatalf("Expected copied file to be duplicate of bind-mounted file")
  437. }
  438. logDone("cp - volume path")
  439. }
  440. func TestCpToDot(t *testing.T) {
  441. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
  442. if err != nil || exitCode != 0 {
  443. t.Fatal("failed to create a container", out, err)
  444. }
  445. cleanedContainerID := stripTrailingCharacters(out)
  446. defer deleteContainer(cleanedContainerID)
  447. out, _, err = dockerCmd(t, "wait", cleanedContainerID)
  448. if err != nil || stripTrailingCharacters(out) != "0" {
  449. t.Fatal("failed to set up container", out, err)
  450. }
  451. tmpdir, err := ioutil.TempDir("", "docker-integration")
  452. if err != nil {
  453. t.Fatal(err)
  454. }
  455. defer os.RemoveAll(tmpdir)
  456. cwd, err := os.Getwd()
  457. if err != nil {
  458. t.Fatal(err)
  459. }
  460. defer os.Chdir(cwd)
  461. if err := os.Chdir(tmpdir); err != nil {
  462. t.Fatal(err)
  463. }
  464. _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/test", ".")
  465. if err != nil {
  466. t.Fatalf("couldn't docker cp to \".\" path: %s", err)
  467. }
  468. content, err := ioutil.ReadFile("./test")
  469. if string(content) != "lololol\n" {
  470. t.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
  471. }
  472. logDone("cp - to dot path")
  473. }
  474. func TestCpToStdout(t *testing.T) {
  475. out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
  476. if err != nil || exitCode != 0 {
  477. t.Fatalf("failed to create a container:%s\n%s", out, err)
  478. }
  479. cID := stripTrailingCharacters(out)
  480. defer deleteContainer(cID)
  481. out, _, err = dockerCmd(t, "wait", cID)
  482. if err != nil || stripTrailingCharacters(out) != "0" {
  483. t.Fatalf("failed to set up container:%s\n%s", out, err)
  484. }
  485. out, _, err = runCommandPipelineWithOutput(
  486. exec.Command(dockerBinary, "cp", cID+":/test", "-"),
  487. exec.Command("tar", "-vtf", "-"))
  488. if err != nil {
  489. t.Fatalf("Failed to run commands: %s", err)
  490. }
  491. if !strings.Contains(out, "test") || !strings.Contains(out, "-rw") {
  492. t.Fatalf("Missing file from tar TOC:\n%s", out)
  493. }
  494. logDone("cp - to stdout")
  495. }