Skip to content

Commit

Permalink
overlay: Test user.fuseoverlayfs.override_stat handling
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiko Odaki <[email protected]>
  • Loading branch information
akihikodaki committed Jun 9, 2024
1 parent 6140fab commit 399c519
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
27 changes: 19 additions & 8 deletions drivers/graphtest/graphtest_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ type Driver struct {
refCount int
}

func newDriver(t testing.TB, name string, options []string) *Driver {
root, err := os.MkdirTemp("", "storage-graphtest-")
require.NoError(t, err)
runroot, err := os.MkdirTemp("", "storage-graphtest-")
require.NoError(t, err)

require.NoError(t, os.MkdirAll(root, 0o755))
func newGraphDriver(t testing.TB, name string, options []string, root string, runroot string) graphdriver.Driver {
d, err := graphdriver.GetDriver(name, graphdriver.Options{DriverOptions: options, Root: root, RunRoot: runroot})
if err != nil {
t.Logf("graphdriver: %v\n", err)
Expand All @@ -63,7 +57,17 @@ func newDriver(t testing.TB, name string, options []string) *Driver {
}
t.Fatal(err)
}
return &Driver{d, root, runroot, 1}
return d
}

func newDriver(t testing.TB, name string, options []string) *Driver {
root, err := os.MkdirTemp("", "storage-graphtest-")
require.NoError(t, err)
runroot, err := os.MkdirTemp("", "storage-graphtest-")
require.NoError(t, err)

require.NoError(t, os.MkdirAll(root, 0o755))
return &Driver{newGraphDriver(t, name, options, root, runroot), root, runroot, 1}
}

func cleanup(t testing.TB, d *Driver) {
Expand All @@ -84,6 +88,13 @@ func GetDriver(t testing.TB, name string, options ...string) graphdriver.Driver
return drv
}

func ReconfigureDriver(t testing.TB, name string, options ...string) {
if err := drv.Cleanup(); err != nil {
t.Fatal(err)
}
drv.Driver = newGraphDriver(t, name, options, drv.root, drv.runroot)
}

// PutDriver removes the driver if it is no longer used and updates the reference count.
func PutDriver(t testing.TB) {
if drv == nil {
Expand Down
29 changes: 29 additions & 0 deletions drivers/overlay/overlay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
package overlay

import (
"os"
"os/exec"
"testing"

graphdriver "github.com/containers/storage/drivers"
"github.com/containers/storage/drivers/graphtest"
"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/reexec"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const driverName = "overlay"
Expand All @@ -31,6 +35,31 @@ func skipIfNaive(t *testing.T) {
}
}

// Ensure that a layer created with force_mask will keep the root directory mode
// with user.fuseoverlayfs.override_stat. This preserved mode should also be
// inherited by the upper layer, whether force_mask is set or not.
//
// This test is placed before TestOverlaySetup() because it uses driver options
// different from the other tests.
func TestOverlayXattr(t *testing.T) {
path, err := exec.LookPath("fuse-overlayfs")
if err != nil {
t.Skipf("fuse-overlayfs unavailable")
}

driver := graphtest.GetDriver(t, driverName, "force_mask=700", "mount_program="+path)
defer graphtest.PutDriver(t)
require.NoError(t, driver.Create("lower", "", nil))
graphtest.ReconfigureDriver(t, driverName, "mount_program="+path)
require.NoError(t, driver.Create("upper", "lower", nil))

root, err := driver.Get("upper", graphdriver.MountOpts{})
require.NoError(t, err)
fi, err := os.Stat(root)
require.NoError(t, err)
assert.Equal(t, 0o555&os.ModePerm, fi.Mode()&os.ModePerm, root)
}

// This avoids creating a new driver for each test if all tests are run
// Make sure to put new tests between TestOverlaySetup and TestOverlayTeardown
func TestOverlaySetup(t *testing.T) {
Expand Down

0 comments on commit 399c519

Please sign in to comment.