Merge pull request #44274 from thaJeztah/integration_cli_no_pkg_system
integration(-cli): remove uses of pkg/system.Stat()
This commit is contained in:
commit
18f8ab6fbd
3 changed files with 19 additions and 14 deletions
|
@ -10,9 +10,9 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
|
@ -59,12 +59,13 @@ func (s *DockerCLICpSuite) TestCpCheckDestOwnership(c *testing.T) {
|
|||
|
||||
assert.NilError(c, runDockerCp(c, srcPath, dstPath))
|
||||
|
||||
stat, err := system.Stat(filepath.Join(tmpVolDir, "file1"))
|
||||
stat, err := os.Stat(filepath.Join(tmpVolDir, "file1"))
|
||||
assert.NilError(c, err)
|
||||
uid, gid, err := getRootUIDGID()
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, stat.UID(), uint32(uid), "Copied file not owned by container root UID")
|
||||
assert.Equal(c, stat.GID(), uint32(gid), "Copied file not owned by container root GID")
|
||||
fi := stat.Sys().(*syscall.Stat_t)
|
||||
assert.Equal(c, fi.Uid, uint32(uid), "Copied file not owned by container root UID")
|
||||
assert.Equal(c, fi.Gid, uint32(gid), "Copied file not owned by container root GID")
|
||||
}
|
||||
|
||||
func getRootUIDGID() (int, int, error) {
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
|
@ -53,10 +53,11 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
|
|||
assert.Equal(c, uidgid[0], user)
|
||||
|
||||
// check that the created directory is owned by remapped uid:gid
|
||||
statNotExists, err := system.Stat(tmpDirNotExists)
|
||||
statNotExists, err := os.Stat(tmpDirNotExists)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, statNotExists.UID(), uint32(uid), "Created directory not owned by remapped root UID")
|
||||
assert.Equal(c, statNotExists.GID(), uint32(gid), "Created directory not owned by remapped root GID")
|
||||
fi := statNotExists.Sys().(*syscall.Stat_t)
|
||||
assert.Equal(c, fi.Uid, uint32(uid), "Created directory not owned by remapped root UID")
|
||||
assert.Equal(c, fi.Gid, uint32(gid), "Created directory not owned by remapped root GID")
|
||||
|
||||
pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns")
|
||||
assert.Assert(c, err == nil, "Could not inspect running container: out: %q", pid)
|
||||
|
@ -73,10 +74,11 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
// check that the touched file is owned by remapped uid:gid
|
||||
stat, err := system.Stat(filepath.Join(tmpDir, "testfile"))
|
||||
stat, err := os.Stat(filepath.Join(tmpDir, "testfile"))
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, stat.UID(), uint32(uid), "Touched file not owned by remapped root UID")
|
||||
assert.Equal(c, stat.GID(), uint32(gid), "Touched file not owned by remapped root GID")
|
||||
fi = stat.Sys().(*syscall.Stat_t)
|
||||
assert.Equal(c, fi.Uid, uint32(uid), "Touched file not owned by remapped root UID")
|
||||
assert.Equal(c, fi.Gid, uint32(gid), "Touched file not owned by remapped root GID")
|
||||
|
||||
// use host usernamespace
|
||||
out, err = s.d.Cmd("run", "-d", "--name", "userns_skip", "--userns", "host", "busybox", "sh", "-c", "touch /goofy/testfile; exec top")
|
||||
|
|
|
@ -3,7 +3,9 @@ package container // import "github.com/docker/docker/integration/container"
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -14,7 +16,6 @@ import (
|
|||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/moby/sys/mount"
|
||||
"github.com/moby/sys/mountinfo"
|
||||
"gotest.tools/v3/assert"
|
||||
|
@ -80,9 +81,10 @@ func TestContainerNetworkMountsNoChown(t *testing.T) {
|
|||
// daemon. In all other volume/bind mount situations we have taken this
|
||||
// same line--we don't chown host file content.
|
||||
// See GitHub PR 34224 for details.
|
||||
statT, err := system.Stat(tmpNWFileMount)
|
||||
info, err := os.Stat(tmpNWFileMount)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(uint32(0), statT.UID()), "bind mounted network file should not change ownership from root")
|
||||
fi := info.Sys().(*syscall.Stat_t)
|
||||
assert.Check(t, is.Equal(fi.Uid, uint32(0)), "bind mounted network file should not change ownership from root")
|
||||
}
|
||||
|
||||
func TestMountDaemonRoot(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue