diff options
author | Jakob Unterwurzacher | 2021-03-21 11:10:18 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-03-21 11:10:18 +0100 |
commit | d7d79aa81c6d8f07e8b5c3f689b528462f32daa0 (patch) | |
tree | efe28c56c726fdabaeaf1c56f55c39eca395563f /tests/sharedstorage | |
parent | 6da2a690187f404031862d56804537649cb4a2ab (diff) |
Add tests/sharedstorage
Towards better test coverage of shared backing storage
mounts.
https://github.com/rfjakob/gocryptfs/issues/525
Diffstat (limited to 'tests/sharedstorage')
-rw-r--r-- | tests/sharedstorage/sharedstorage_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/sharedstorage/sharedstorage_test.go b/tests/sharedstorage/sharedstorage_test.go new file mode 100644 index 0000000..d2230a0 --- /dev/null +++ b/tests/sharedstorage/sharedstorage_test.go @@ -0,0 +1,61 @@ +// test gocryptfs cipherdir mounted multiple times at the same time +package sharedstorage + +import ( + "testing" + + "golang.org/x/sys/unix" + + "github.com/rfjakob/gocryptfs/tests/test_helpers" +) + +var flagSharestorage bool + +func TestMain(m *testing.M) { + flagSharestorage = false + m.Run() + flagSharestorage = true + m.Run() +} + +// mountSharedstorage mounts `cipherdir` on `mnt` with or without the +// `-sharedstorage` flag, depending on the global var `flagSharestorage`. +func mountSharedstorage(t *testing.T, cipherdir string, mnt string) { + args := []string{"-extpass=echo test"} + if flagSharestorage { + args = append(args, "-sharedstorage") + } + test_helpers.MountOrFatal(t, cipherdir, mnt, args...) +} + +func TestUnlink(t *testing.T) { + cipherdir := test_helpers.InitFS(t) + mnt1 := cipherdir + ".mnt1" + mnt2 := cipherdir + ".mnt2" + mountSharedstorage(t, cipherdir, mnt1) + defer test_helpers.UnmountPanic(mnt1) + mountSharedstorage(t, cipherdir, mnt2) + defer test_helpers.UnmountPanic(mnt2) + + // Create dir via mnt1 + if err := unix.Mkdir(mnt1+"/foo", 0700); err != nil { + t.Fatal(err) + } + // Replace dir with file via mnt2 + if err := unix.Rmdir(mnt2 + "/foo"); err != nil { + t.Fatal(err) + } + if fd, err := unix.Creat(mnt2+"/foo", 0600); err != nil { + t.Fatal(err) + } else { + unix.Close(fd) + } + // Try to unlink via mnt1 + if err := unix.Unlink(mnt1 + "/foo"); err != nil { + if flagSharestorage { + t.Fatal(err) + } else { + t.Logf("Unlink failed as expected: errno %d / %v", err, err) + } + } +} |