aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2024-08-23 22:27:51 +0200
committerJakob Unterwurzacher2024-08-23 22:32:41 +0200
commit1db3808654187b57c8fbb52ab9ef46b7ddf90951 (patch)
tree649a6cc675118fa47ca4a4e65d8a474ee15f8497
parentb78e6a1c4cc0d1bbd3581d561773db85ee2e75b7 (diff)
tests: reverse: add TestForceOwner
https://github.com/rfjakob/gocryptfs/issues/809
-rw-r--r--tests/reverse/force_owner_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/reverse/force_owner_test.go b/tests/reverse/force_owner_test.go
new file mode 100644
index 0000000..6e47b50
--- /dev/null
+++ b/tests/reverse/force_owner_test.go
@@ -0,0 +1,50 @@
+package reverse_test
+
+import (
+ "io/ioutil"
+ "net/url"
+ "os"
+ "syscall"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
+)
+
+func TestForceOwner(t *testing.T) {
+ // Let's not explode with "TempDir: pattern contains path separator"
+ myEscapedName := url.PathEscape(t.Name())
+ mnt, err := ioutil.TempDir(test_helpers.TmpDir, myEscapedName)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cliArgs := []string{"-reverse", "-zerokey", "-force_owner=1234:1234"}
+ if plaintextnames {
+ cliArgs = append(cliArgs, "-plaintextnames")
+ } else if deterministic_names {
+ cliArgs = append(cliArgs, "-deterministic-names")
+ }
+ test_helpers.MountOrFatal(t, "/", mnt, cliArgs...)
+ defer test_helpers.UnmountErr(mnt)
+
+ entries, err := os.ReadDir(mnt)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Check the mountpoint and everything inside it
+ toCheck := []string{mnt}
+ for _, e := range entries {
+ toCheck = append(toCheck, mnt+"/"+e.Name())
+ }
+
+ var st syscall.Stat_t
+ for _, path := range toCheck {
+ if err := syscall.Lstat(path, &st); err != nil {
+ t.Fatal(err)
+ }
+ if st.Uid != 1234 || st.Gid != 1234 {
+ t.Errorf("file %q: uid or gid != 1234: %#v", path, st)
+ }
+ }
+
+}