Skip to content

Commit

Permalink
tetss: reverse: add TestHardlinkedLongname
Browse files Browse the repository at this point in the history
Regression test for #802 .
Fails at the moment.
  • Loading branch information
rfjakob committed May 1, 2024
1 parent 1b3fb29 commit 210c5c5
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/reverse/correctness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"syscall"
"testing"

Expand Down Expand Up @@ -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)
}
}

0 comments on commit 210c5c5

Please sign in to comment.