2020-03-25 13:53:11 +00:00
|
|
|
package cephfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChmodDir(t *testing.T) {
|
|
|
|
dirname := "two"
|
2021-07-26 17:31:39 +00:00
|
|
|
var statsBefore uint32 = 0755
|
|
|
|
var statsAfter uint32 = 0700
|
2020-03-25 13:53:11 +00:00
|
|
|
mount := fsConnect(t)
|
|
|
|
defer fsDisconnect(t, mount)
|
|
|
|
|
2021-07-26 17:31:39 +00:00
|
|
|
err := mount.MakeDir(dirname, statsBefore)
|
2020-03-25 13:53:11 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer mount.RemoveDir(dirname)
|
|
|
|
|
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-03-12 19:49:59 +00:00
|
|
|
sx, err := mount.Statx(dirname, StatxBasicStats, 0)
|
2020-03-25 13:53:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-26 17:31:39 +00:00
|
|
|
assert.Equal(t, uint32(sx.Mode&0777), statsBefore)
|
2020-03-25 13:53:11 +00:00
|
|
|
|
2021-07-26 17:31:39 +00:00
|
|
|
err = mount.Chmod(dirname, statsAfter)
|
2020-03-25 13:53:11 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-03-12 19:49:59 +00:00
|
|
|
sx, err = mount.Statx(dirname, StatxBasicStats, 0)
|
|
|
|
require.NoError(t, err)
|
2021-07-26 17:31:39 +00:00
|
|
|
assert.Equal(t, uint32(sx.Mode&0777), statsAfter)
|
2020-03-25 13:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestChown(t *testing.T) {
|
|
|
|
dirname := "three"
|
|
|
|
// dockerfile creates bob user account
|
|
|
|
var bob uint32 = 1010
|
|
|
|
var root uint32
|
|
|
|
|
|
|
|
mount := fsConnect(t)
|
|
|
|
defer fsDisconnect(t, mount)
|
|
|
|
|
|
|
|
err := mount.MakeDir(dirname, 0755)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer mount.RemoveDir(dirname)
|
|
|
|
|
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-03-12 19:49:59 +00:00
|
|
|
sx, err := mount.Statx(dirname, StatxBasicStats, 0)
|
2020-03-25 13:53:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-03-12 19:49:59 +00:00
|
|
|
assert.Equal(t, uint32(sx.Uid), root)
|
|
|
|
assert.Equal(t, uint32(sx.Gid), root)
|
2020-03-25 13:53:11 +00:00
|
|
|
|
|
|
|
err = mount.Chown(dirname, bob, bob)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-03-12 19:49:59 +00:00
|
|
|
sx, err = mount.Statx(dirname, StatxBasicStats, 0)
|
2020-03-25 13:53:11 +00:00
|
|
|
assert.NoError(t, err)
|
2021-03-12 19:49:59 +00:00
|
|
|
assert.Equal(t, uint32(sx.Uid), bob)
|
|
|
|
assert.Equal(t, uint32(sx.Gid), bob)
|
2020-03-25 13:53:11 +00:00
|
|
|
}
|
2021-05-04 17:03:28 +00:00
|
|
|
|
|
|
|
func TestLchown(t *testing.T) {
|
|
|
|
dirname := "four"
|
|
|
|
var bob uint32 = 1010
|
|
|
|
var root uint32
|
|
|
|
|
|
|
|
mount := fsConnect(t)
|
|
|
|
defer fsDisconnect(t, mount)
|
|
|
|
|
|
|
|
err := mount.MakeDir(dirname, 0755)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer mount.RemoveDir(dirname)
|
|
|
|
|
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.Symlink(dirname, "symlnk")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer mount.Unlink("symlnk")
|
|
|
|
|
|
|
|
err = mount.Lchown("symlnk", bob, bob)
|
|
|
|
sx, err := mount.Statx("symlnk", StatxBasicStats, AtSymlinkNofollow)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, uint32(sx.Uid), bob)
|
|
|
|
assert.Equal(t, uint32(sx.Gid), bob)
|
|
|
|
sx, err = mount.Statx(dirname, StatxBasicStats, AtSymlinkNofollow)
|
|
|
|
assert.Equal(t, uint32(sx.Uid), root)
|
|
|
|
assert.Equal(t, uint32(sx.Gid), root)
|
|
|
|
}
|