aboutsummaryrefslogtreecommitdiff
path: root/tests/cli
diff options
context:
space:
mode:
authorJakob Unterwurzacher2023-05-17 15:31:52 +0200
committerJakob Unterwurzacher2023-05-17 15:34:47 +0200
commitd7a3d7b97d0879853afa38cacf56e9582ad2a59d (patch)
treefe84bfce644e28b473852ce2bd3fd47f4da68d49 /tests/cli
parent76d0f3ca7c491b39197e1a69c52b63c39455acfc (diff)
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.
Diffstat (limited to 'tests/cli')
-rw-r--r--tests/cli/directmount_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/cli/directmount_test.go b/tests/cli/directmount_test.go
new file mode 100644
index 0000000..da78039
--- /dev/null
+++ b/tests/cli/directmount_test.go
@@ -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)
+ }
+
+}