2019-01-20 13:41:20 +01:00
|
|
|
package matrix
|
|
|
|
|
|
|
|
import (
|
2019-01-20 14:32:59 +01:00
|
|
|
"fmt"
|
2019-01-20 13:41:20 +01:00
|
|
|
"os"
|
2021-05-23 11:08:03 +02:00
|
|
|
"os/exec"
|
2019-01-20 13:41:20 +01:00
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
2021-08-23 15:05:15 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
|
2019-01-20 13:41:20 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Test Mkdir and Rmdir
|
|
|
|
func TestMkdirRmdir(t *testing.T) {
|
|
|
|
test_helpers.TestMkdirRmdir(t, test_helpers.DefaultPlainDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overwrite an empty directory with another directory
|
|
|
|
func TestDirOverwrite(t *testing.T) {
|
|
|
|
dir1 := test_helpers.DefaultPlainDir + "/DirOverwrite1"
|
|
|
|
dir2 := test_helpers.DefaultPlainDir + "/DirOverwrite2"
|
|
|
|
err := os.Mkdir(dir1, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = os.Mkdir(dir2, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = syscall.Rename(dir1, dir2)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2019-01-20 14:32:59 +01:00
|
|
|
|
|
|
|
// Test that we can create and remove a directory regardless of the permission it has
|
2021-08-30 11:31:01 +02:00
|
|
|
// https://github.com/rfjakob/gocryptfs/issues/354
|
2019-01-20 14:32:59 +01:00
|
|
|
func TestRmdirPerms(t *testing.T) {
|
|
|
|
for _, perm := range []uint32{0000, 0100, 0200, 0300, 0400, 0500, 0600, 0700} {
|
|
|
|
dir := fmt.Sprintf("TestRmdir%#o", perm)
|
|
|
|
path := test_helpers.DefaultPlainDir + "/" + dir
|
|
|
|
err := syscall.Mkdir(path, perm)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Mkdir %q: %v", dir, err)
|
|
|
|
}
|
|
|
|
err = syscall.Rmdir(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Rmdir %q: %v", dir, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-23 11:08:03 +02:00
|
|
|
|
|
|
|
// TestHaveDotdot checks that we have "." and ".." in a directory.
|
|
|
|
// (gocryptfs v2.0-beta1 did not!)
|
|
|
|
func TestHaveDotdot(t *testing.T) {
|
|
|
|
dir1 := test_helpers.DefaultPlainDir + "/TestHaveDotdot"
|
|
|
|
err := os.Mkdir(dir1, 0700)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// All Go readdir functions filter out "." and "..".
|
|
|
|
// Fall back to "ls -a" which does not.
|
|
|
|
out, err := exec.Command("ls", "-a", dir1).CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
have := string(out)
|
|
|
|
want := ".\n..\n"
|
|
|
|
if have != want {
|
|
|
|
t.Errorf("have=%q want=%q", have, want)
|
|
|
|
}
|
|
|
|
}
|