mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/chrootarchive: use t.TempDir()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d006242d73
commit
0955c88c2e
2 changed files with 12 additions and 55 deletions
|
@ -43,11 +43,7 @@ func CopyWithTar(src, dst string) error {
|
||||||
|
|
||||||
func TestChrootTarUntar(t *testing.T) {
|
func TestChrootTarUntar(t *testing.T) {
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootTarUntar")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
src := filepath.Join(tmpdir, "src")
|
src := filepath.Join(tmpdir, "src")
|
||||||
if err := system.MkdirAll(src, 0700); err != nil {
|
if err := system.MkdirAll(src, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -75,11 +71,7 @@ func TestChrootTarUntar(t *testing.T) {
|
||||||
// local images)
|
// local images)
|
||||||
func TestChrootUntarWithHugeExcludesList(t *testing.T) {
|
func TestChrootUntarWithHugeExcludesList(t *testing.T) {
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootUntarHugeExcludes")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
src := filepath.Join(tmpdir, "src")
|
src := filepath.Join(tmpdir, "src")
|
||||||
if err := system.MkdirAll(src, 0700); err != nil {
|
if err := system.MkdirAll(src, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -110,12 +102,7 @@ func TestChrootUntarWithHugeExcludesList(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChrootUntarEmptyArchive(t *testing.T) {
|
func TestChrootUntarEmptyArchive(t *testing.T) {
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootUntarEmptyArchive")
|
if err := Untar(nil, t.TempDir(), nil); err == nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
if err := Untar(nil, tmpdir, nil); err == nil {
|
|
||||||
t.Fatal("expected error on empty archive")
|
t.Fatal("expected error on empty archive")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,11 +163,7 @@ func compareFiles(src string, dest string) error {
|
||||||
func TestChrootTarUntarWithSymlink(t *testing.T) {
|
func TestChrootTarUntarWithSymlink(t *testing.T) {
|
||||||
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
|
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootTarUntarWithSymlink")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
src := filepath.Join(tmpdir, "src")
|
src := filepath.Join(tmpdir, "src")
|
||||||
if err := system.MkdirAll(src, 0700); err != nil {
|
if err := system.MkdirAll(src, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -200,11 +183,7 @@ func TestChrootTarUntarWithSymlink(t *testing.T) {
|
||||||
func TestChrootCopyWithTar(t *testing.T) {
|
func TestChrootCopyWithTar(t *testing.T) {
|
||||||
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
|
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootCopyWithTar")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
src := filepath.Join(tmpdir, "src")
|
src := filepath.Join(tmpdir, "src")
|
||||||
if err := system.MkdirAll(src, 0700); err != nil {
|
if err := system.MkdirAll(src, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -247,11 +226,7 @@ func TestChrootCopyWithTar(t *testing.T) {
|
||||||
|
|
||||||
func TestChrootCopyFileWithTar(t *testing.T) {
|
func TestChrootCopyFileWithTar(t *testing.T) {
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootCopyFileWithTar")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
src := filepath.Join(tmpdir, "src")
|
src := filepath.Join(tmpdir, "src")
|
||||||
if err := system.MkdirAll(src, 0700); err != nil {
|
if err := system.MkdirAll(src, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -292,11 +267,7 @@ func TestChrootCopyFileWithTar(t *testing.T) {
|
||||||
func TestChrootUntarPath(t *testing.T) {
|
func TestChrootUntarPath(t *testing.T) {
|
||||||
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
|
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootUntarPath")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
src := filepath.Join(tmpdir, "src")
|
src := filepath.Join(tmpdir, "src")
|
||||||
if err := system.MkdirAll(src, 0700); err != nil {
|
if err := system.MkdirAll(src, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -354,11 +325,7 @@ func (s *slowEmptyTarReader) Read(p []byte) (int, error) {
|
||||||
|
|
||||||
func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
|
func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootUntarEmptyArchiveFromSlowReader")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
dest := filepath.Join(tmpdir, "dest")
|
dest := filepath.Join(tmpdir, "dest")
|
||||||
if err := system.MkdirAll(dest, 0700); err != nil {
|
if err := system.MkdirAll(dest, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -371,11 +338,7 @@ func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
|
||||||
|
|
||||||
func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) {
|
func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) {
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootApplyEmptyArchiveFromSlowReader")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
dest := filepath.Join(tmpdir, "dest")
|
dest := filepath.Join(tmpdir, "dest")
|
||||||
if err := system.MkdirAll(dest, 0700); err != nil {
|
if err := system.MkdirAll(dest, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -388,11 +351,7 @@ func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) {
|
||||||
|
|
||||||
func TestChrootApplyDotDotFile(t *testing.T) {
|
func TestChrootApplyDotDotFile(t *testing.T) {
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
tmpdir, err := os.MkdirTemp("", "docker-TestChrootApplyDotDotFile")
|
tmpdir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
src := filepath.Join(tmpdir, "src")
|
src := filepath.Join(tmpdir, "src")
|
||||||
if err := system.MkdirAll(src, 0700); err != nil {
|
if err := system.MkdirAll(src, 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -25,13 +25,11 @@ import (
|
||||||
// container path that will actually overwrite data on the host
|
// container path that will actually overwrite data on the host
|
||||||
func TestUntarWithMaliciousSymlinks(t *testing.T) {
|
func TestUntarWithMaliciousSymlinks(t *testing.T) {
|
||||||
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
||||||
dir, err := os.MkdirTemp("", t.Name())
|
dir := t.TempDir()
|
||||||
assert.NilError(t, err)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
root := filepath.Join(dir, "root")
|
root := filepath.Join(dir, "root")
|
||||||
|
|
||||||
err = os.MkdirAll(root, 0755)
|
err := os.MkdirAll(root, 0o755)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
// Add a file into a directory above root
|
// Add a file into a directory above root
|
||||||
|
|
Loading…
Reference in a new issue