aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2024-05-01 22:24:24 +0200
committerJakob Unterwurzacher2024-05-01 22:24:24 +0200
commit210c5c512a7e363d1ada9de2b405463166ec940a (patch)
treee9a0e6496aac60e773f147c9fd80aa61cfaecfff
parent1b3fb29ba4d05cc3863c1fe1a76c591a0982fc22 (diff)
tetss: reverse: add TestHardlinkedLongname
Regression test for https://github.com/rfjakob/gocryptfs/issues/802 . Fails at the moment.
-rw-r--r--tests/reverse/correctness_test.go60
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)
+ }
+}