diff options
Diffstat (limited to 'tests/reverse')
-rw-r--r-- | tests/reverse/correctness_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/reverse/correctness_test.go b/tests/reverse/correctness_test.go index 4a5224c..8747a11 100644 --- a/tests/reverse/correctness_test.go +++ b/tests/reverse/correctness_test.go @@ -4,8 +4,10 @@ import ( "bytes" "fmt" "io/ioutil" + "log" "os" "path/filepath" + "strings" "syscall" "testing" @@ -293,3 +295,61 @@ func TestSeekData(t *testing.T) { } f.Close() } + +func findInum(dir string, inum uint64) (name string) { + entries, err := os.ReadDir(dir) + if err != nil { + panic(err) + } + for _, e := range entries { + info, _ := e.Info() + st := info.Sys().(*syscall.Stat_t) + if st.Ino == inum { + return dir + "/" + e.Name() + } + } + log.Panicf("inum %d not found", inum) + return "" +} + +// gocryptfs.longname.*.name of hardlinked files should not appear hardlinked (as the +// contents are different). +// +// https://github.com/rfjakob/gocryptfs/issues/802 +func TestHardlinkedLongname(t *testing.T) { + if plaintextnames { + t.Skip() + } + + workdir := dirA + "/" + t.Name() + if err := os.Mkdir(workdir, 0700); err != nil { + t.Fatal(err) + } + long1 := workdir + "/" + strings.Repeat("x", 200) + if err := ioutil.WriteFile(long1, []byte("hello"), 0600); err != nil { + t.Fatal(err) + } + long2 := workdir + "/" + strings.Repeat("y", 220) + if err := syscall.Link(long1, long2); err != nil { + t.Fatal(err) + } + + // Find workdir in encrypted view + var st syscall.Stat_t + if err := syscall.Stat(workdir, &st); err != nil { + t.Fatal(err) + } + cWorkdir := findInum(dirB, st.Ino) + t.Logf("workdir=%q cWorkdir=%q", workdir, cWorkdir) + + matches, err := filepath.Glob(cWorkdir + "/gocryptfs.longname.*.name") + if err != nil { + t.Fatal(err) + } + if len(matches) != 2 { + t.Fatalf("BUG: only %d matches, want 2", len(matches)) + } + if test_helpers.Md5fn(matches[0]) == test_helpers.Md5fn(matches[1]) { + t.Errorf("Files %q are identical - that's wrong!", matches) + } +} |