c86981342b
Everything except the if err2.Err == syscall.EOPNOTSUPP case. Gets too confusing when collapsed into a single line. Issues were: $ golangci-lint run --disable-all --enable gosimple mount.go:473:2: S1008: should use 'return strings.HasPrefix(v, "fusermount version")' instead of 'if strings.HasPrefix(v, "fusermount version") { return true }; return false' (gosimple) if strings.HasPrefix(v, "fusermount version") { ^ cli_args.go:258:5: S1002: should omit comparison to bool constant, can be simplified to `args.forcedecode` (gosimple) if args.forcedecode == true { ^ cli_args.go:263:6: S1002: should omit comparison to bool constant, can be simplified to `args.aessiv` (gosimple) if args.aessiv == true { ^ cli_args.go:267:6: S1002: should omit comparison to bool constant, can be simplified to `args.reverse` (gosimple) if args.reverse == true { ^ internal/stupidgcm/stupidgcm.go:227:6: S1002: should omit comparison to bool constant, can be simplified to `g.forceDecode` (gosimple) if g.forceDecode == true { ^ gocryptfs-xray/xray_tests/xray_test.go:23:5: S1004: should use !bytes.Equal(out, expected) instead (gosimple) if bytes.Compare(out, expected) != 0 { ^ gocryptfs-xray/xray_tests/xray_test.go:40:5: S1004: should use !bytes.Equal(out, expected) instead (gosimple) if bytes.Compare(out, expected) != 0 { ^ gocryptfs-xray/paths_ctlsock.go:34:20: S1002: should omit comparison to bool constant, can be simplified to `!eof` (gosimple) for eof := false; eof == false; line++ { ^ tests/reverse/xattr_test.go:19:2: S1008: should use 'return err2.Err != syscall.EOPNOTSUPP' instead of 'if err2.Err == syscall.EOPNOTSUPP { return false }; return true' (gosimple) if err2.Err == syscall.EOPNOTSUPP { ^ internal/fusefrontend/node.go:459:45: S1002: should omit comparison to bool constant, can be simplified to `!nameFileAlreadyThere` (gosimple) if nametransform.IsLongContent(cName2) && nameFileAlreadyThere == false { ^ tests/xattr/xattr_integration_test.go:221:2: S1008: should use 'return err2.Err != syscall.EOPNOTSUPP' instead of 'if err2.Err == syscall.EOPNOTSUPP { return false }; return true' (gosimple) if err2.Err == syscall.EOPNOTSUPP { ^ tests/test_helpers/helpers.go:338:19: S1002: should omit comparison to bool constant, can be simplified to `open` (gosimple) if err != nil && open == true { ^ tests/matrix/concurrency_test.go:121:7: S1004: should use !bytes.Equal(buf, content) instead (gosimple) if bytes.Compare(buf, content) != 0 { ^
111 lines
2.3 KiB
Go
111 lines
2.3 KiB
Go
package xray_tests
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os/exec"
|
|
"testing"
|
|
|
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
|
)
|
|
|
|
func TestAesgcmXray(t *testing.T) {
|
|
expected, err := ioutil.ReadFile("aesgcm_fs.xray.txt")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cmd := exec.Command("../gocryptfs-xray", "aesgcm_fs/VnvoeSetPaOFjZDaZAh0lA")
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(out, expected) {
|
|
t.Errorf("Unexpected output")
|
|
fmt.Printf("expected:\n%s", string(expected))
|
|
fmt.Printf("have:\n%s", string(out))
|
|
}
|
|
}
|
|
|
|
func TestAessivXray(t *testing.T) {
|
|
expected, err := ioutil.ReadFile("aessiv_fs.xray.txt")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cmd := exec.Command("../gocryptfs-xray", "-aessiv", "aessiv_fs/klepPXQJIaEDaIx-yurAqQ")
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(out, expected) {
|
|
t.Errorf("Unexpected output")
|
|
fmt.Printf("expected:\n%s", string(expected))
|
|
fmt.Printf("have:\n%s", string(out))
|
|
}
|
|
}
|
|
|
|
func TestDumpmasterkey(t *testing.T) {
|
|
expected := "b4d8b25c324dd6eaa328c9906e8a2a3c6038552a042ced4326cfff210c62957a\n"
|
|
cmd := exec.Command("../gocryptfs-xray", "-dumpmasterkey", "aesgcm_fs/gocryptfs.conf")
|
|
// Password = "test"
|
|
cmd.Stdin = bytes.NewBuffer([]byte("test"))
|
|
out1, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := string(out1)
|
|
if out != expected {
|
|
t.Errorf("Wrong output")
|
|
fmt.Printf("expected: %s\n", expected)
|
|
fmt.Printf("have: %s\n", out)
|
|
}
|
|
}
|
|
|
|
func TestEncryptPaths(t *testing.T) {
|
|
cDir := test_helpers.InitFS(t)
|
|
pDir := cDir + ".mnt"
|
|
sock := cDir + ".sock"
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-ctlsock="+sock, "-extpass", "echo test")
|
|
defer test_helpers.UnmountPanic(pDir)
|
|
|
|
testCases := []struct {
|
|
in []string
|
|
sep0 bool
|
|
}{
|
|
{
|
|
[]string{
|
|
"test1",
|
|
"test1\n",
|
|
"test1\ntest2",
|
|
"test1\ntest2\n",
|
|
},
|
|
false,
|
|
},
|
|
{
|
|
[]string{
|
|
"test1",
|
|
"test1\000",
|
|
"test1\000test2",
|
|
"test1\000test2\000",
|
|
},
|
|
true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
for _, in := range tc.in {
|
|
sepArg := "-0=false"
|
|
if tc.sep0 {
|
|
sepArg = "-0=true"
|
|
}
|
|
cmd := exec.Command("../gocryptfs-xray", "-encrypt-paths", sepArg, sock)
|
|
cmd.Stdin = bytes.NewBuffer([]byte(in))
|
|
out, err := cmd.CombinedOutput()
|
|
t.Logf("%q", string(out))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
}
|