github.com/getong/docker@v1.13.1/integration-cli/docker_cli_cp_to_container_unix_test.go (about)

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