tests/reverse/TestExcludeTestFs: improve comments & code style

No functional changes.
This commit is contained in:
Jakob Unterwurzacher 2021-08-18 10:56:45 +02:00
parent 022c169c39
commit 884398eec3
1 changed files with 48 additions and 79 deletions

View File

@ -10,43 +10,6 @@ import (
"github.com/rfjakob/gocryptfs/tests/test_helpers" "github.com/rfjakob/gocryptfs/tests/test_helpers"
) )
const xxx = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/*
tree exclude_test_fs
exclude_test_fs/
bkp1~
dir1
file1
file2
exclude
longbkp1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~
longfile1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
longfile2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
*/
func ctlsockEncryptPath(t *testing.T, sock string, path string) string { func ctlsockEncryptPath(t *testing.T, sock string, path string) string {
req := ctlsock.RequestStruct{EncryptPath: path} req := ctlsock.RequestStruct{EncryptPath: path}
response := test_helpers.QueryCtlSock(t, sock, req) response := test_helpers.QueryCtlSock(t, sock, req)
@ -56,48 +19,53 @@ func ctlsockEncryptPath(t *testing.T, sock string, path string) string {
return response.Result return response.Result
} }
func testExclude(t *testing.T, flag string) { // doTestExcludeTestFs runs exclude tests against the exclude_test_fs folder
pPatterns := []string{ func doTestExcludeTestFs(t *testing.T, flag string) {
"file1", // matches file1 anywhere // --exclude-wildcard patterns, gitignore syntax
"!longdir1" + xxx + "/file1", // ! includes an otherwise file patterns := []string{
"file2/", // a trailing slash matches only a directory "file1", // matches file1 anywhere
"dir1/file2", // matches file2 inside dir1 anywhere "!longdir1" + x240 + "/file1", // ! includes an otherwise file
"#file2", // comments are ignored "file2/", // a trailing slash matches only a directory
"dir2", // excludes the whole directory "dir1/file2", // matches file2 inside dir1 anywhere
"longfile2" + xxx, // matches longfile2 anywhere "#file2", // comments are ignored
"/longfile3" + xxx, // a leading / anchors the match at the root "dir2", // excludes the whole directory
"*~", // wildcards are supported "longfile2" + x240, // matches longfile2 anywhere
"dir1/**/exclude", // ** matches any number of directories "/longfile3" + x240, // a leading / anchors the match at the root
"*~", // wildcards are supported
"dir1/**/exclude", // ** matches any number of directories
} }
pOk := []string{ // pVisible are plaintext paths that should be visible in the encrypted view
pVisible := []string{
"file2", "file2",
"dir1/longfile1" + xxx, "dir1/longfile1" + x240,
"dir1/longfile3" + xxx, "dir1/longfile3" + x240,
"longdir1" + xxx, "longdir1" + x240,
"longdir1" + xxx + "/file1", "longdir1" + x240 + "/file1",
"longdir2" + xxx + "/file", "longdir2" + x240 + "/file",
"longfile1" + xxx, "longfile1" + x240,
} }
pExclude := []string{ // pHidden are plaintext paths that should be hidden in the encrypted view
pHidden := []string{
"bkp1~", "bkp1~",
"dir1/file1", "dir1/file1",
"dir1/file2", "dir1/file2",
"dir1/exclude", "dir1/exclude",
"dir1/longbkp1" + xxx + "~", "dir1/longbkp1" + x240 + "~",
"dir1/longfile2" + xxx, "dir1/longfile2" + x240,
"dir1/subdir1/exclude", "dir1/subdir1/exclude",
"dir1/subdir1/subdir2/exclude", "dir1/subdir1/subdir2/exclude",
"dir2", "dir2",
"dir2/file", "dir2/file",
"dir2/longdir1" + xxx + "/file", "dir2/longdir1" + x240 + "/file",
"dir2/longfile." + xxx, "dir2/longfile." + x240,
"dir2/subdir", "dir2/subdir",
"dir2/subdir/file", "dir2/subdir/file",
"file1", "file1",
"longdir2" + xxx + "/bkp~", "longdir2" + x240 + "/bkp~",
"longfile2" + xxx, "longfile2" + x240,
"longfile3" + xxx, "longfile3" + x240,
} }
// Mount reverse fs // Mount reverse fs
mnt, err := ioutil.TempDir(test_helpers.TmpDir, "TestExclude") mnt, err := ioutil.TempDir(test_helpers.TmpDir, "TestExclude")
if err != nil { if err != nil {
@ -105,7 +73,7 @@ func testExclude(t *testing.T, flag string) {
} }
sock := mnt + ".sock" sock := mnt + ".sock"
cliArgs := []string{"-reverse", "-extpass", "echo test", "-ctlsock", sock} cliArgs := []string{"-reverse", "-extpass", "echo test", "-ctlsock", sock}
for _, v := range pPatterns { for _, v := range patterns {
cliArgs = append(cliArgs, flag, v) cliArgs = append(cliArgs, flag, v)
} }
if plaintextnames { if plaintextnames {
@ -113,28 +81,28 @@ func testExclude(t *testing.T, flag string) {
} }
test_helpers.MountOrFatal(t, "exclude_test_fs", mnt, cliArgs...) test_helpers.MountOrFatal(t, "exclude_test_fs", mnt, cliArgs...)
defer test_helpers.UnmountPanic(mnt) defer test_helpers.UnmountPanic(mnt)
// Get encrypted version of "ok" and "excluded" paths
cOk := encryptExcludeTestPaths(t, sock, pOk) // Get encrypted version of visible and hidden paths
cExclude := encryptExcludeTestPaths(t, sock, pExclude) cVisible := encryptExcludeTestPaths(t, sock, pVisible)
// Check that "excluded" paths are not there and "ok" paths are there cHidden := encryptExcludeTestPaths(t, sock, pHidden)
for _, v := range cExclude {
t.Logf("File %q should be invisible", v) // Check that hidden paths are not there and visible paths are there
for _, v := range cHidden {
if test_helpers.VerifyExistence(t, mnt+"/"+v) { if test_helpers.VerifyExistence(t, mnt+"/"+v) {
t.Errorf("File %q is visible, but should be excluded", v) t.Errorf("File %q is visible, but should be hidden", v)
} }
if nametransform.IsLongContent(filepath.Base(v)) { if nametransform.IsLongContent(filepath.Base(v)) {
// TODO ???
} }
} }
for _, v := range cOk { for _, v := range cVisible {
t.Logf("File %q should be visible", v)
if !test_helpers.VerifyExistence(t, mnt+"/"+v) { if !test_helpers.VerifyExistence(t, mnt+"/"+v) {
t.Errorf("File %q is hidden, but should be visible", v) t.Errorf("File %q is hidden, but should be visible", v)
} }
} }
} }
// encryptExcludeTestPaths is used by testExclude() to encrypt the lists of // encryptExcludeTestPaths is used by doTestExcludeTestFs() to encrypt the lists of
// testcase paths // testcase paths
func encryptExcludeTestPaths(t *testing.T, socket string, pRelPaths []string) (out []string) { func encryptExcludeTestPaths(t *testing.T, socket string, pRelPaths []string) (out []string) {
for _, pRelPath := range pRelPaths { for _, pRelPath := range pRelPaths {
@ -151,7 +119,8 @@ func encryptExcludeTestPaths(t *testing.T, socket string, pRelPaths []string) (o
return out return out
} }
func TestExclude(t *testing.T) { // TestExcludeTestFs runs exclude tests against the exclude_test_fs folder.
testExclude(t, "-exclude-wildcard") func TestExcludeTestFs(t *testing.T) {
testExclude(t, "-ew") doTestExcludeTestFs(t, "-exclude-wildcard")
doTestExcludeTestFs(t, "-ew")
} }