summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-06-21 11:48:16 +0200
committerJakob Unterwurzacher2021-06-21 11:48:16 +0200
commite244b514913a31293eac1dc728f5b1026ab84b98 (patch)
tree6566c28f7c7fee3c7c0f2ccf54a9bf039db908e1 /tests
parent6b0e63c1a86946de23f549e7d80ea933a4a105f8 (diff)
tests: cli: add TestZerokey
TestZerokey verifies that `gocryptfs -zerokey` uses the same options as `gocryptfs -init`.
Diffstat (limited to 'tests')
-rw-r--r--tests/cli/zerokey.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/cli/zerokey.go b/tests/cli/zerokey.go
new file mode 100644
index 0000000..b809d1f
--- /dev/null
+++ b/tests/cli/zerokey.go
@@ -0,0 +1,60 @@
+package cli
+
+import (
+ "io/ioutil"
+ "os"
+ "os/exec"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/tests/test_helpers"
+)
+
+// TestZerokey verifies that `gocryptfs -zerokey` uses the same options as
+// `gocryptfs -init`.
+func TestZerokey(t *testing.T) {
+ // Create FS
+ dir := test_helpers.InitFS(t)
+
+ // Change masterkey to all-zero using password change
+ args := []string{"-q", "-passwd", "-masterkey",
+ "00000000-00000000-00000000-00000000-00000000-00000000-00000000-00000000"}
+ args = append(args, dir)
+ cmd := exec.Command(test_helpers.GocryptfsBinary, args...)
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ p, err := cmd.StdinPipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = cmd.Start()
+ if err != nil {
+ t.Error(err)
+ }
+ // New password = old password
+ p.Write([]byte("test\n"))
+ p.Close()
+ err = cmd.Wait()
+ if err != nil {
+ t.Error(err)
+ }
+
+ // Add content
+ mnt := dir + ".mnt"
+ test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo test")
+ file1 := mnt + "/file1"
+ err = ioutil.WriteFile(file1, []byte("somecontent"), 0600)
+ if err != nil {
+ t.Fatal(err)
+ }
+ test_helpers.UnmountPanic(mnt)
+
+ // Mount using -zerokey and verify we get the same result
+ test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo test")
+ content, err := ioutil.ReadFile(file1)
+ if err != nil {
+ t.Error(err)
+ } else if string(content) != "somecontent" {
+ t.Errorf("wrong content: %q", string(content))
+ }
+ test_helpers.UnmountPanic(mnt)
+}