summaryrefslogtreecommitdiff
path: root/tests/cli/longnamemax_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-10-21 15:58:19 +0200
committerJakob Unterwurzacher2021-10-21 15:58:19 +0200
commitd14c9340d6fb473e9837e91db8b6e869c37ad8e5 (patch)
tree253ba3c3db8a97ba7fdcd5d59b699db92da1cea2 /tests/cli/longnamemax_test.go
parentd583bdb79e6f05bce2451a7e220e553209da4c1d (diff)
cli: add -longnamemax
Fixes https://github.com/rfjakob/gocryptfs/issues/499
Diffstat (limited to 'tests/cli/longnamemax_test.go')
-rw-r--r--tests/cli/longnamemax_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/cli/longnamemax_test.go b/tests/cli/longnamemax_test.go
new file mode 100644
index 0000000..fc429f6
--- /dev/null
+++ b/tests/cli/longnamemax_test.go
@@ -0,0 +1,61 @@
+package cli
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "strings"
+ "syscall"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/v2/internal/configfile"
+
+ "github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
+)
+
+// Create & test fs with -longnamemax=100
+func TestLongnamemax100(t *testing.T) {
+ cDir := test_helpers.InitFS(nil, "-longnamemax", "100")
+ pDir := cDir + ".mnt"
+
+ // Check config file sanity
+ _, c, err := configfile.LoadAndDecrypt(cDir+"/"+configfile.ConfDefaultName, testPw)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ if !c.IsFeatureFlagSet(configfile.FlagLongNameMax) {
+ t.Error("FlagLongNameMax should be on")
+ }
+ if c.LongNameMax != 100 {
+ t.Errorf("LongNameMax=%d, want 100", c.LongNameMax)
+ }
+
+ // Check that it takes effect
+ test_helpers.MountOrExit(cDir, pDir, "-extpass", "echo test")
+ defer test_helpers.UnmountPanic(pDir)
+
+ for l := 1; l <= 255; l++ {
+ path := pDir + "/" + strings.Repeat("x", l)
+ if err := ioutil.WriteFile(path, nil, 0600); err != nil {
+ t.Fatal(err)
+ }
+ matches, err := filepath.Glob(cDir + "/gocryptfs.longname.*")
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = syscall.Unlink(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // As determined experimentally, a name of length >= 64 causes a longname
+ // to be created.
+ if l <= 63 && len(matches) != 0 {
+ t.Errorf("l=%d: should not see a longname yet", l)
+ }
+ if l >= 64 && len(matches) != 2 {
+ t.Errorf("l=%d: should see a longname now", l)
+ }
+ }
+}