aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cli/cli_test.go37
-rwxr-xr-xtests/dl-linux-tarball.bash2
-rw-r--r--tests/reverse/force_owner_test.go50
3 files changed, 88 insertions, 1 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go
index 686d14c..b2f9f40 100644
--- a/tests/cli/cli_test.go
+++ b/tests/cli/cli_test.go
@@ -4,6 +4,7 @@ package cli
import (
"bytes"
"encoding/hex"
+ "errors"
"fmt"
"io/ioutil"
"os"
@@ -1033,3 +1034,39 @@ func TestMountCreat(t *testing.T) {
test_helpers.UnmountPanic(mnt)
}
}
+
+// https://github.com/rfjakob/gocryptfs/issues/776
+func TestOrphanedSocket(t *testing.T) {
+ cDir := test_helpers.InitFS(t)
+ ctlSock := cDir + ".sock"
+ mnt := cDir + ".mnt"
+ test_helpers.MountOrFatal(t, cDir, mnt, "-extpass", "echo test", "-wpanic=false", "-ctlsock", ctlSock)
+
+ mnt2 := cDir + ".mnt2"
+ err := test_helpers.Mount(cDir, mnt2, false, "-extpass", "echo test", "-wpanic=false", "-ctlsock", ctlSock)
+ exitCode := test_helpers.ExtractCmdExitCode(err)
+ if exitCode != exitcodes.CtlSock {
+ t.Errorf("wrong exit code: want=%d, have=%d", exitcodes.CtlSock, exitCode)
+ }
+ test_helpers.UnmountPanic(mnt)
+
+ // Unmount returns before the gocryptfs process has terminated and before the
+ // socket file has been deleted. Wait out the deletion.
+ for i := 0; i < 100; i++ {
+ _, err := os.Stat(ctlSock)
+ if errors.Is(err, os.ErrNotExist) {
+ break
+ }
+ time.Sleep(time.Millisecond)
+ }
+
+ // Create orphaned socket file
+ err = syscall.Mknod(ctlSock, syscall.S_IFSOCK|0666, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Should delete the socket file automatically and the mount should work
+ test_helpers.MountOrFatal(t, cDir, mnt, "-extpass", "echo test", "-wpanic=false", "-ctlsock", ctlSock)
+ test_helpers.UnmountPanic(mnt)
+}
diff --git a/tests/dl-linux-tarball.bash b/tests/dl-linux-tarball.bash
index dfff492..03c0e7d 100755
--- a/tests/dl-linux-tarball.bash
+++ b/tests/dl-linux-tarball.bash
@@ -20,7 +20,7 @@ fi
if [[ $SIZE_ACTUAL -ne $SIZE_WANT ]]; then
echo "Downloading linux-3.0.tar.gz"
if command -v wget > /dev/null ; then
- wget -nv --show-progress -c -O "$TGZ" "$URL"
+ wget -nv -c -O "$TGZ" "$URL"
else
curl -o "$TGZ" "$URL"
fi
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)
+ }
+ }
+
+}