2018-08-11 23:26:49 +02:00
|
|
|
package reverse_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
2019-01-04 17:57:57 +01:00
|
|
|
"path/filepath"
|
2018-08-11 23:26:49 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-05-09 17:36:41 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
2019-01-04 17:57:57 +01:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
2018-08-11 23:26:49 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
|
|
|
)
|
|
|
|
|
|
|
|
const xxx = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
|
|
|
|
|
|
/*
|
|
|
|
tree exclude_test_fs
|
|
|
|
exclude_test_fs/
|
2019-02-16 21:55:54 +01:00
|
|
|
├── bkp1~
|
2018-08-11 23:26:49 +02:00
|
|
|
├── dir1
|
|
|
|
│ ├── file1
|
|
|
|
│ ├── file2
|
2019-02-16 21:55:54 +01:00
|
|
|
│ ├── exclude
|
|
|
|
│ ├── longbkp1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~
|
2018-08-11 23:26:49 +02:00
|
|
|
│ ├── longfile1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
2019-02-16 21:55:54 +01:00
|
|
|
│ ├── longfile2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
│ ├── longfile3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
│ └── subdir1
|
|
|
|
│ ├── exclude
|
|
|
|
│ └── subdir2
|
|
|
|
│ └── exclude
|
2018-08-11 23:26:49 +02:00
|
|
|
├── dir2
|
|
|
|
│ ├── file
|
|
|
|
│ ├── longdir1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
│ │ └── file
|
|
|
|
│ ├── longfile.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
│ └── subdir
|
|
|
|
│ └── file
|
|
|
|
├── file1
|
|
|
|
├── file2
|
|
|
|
├── longdir1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
2019-02-16 21:55:54 +01:00
|
|
|
│ └── file1
|
2018-08-11 23:26:49 +02:00
|
|
|
├── longdir2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
2019-02-16 21:55:54 +01:00
|
|
|
│ ├── bkp~
|
2018-08-11 23:26:49 +02:00
|
|
|
│ └── file
|
|
|
|
├── longfile1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
2019-02-16 21:55:54 +01:00
|
|
|
├── longfile2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
└── longfile3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
2018-08-11 23:26:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
func ctlsockEncryptPath(t *testing.T, sock string, path string) string {
|
|
|
|
req := ctlsock.RequestStruct{EncryptPath: path}
|
|
|
|
response := test_helpers.QueryCtlSock(t, sock, req)
|
|
|
|
if response.ErrNo != 0 {
|
|
|
|
t.Fatal(response)
|
|
|
|
}
|
|
|
|
return response.Result
|
|
|
|
}
|
|
|
|
|
2018-08-15 13:11:34 +02:00
|
|
|
func testExclude(t *testing.T, flag string) {
|
2019-02-16 21:55:54 +01:00
|
|
|
pPatterns := []string{
|
|
|
|
"file1", // matches file1 anywhere
|
|
|
|
"!longdir1" + xxx + "/file1", // ! includes an otherwise file
|
|
|
|
"file2/", // a trailing slash matches only a directory
|
|
|
|
"dir1/file2", // matches file2 inside dir1 anywhere
|
|
|
|
"#file2", // comments are ignored
|
|
|
|
"dir2", // excludes the whole directory
|
|
|
|
"longfile2" + xxx, // matches longfile2 anywhere
|
|
|
|
"/longfile3" + xxx, // a leading / anchors the match at the root
|
|
|
|
"*~", // wildcards are supported
|
|
|
|
"dir1/**/exclude", // ** matches any number of directories
|
|
|
|
}
|
2018-08-11 23:26:49 +02:00
|
|
|
pOk := []string{
|
|
|
|
"file2",
|
|
|
|
"dir1/longfile1" + xxx,
|
2019-02-16 21:55:54 +01:00
|
|
|
"dir1/longfile3" + xxx,
|
2018-08-11 23:26:49 +02:00
|
|
|
"longdir1" + xxx,
|
2019-02-16 21:55:54 +01:00
|
|
|
"longdir1" + xxx + "/file1",
|
|
|
|
"longdir2" + xxx + "/file",
|
2018-08-11 23:26:49 +02:00
|
|
|
"longfile1" + xxx,
|
|
|
|
}
|
|
|
|
pExclude := []string{
|
2019-02-16 21:55:54 +01:00
|
|
|
"bkp1~",
|
|
|
|
"dir1/file1",
|
2018-08-11 23:26:49 +02:00
|
|
|
"dir1/file2",
|
2019-02-16 21:55:54 +01:00
|
|
|
"dir1/exclude",
|
|
|
|
"dir1/longbkp1" + xxx + "~",
|
2018-08-11 23:26:49 +02:00
|
|
|
"dir1/longfile2" + xxx,
|
2019-02-16 21:55:54 +01:00
|
|
|
"dir1/subdir1/exclude",
|
|
|
|
"dir1/subdir1/subdir2/exclude",
|
2018-08-11 23:26:49 +02:00
|
|
|
"dir2",
|
|
|
|
"dir2/file",
|
|
|
|
"dir2/longdir1" + xxx + "/file",
|
|
|
|
"dir2/longfile." + xxx,
|
2019-02-16 21:55:54 +01:00
|
|
|
"dir2/subdir",
|
|
|
|
"dir2/subdir/file",
|
|
|
|
"file1",
|
|
|
|
"longdir2" + xxx + "/bkp~",
|
2018-08-11 23:26:49 +02:00
|
|
|
"longfile2" + xxx,
|
2019-02-16 21:55:54 +01:00
|
|
|
"longfile3" + xxx,
|
2018-08-11 23:26:49 +02:00
|
|
|
}
|
|
|
|
// Mount reverse fs
|
|
|
|
mnt, err := ioutil.TempDir(test_helpers.TmpDir, "TestExclude")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
sock := mnt + ".sock"
|
|
|
|
cliArgs := []string{"-reverse", "-extpass", "echo test", "-ctlsock", sock}
|
2019-02-16 21:55:54 +01:00
|
|
|
for _, v := range pPatterns {
|
2018-08-15 13:11:34 +02:00
|
|
|
cliArgs = append(cliArgs, flag, v)
|
2018-08-11 23:26:49 +02:00
|
|
|
}
|
|
|
|
if plaintextnames {
|
|
|
|
cliArgs = append(cliArgs, "-config", "exclude_test_fs/.gocryptfs.reverse.conf.plaintextnames")
|
|
|
|
}
|
|
|
|
test_helpers.MountOrFatal(t, "exclude_test_fs", mnt, cliArgs...)
|
|
|
|
defer test_helpers.UnmountPanic(mnt)
|
|
|
|
// Get encrypted version of "ok" and "excluded" paths
|
2019-01-04 17:57:57 +01:00
|
|
|
cOk := encryptExcludeTestPaths(t, sock, pOk)
|
|
|
|
cExclude := encryptExcludeTestPaths(t, sock, pExclude)
|
2018-08-11 23:26:49 +02:00
|
|
|
// Check that "excluded" paths are not there and "ok" paths are there
|
2019-01-04 17:57:57 +01:00
|
|
|
for _, v := range cExclude {
|
2020-08-15 17:31:25 +02:00
|
|
|
t.Logf("File %q should be invisible", v)
|
2020-08-15 15:39:08 +02:00
|
|
|
if test_helpers.VerifyExistence(t, mnt+"/"+v) {
|
2019-01-04 17:57:57 +01:00
|
|
|
t.Errorf("File %q is visible, but should be excluded", v)
|
|
|
|
}
|
|
|
|
if nametransform.IsLongContent(filepath.Base(v)) {
|
|
|
|
|
2018-08-11 23:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-04 17:57:57 +01:00
|
|
|
for _, v := range cOk {
|
2020-08-15 17:31:25 +02:00
|
|
|
t.Logf("File %q should be visible", v)
|
2020-08-15 15:39:08 +02:00
|
|
|
if !test_helpers.VerifyExistence(t, mnt+"/"+v) {
|
2019-01-04 17:57:57 +01:00
|
|
|
t.Errorf("File %q is hidden, but should be visible", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// encryptExcludeTestPaths is used by testExclude() to encrypt the lists of
|
|
|
|
// testcase paths
|
|
|
|
func encryptExcludeTestPaths(t *testing.T, socket string, pRelPaths []string) (out []string) {
|
|
|
|
for _, pRelPath := range pRelPaths {
|
|
|
|
cRelPath := ctlsockEncryptPath(t, socket, pRelPath)
|
|
|
|
out = append(out, cRelPath)
|
|
|
|
if !plaintextnames && nametransform.IsLongContent(filepath.Base(cRelPath)) {
|
|
|
|
// If we exclude
|
|
|
|
// gocryptfs.longname.3vZ_r3eDPb1_fL3j5VA4rd_bcKWLKT9eaxOVIGK5HFA
|
|
|
|
// we should also exclude
|
|
|
|
// gocryptfs.longname.3vZ_r3eDPb1_fL3j5VA4rd_bcKWLKT9eaxOVIGK5HFA.name
|
|
|
|
out = append(out, cRelPath+nametransform.LongNameSuffix)
|
2018-08-11 23:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-04 17:57:57 +01:00
|
|
|
return out
|
2018-08-11 23:26:49 +02:00
|
|
|
}
|
2018-08-15 13:11:34 +02:00
|
|
|
|
|
|
|
func TestExclude(t *testing.T) {
|
2019-02-16 21:55:54 +01:00
|
|
|
testExclude(t, "-exclude-wildcard")
|
|
|
|
testExclude(t, "-ew")
|
2018-08-15 13:11:34 +02:00
|
|
|
}
|