summaryrefslogtreecommitdiff
path: root/gocryptfs-xray/xray_tests/xray_test.go
blob: 6dc7c1367e8d1427581afafe6bf8b7cdb74d80e9 (plain)
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
108
109
110
package xray_tests

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os/exec"
	"testing"

	"github.com/rfjakob/gocryptfs/v2/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)
			}
		}
	}
}