2021-08-20 17:06:18 +02:00
|
|
|
package reverse_test
|
2021-08-16 18:40:48 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/url"
|
2021-08-20 17:06:18 +02:00
|
|
|
"os"
|
2021-08-16 18:40:48 +02:00
|
|
|
"runtime"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
2021-08-23 15:05:15 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
|
2021-08-16 18:40:48 +02:00
|
|
|
)
|
|
|
|
|
2021-08-20 17:06:18 +02:00
|
|
|
func TestOneFileSystem(t *testing.T) {
|
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
t.Skip("only works on linux")
|
|
|
|
}
|
2021-08-16 18:40:48 +02:00
|
|
|
// 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", "-one-file-system"}
|
|
|
|
if plaintextnames {
|
|
|
|
cliArgs = append(cliArgs, "-plaintextnames")
|
2021-08-20 17:06:18 +02:00
|
|
|
} else if deterministic_names {
|
|
|
|
cliArgs = append(cliArgs, "-deterministic-names")
|
2021-08-16 18:40:48 +02:00
|
|
|
}
|
|
|
|
test_helpers.MountOrFatal(t, "/", mnt, cliArgs...)
|
|
|
|
defer test_helpers.UnmountErr(mnt)
|
|
|
|
|
|
|
|
// Copied from inomap
|
|
|
|
const maxPassthruIno = 1<<48 - 1
|
|
|
|
|
2021-08-16 22:00:40 +02:00
|
|
|
entries, err := ioutil.ReadDir(mnt)
|
2021-08-16 18:40:48 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
mountpoints := []string{}
|
|
|
|
for _, e := range entries {
|
|
|
|
if !e.IsDir() {
|
|
|
|
// We are only interested in directories
|
|
|
|
continue
|
|
|
|
}
|
2021-08-16 22:00:40 +02:00
|
|
|
st := e.Sys().(*syscall.Stat_t)
|
2021-08-16 18:40:48 +02:00
|
|
|
// The inode numbers of files with a different device number are remapped
|
|
|
|
// to something above maxPassthruIno
|
|
|
|
if st.Ino > maxPassthruIno {
|
|
|
|
mountpoints = append(mountpoints, e.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(mountpoints) == 0 {
|
|
|
|
t.Skip("no mountpoints found, nothing to test")
|
|
|
|
}
|
|
|
|
for _, m := range mountpoints {
|
2021-08-20 17:06:18 +02:00
|
|
|
dir, err := os.Open(mnt + "/" + m)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
defer dir.Close()
|
|
|
|
e, err := dir.Readdirnames(-1)
|
2021-08-16 18:40:48 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
expected := 1
|
2021-08-20 17:06:18 +02:00
|
|
|
if plaintextnames || deterministic_names {
|
2021-08-16 18:40:48 +02:00
|
|
|
expected = 0
|
|
|
|
}
|
|
|
|
if len(e) != expected {
|
2021-08-20 17:06:18 +02:00
|
|
|
t.Errorf("mountpoint %q should have %d entries, actually has: %v", m, expected, e)
|
2021-08-16 18:40:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Logf("tested %d mountpoints: %v", len(mountpoints), mountpoints)
|
|
|
|
}
|