docker_cli_cp_to_container_unix_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // +build !windows
  2. package main
  3. import (
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. "github.com/docker/docker/pkg/integration/checker"
  8. "github.com/docker/docker/pkg/system"
  9. "github.com/go-check/check"
  10. )
  11. // Check ownership is root, both in non-userns and userns enabled modes
  12. func (s *DockerSuite) TestCpCheckDestOwnership(c *check.C) {
  13. testRequires(c, DaemonIsLinux, SameHostDaemon)
  14. tmpVolDir := getTestDir(c, "test-cp-tmpvol")
  15. containerID := makeTestContainer(c,
  16. testContainerOptions{volumes: []string{fmt.Sprintf("%s:/tmpvol", tmpVolDir)}})
  17. tmpDir := getTestDir(c, "test-cp-to-check-ownership")
  18. defer os.RemoveAll(tmpDir)
  19. makeTestContentInDir(c, tmpDir)
  20. srcPath := cpPath(tmpDir, "file1")
  21. dstPath := containerCpPath(containerID, "/tmpvol", "file1")
  22. err := runDockerCp(c, srcPath, dstPath)
  23. c.Assert(err, checker.IsNil)
  24. stat, err := system.Stat(filepath.Join(tmpVolDir, "file1"))
  25. c.Assert(err, checker.IsNil)
  26. uid, gid, err := getRootUIDGID()
  27. c.Assert(err, checker.IsNil)
  28. c.Assert(stat.UID(), checker.Equals, uint32(uid), check.Commentf("Copied file not owned by container root UID"))
  29. c.Assert(stat.GID(), checker.Equals, uint32(gid), check.Commentf("Copied file not owned by container root GID"))
  30. }