1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
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(t, "-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)
}
}
}
// Create & test fs with -reverse -longnamemax=100
func TestLongnamemax100Reverse(t *testing.T) {
backingDir := test_helpers.InitFS(t, "-reverse", "-longnamemax", "100")
mntDir := backingDir + ".mnt"
// Check config file sanity
_, c, err := configfile.LoadAndDecrypt(backingDir+"/"+configfile.ConfReverseName, 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(backingDir, mntDir, "-reverse", "-extpass", "echo test")
defer test_helpers.UnmountPanic(mntDir)
for l := 1; l <= 255; l++ {
path := backingDir + "/" + strings.Repeat("x", l)
if err := ioutil.WriteFile(path, nil, 0600); err != nil {
t.Fatal(err)
}
matches, err := filepath.Glob(mntDir + "/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)
}
}
}
|