tests: add TestDirectMount

This is in preparation of adding directmount capability.

It also check that FsName is set correctly, which is
in preparation for the next patch.
This commit is contained in:
Jakob Unterwurzacher 2023-05-17 15:31:52 +02:00
parent 76d0f3ca7c
commit d7a3d7b97d
2 changed files with 65 additions and 1 deletions

View File

@ -10,9 +10,12 @@ test:
.phony: root_test .phony: root_test
root_test: root_test:
./build.bash ./build.bash
# Need to use TMPDIR=/var/tmp as TestOverlay fails on tmpfs. # Need to use TMPDIR=/var/tmp as TestOverlay fails on tmpfs.
cd tests/root_test && go test -c && sudo TMPDIR=/var/tmp ./root_test.test -test.v cd tests/root_test && go test -c && sudo TMPDIR=/var/tmp ./root_test.test -test.v
cd tests/cli && go test -c && sudo ./cli.test -test.v -test.run=TestDirectMount
.phony: format .phony: format
format: format:
go fmt ./... go fmt ./...

View File

@ -0,0 +1,61 @@
package cli
import (
"fmt"
"strings"
"testing"
"github.com/moby/sys/mountinfo"
"github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
)
// TestDirectMount checks that the effective mount options are what we expect.
//
// This test should be run twice:
// 1) As a normal user (uses fusermount): make test
// 2) As root (mount syscall is called directly): make root_test
func TestDirectMount(t *testing.T) {
type testCase struct {
allow_other bool
}
table := []testCase{
{allow_other: false},
{allow_other: true},
}
dir := test_helpers.InitFS(t)
mnt := dir + ".mnt"
doTestMountInfo := func(t *testing.T, row testCase) {
test_helpers.MountOrFatal(t, dir, mnt, "-extpass=echo test", fmt.Sprintf("-allow_other=%v", row.allow_other))
defer test_helpers.UnmountErr(mnt)
mounts, err := mountinfo.GetMounts(mountinfo.SingleEntryFilter(mnt))
if err != nil {
t.Fatal(err)
}
if len(mounts) != 1 {
t.Fatalf("Could not find mountpoint %q in /proc/self/mountinfo", mnt)
}
info := mounts[0]
if info.FSType != "fuse.gocryptfs" {
t.Errorf("wrong FSType: %q", info.FSType)
}
if info.Source != dir {
t.Errorf("wrong Source: have %q, want %q", info.Source, dir)
}
if !strings.Contains(info.VFSOptions, "max_read=") {
t.Errorf("VFSOptions is missing max_read")
}
if row.allow_other && !strings.Contains(info.VFSOptions, "allow_other") {
t.Errorf("VFSOptions is missing allow_other")
}
}
for _, row := range table {
doTestMountInfo(t, row)
}
}