2016-04-14 21:14:42 -04:00
|
|
|
// +build linux freebsd
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package graphtest // import "github.com/docker/docker/daemon/graphdriver/graphtest"
|
2016-04-14 21:14:42 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
contdriver "github.com/containerd/continuity/driver"
|
2016-04-14 21:14:42 -04:00
|
|
|
"github.com/docker/docker/daemon/graphdriver"
|
2017-05-23 10:22:32 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2016-04-14 21:14:42 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func verifyFile(t testing.TB, path string, mode os.FileMode, uid, gid uint32) {
|
|
|
|
fi, err := os.Stat(path)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2016-04-14 21:14:42 -04:00
|
|
|
|
2017-05-24 16:25:13 -04:00
|
|
|
actual := fi.Mode()
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(mode&os.ModeType, actual&os.ModeType), path)
|
|
|
|
assert.Check(t, is.Equal(mode&os.ModePerm, actual&os.ModePerm), path)
|
|
|
|
assert.Check(t, is.Equal(mode&os.ModeSticky, actual&os.ModeSticky), path)
|
|
|
|
assert.Check(t, is.Equal(mode&os.ModeSetuid, actual&os.ModeSetuid), path)
|
|
|
|
assert.Check(t, is.Equal(mode&os.ModeSetgid, actual&os.ModeSetgid), path)
|
2016-04-14 21:14:42 -04:00
|
|
|
|
|
|
|
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(uid, stat.Uid), path)
|
|
|
|
assert.Check(t, is.Equal(gid, stat.Gid), path)
|
2016-04-14 21:14:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createBase(t testing.TB, driver graphdriver.Driver, name string) {
|
|
|
|
// We need to be able to set any perms
|
2017-05-23 10:22:32 -04:00
|
|
|
oldmask := unix.Umask(0)
|
|
|
|
defer unix.Umask(oldmask)
|
2016-04-14 21:14:42 -04:00
|
|
|
|
2017-05-24 16:25:13 -04:00
|
|
|
err := driver.CreateReadWrite(name, "", nil)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2016-04-14 21:14:42 -04:00
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
dirFS, err := driver.Get(name, "")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2016-04-14 21:14:42 -04:00
|
|
|
defer driver.Put(name)
|
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
subdir := dirFS.Join(dirFS.Path(), "a subdir")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, dirFS.Mkdir(subdir, 0705|os.ModeSticky))
|
|
|
|
assert.NilError(t, dirFS.Lchown(subdir, 1, 2))
|
2016-04-14 21:14:42 -04:00
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
file := dirFS.Join(dirFS.Path(), "a file")
|
|
|
|
err = contdriver.WriteFile(dirFS, file, []byte("Some data"), 0222|os.ModeSetuid)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2016-04-14 21:14:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func verifyBase(t testing.TB, driver graphdriver.Driver, name string) {
|
2017-08-03 20:22:00 -04:00
|
|
|
dirFS, err := driver.Get(name, "")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2016-04-14 21:14:42 -04:00
|
|
|
defer driver.Put(name)
|
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
subdir := dirFS.Join(dirFS.Path(), "a subdir")
|
2016-04-14 21:14:42 -04:00
|
|
|
verifyFile(t, subdir, 0705|os.ModeDir|os.ModeSticky, 1, 2)
|
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
file := dirFS.Join(dirFS.Path(), "a file")
|
2016-04-14 21:14:42 -04:00
|
|
|
verifyFile(t, file, 0222|os.ModeSetuid, 0, 0)
|
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
files, err := readDir(dirFS, dirFS.Path())
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Len(files, 2))
|
2016-04-14 21:14:42 -04:00
|
|
|
}
|