From 65f9b1f3909716a7ec82f2d6f4c69c5858576f81 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Tue, 25 Sep 2018 17:02:26 -0500 Subject: [PATCH] integration/docker: Add test to check host's integrity after `docker cp` host's files shouldn't be modified after running `docker cp` and finishing the container. fixes #771 Signed-off-by: Julio Montes --- integration/docker/cp_test.go | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/integration/docker/cp_test.go b/integration/docker/cp_test.go index 0006a3bfd..5602e2f5e 100644 --- a/integration/docker/cp_test.go +++ b/integration/docker/cp_test.go @@ -9,6 +9,7 @@ import ( "os" "path" + "github.com/kata-containers/tests" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -50,3 +51,53 @@ var _ = Describe("docker cp", func() { }) }) }) + +var _ = Describe("docker cp with volume attached", func() { + var ( + id string + exitCode int + hostPath string + cmd *tests.Command + dirBeforeCp string + dirAfterCp string + ) + + BeforeEach(func() { + hostPath = "/dev" + id = randomDockerName() + }) + + AfterEach(func() { + Expect(ExistDockerContainer(id)).NotTo(BeTrue()) + }) + + Context("check host path integrity", func() { + It("should not be modified", func() { + file, err := ioutil.TempFile(os.TempDir(), "file") + Expect(err).ToNot(HaveOccurred()) + err = file.Close() + Expect(err).ToNot(HaveOccurred()) + defer os.Remove(file.Name()) + Expect(file.Name()).To(BeAnExistingFile()) + + // check hostPath before running docker cp + cmd = tests.NewCommand("ls", hostPath) + dirBeforeCp, _, exitCode = cmd.Run() + Expect(exitCode).To(BeZero()) + + _, _, exitCode = dockerRun("-td", "-v", hostPath+":"+hostPath, "--name", id, Image, "sh") + Expect(exitCode).To(Equal(0)) + _, _, exitCode = dockerCp(file.Name(), id+":/") + Expect(exitCode).To(BeZero()) + Expect(RemoveDockerContainer(id)).To(BeTrue()) + + // check hostPath after running docker cp + cmd = tests.NewCommand("ls", hostPath) + dirAfterCp, _, exitCode = cmd.Run() + Expect(exitCode).To(BeZero()) + + // hostPath files and directories should be the same + Expect(dirBeforeCp).To(Equal(dirAfterCp)) + }) + }) +})