From c03fc46a5150715bf6aee20ce4b89d9704141220 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 10 Nov 2016 23:32:51 +0100 Subject: ctlsock: implement EncryptPath for reverse mode, add tests --- .../.gocryptfs.reverse.conf | 19 ++++++++ tests/reverse/ctlsock_reverse_test_fs/dir/dir/file | 0 tests/reverse/ctlsock_reverse_test_fs/dir/file | 0 ...xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 0 tests/reverse/ctlsock_reverse_test_fs/file | 0 .../file | 0 ...xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 0 tests/reverse/ctlsock_test.go | 52 ++++++++++++++++++++++ tests/reverse/main_test.go | 3 +- 9 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tests/reverse/ctlsock_reverse_test_fs/.gocryptfs.reverse.conf create mode 100644 tests/reverse/ctlsock_reverse_test_fs/dir/dir/file create mode 100644 tests/reverse/ctlsock_reverse_test_fs/dir/file create mode 100644 tests/reverse/ctlsock_reverse_test_fs/dir/longfile.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx create mode 100644 tests/reverse/ctlsock_reverse_test_fs/file create mode 100644 tests/reverse/ctlsock_reverse_test_fs/longdir.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/file create mode 100644 tests/reverse/ctlsock_reverse_test_fs/longfile.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx create mode 100644 tests/reverse/ctlsock_test.go (limited to 'tests/reverse') diff --git a/tests/reverse/ctlsock_reverse_test_fs/.gocryptfs.reverse.conf b/tests/reverse/ctlsock_reverse_test_fs/.gocryptfs.reverse.conf new file mode 100644 index 0000000..9bd9259 --- /dev/null +++ b/tests/reverse/ctlsock_reverse_test_fs/.gocryptfs.reverse.conf @@ -0,0 +1,19 @@ +{ + "Creator": "gocryptfs v1.1.1-16-g75ebb28-dirty", + "EncryptedKey": "cE5bhCZl1iL1tn0dNLh8aQy8n55NMbojmmkwM8iM8/y0uChO0CGaK16sNHffAKJ++qH287JlCpk/BFyi", + "ScryptObject": { + "Salt": "yUxEmtl4KeUkCxL8b6aYcEGVtFe2NAlwy0WsFLt8p+Y=", + "N": 1024, + "R": 8, + "P": 1, + "KeyLen": 32 + }, + "Version": 2, + "FeatureFlags": [ + "GCMIV128", + "DirIV", + "EMENames", + "LongNames", + "AESSIV" + ] +} diff --git a/tests/reverse/ctlsock_reverse_test_fs/dir/dir/file b/tests/reverse/ctlsock_reverse_test_fs/dir/dir/file new file mode 100644 index 0000000..e69de29 diff --git a/tests/reverse/ctlsock_reverse_test_fs/dir/file b/tests/reverse/ctlsock_reverse_test_fs/dir/file new file mode 100644 index 0000000..e69de29 diff --git a/tests/reverse/ctlsock_reverse_test_fs/dir/longfile.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx b/tests/reverse/ctlsock_reverse_test_fs/dir/longfile.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx new file mode 100644 index 0000000..e69de29 diff --git a/tests/reverse/ctlsock_reverse_test_fs/file b/tests/reverse/ctlsock_reverse_test_fs/file new file mode 100644 index 0000000..e69de29 diff --git a/tests/reverse/ctlsock_reverse_test_fs/longdir.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/file b/tests/reverse/ctlsock_reverse_test_fs/longdir.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/file new file mode 100644 index 0000000..e69de29 diff --git a/tests/reverse/ctlsock_reverse_test_fs/longfile.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx b/tests/reverse/ctlsock_reverse_test_fs/longfile.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx new file mode 100644 index 0000000..e69de29 diff --git a/tests/reverse/ctlsock_test.go b/tests/reverse/ctlsock_test.go new file mode 100644 index 0000000..0e4a29b --- /dev/null +++ b/tests/reverse/ctlsock_test.go @@ -0,0 +1,52 @@ +package reverse_test + +import ( + "io/ioutil" + "testing" + + "github.com/rfjakob/gocryptfs/internal/ctlsock" + "github.com/rfjakob/gocryptfs/tests/test_helpers" +) + +var ctlSockTestCases = [][]string{ + {"4RQq1dJlfvQPaVU5Xypf0w==", "file"}, + {"gocryptfs.longname.ZQCAoi5li3xvDZRO8McBV0L_kzJc4IcAOEzuW-2S1Y4=", "longfile." + x240}, + {"v6puXntoQOk7Mhl8zJ4Idg==", "dir"}, + {"v6puXntoQOk7Mhl8zJ4Idg==/UVy2gV0RQTUC8AE4wYoMwg==", "dir/file"}, + {"v6puXntoQOk7Mhl8zJ4Idg==/fvHFLHlxHCQ7EpVMJu0AZg==", "dir/dir"}, + {"v6puXntoQOk7Mhl8zJ4Idg==/fvHFLHlxHCQ7EpVMJu0AZg==/_4uudIGniACke55JoDsqDA==", "dir/dir/dir"}, + {"v6puXntoQOk7Mhl8zJ4Idg==/fvHFLHlxHCQ7EpVMJu0AZg==/QvPahkkeVRKTw2kdZFZxwQ==", "dir/dir/file"}, + {"v6puXntoQOk7Mhl8zJ4Idg==/gocryptfs.longname.y6rxCn6Id8hIZL2t_STpdLZpu-aE2HpprJR25xD60mk=", "dir/longfile." + x240}, + {"gocryptfs.longname.cvRximo1ATRJVEzw_V9MZieHFlod9y2iv2Sug1kbiTE=", "longdir." + x240}, + {"gocryptfs.longname.cvRximo1ATRJVEzw_V9MZieHFlod9y2iv2Sug1kbiTE=/-LMdFgFt6UxO-z5iJvuC9w==", "longdir." + x240 + "/dir"}, + {"gocryptfs.longname.cvRximo1ATRJVEzw_V9MZieHFlod9y2iv2Sug1kbiTE=/rBPJYAzcHWLdPj1T8kgh8A==", "longdir." + x240 + "/file"}, +} + +func TestCtlSockDecryptPath(t *testing.T) { + mnt, err := ioutil.TempDir(test_helpers.TmpDir, "reverse_mnt_") + if err != nil { + t.Fatal(err) + } + sock := mnt + ".sock" + test_helpers.MountOrFatal(t, "ctlsock_reverse_test_fs", mnt, "-reverse", "-extpass", "echo test", "-ctlsock="+sock) + defer test_helpers.UnmountPanic(mnt) + var req ctlsock.RequestStruct + for i, tc := range ctlSockTestCases { + // Decrypt + req = ctlsock.RequestStruct{DecryptPath: tc[0]} + response := test_helpers.QueryCtlSock(t, sock, req) + if response.ErrNo != 0 { + t.Errorf("Testcase %d Decrypt: %q ErrNo=%d ErrText=%s", i, tc[0], response.ErrNo, response.ErrText) + } else if response.Result != tc[1] { + t.Errorf("Testcase %d Decrypt: Want %q got %q", i, tc[1], response.Result) + } + // Encrypt + req = ctlsock.RequestStruct{EncryptPath: tc[1]} + response = test_helpers.QueryCtlSock(t, sock, req) + if response.ErrNo != 0 { + t.Errorf("Testcase %d Encrypt: %q ErrNo=%d ErrText=%s", i, tc[0], response.ErrNo, response.ErrText) + } else if response.Result != tc[0] { + t.Errorf("Testcase %d Encrypt: Want %q got %q", i, tc[1], response.Result) + } + } +} diff --git a/tests/reverse/main_test.go b/tests/reverse/main_test.go index a2b7eb6..be6016f 100644 --- a/tests/reverse/main_test.go +++ b/tests/reverse/main_test.go @@ -9,11 +9,10 @@ import ( ) var dirA, dirB, dirC string -var x240 string +var x240 = string(bytes.Repeat([]byte("x"), 240)) var plaintextnames bool func TestMain(m *testing.M) { - x240 = string(bytes.Repeat([]byte("x"), 240)) var r int for _, plaintextnames = range []bool{false, true} { argsA := []string{"-reverse"} -- cgit v1.2.3