summaryrefslogtreecommitdiff
path: root/internal/readpassword/extpass_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/readpassword/extpass_test.go')
-rw-r--r--internal/readpassword/extpass_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/readpassword/extpass_test.go b/internal/readpassword/extpass_test.go
new file mode 100644
index 0000000..6eda142
--- /dev/null
+++ b/internal/readpassword/extpass_test.go
@@ -0,0 +1,55 @@
+package readpassword
+
+import (
+ "os"
+ "os/exec"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/internal/toggledlog"
+)
+
+func TestMain(m *testing.M) {
+ // Shut up info output
+ toggledlog.Info.Enabled = false
+ m.Run()
+}
+
+func TestExtpass(t *testing.T) {
+ p1 := "ads2q4tw41reg52"
+ p2 := readPasswordExtpass("echo " + p1)
+ if p1 != p2 {
+ t.Errorf("p1=%q != p2=%q", p1, p2)
+ }
+}
+
+func TestOnceExtpass(t *testing.T) {
+ p1 := "lkadsf0923rdfi48rqwhdsf"
+ p2 := Once("echo " + p1)
+ if p1 != p2 {
+ t.Errorf("p1=%q != p2=%q", p1, p2)
+ }
+}
+
+func TestTwiceExtpass(t *testing.T) {
+ p1 := "w5w44t3wfe45srz434"
+ p2 := Once("echo " + p1)
+ if p1 != p2 {
+ t.Errorf("p1=%q != p2=%q", p1, p2)
+ }
+}
+
+// When extpass returns an empty string, we should crash.
+// https://talks.golang.org/2014/testing.slide#23
+func TestExtpassEmpty(t *testing.T) {
+ if os.Getenv("TEST_SLAVE") == "1" {
+ readPasswordExtpass("echo")
+ return
+ }
+ cmd := exec.Command(os.Args[0], "-test.run=TestExtpassEmpty$")
+ cmd.Env = append(os.Environ(), "TEST_SLAVE=1")
+ err := cmd.Run()
+ if err != nil {
+ return
+ }
+ t.Fatal("empty password should have failed")
+}