2016-06-15 22:43:31 +02:00
|
|
|
package readpassword
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-08-23 15:05:15 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/tlog"
|
2016-06-15 22:43:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
// Shut up info output
|
2016-06-15 23:30:44 +02:00
|
|
|
tlog.Info.Enabled = false
|
2016-06-16 21:56:23 +02:00
|
|
|
os.Exit(m.Run())
|
2016-06-15 22:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestExtpass(t *testing.T) {
|
|
|
|
p1 := "ads2q4tw41reg52"
|
2022-01-03 15:18:59 +01:00
|
|
|
p2, err := readPasswordExtpass([]string{"echo " + p1})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if p1 != string(p2) {
|
|
|
|
t.Errorf("p1=%q != p2=%q", p1, string(p2))
|
2016-06-15 22:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOnceExtpass(t *testing.T) {
|
|
|
|
p1 := "lkadsf0923rdfi48rqwhdsf"
|
2022-01-03 15:18:59 +01:00
|
|
|
p2, err := Once([]string{"echo " + p1}, nil, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if p1 != string(p2) {
|
|
|
|
t.Errorf("p1=%q != p2=%q", p1, string(p2))
|
2019-03-03 13:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// extpass with two arguments
|
|
|
|
func TestOnceExtpass2(t *testing.T) {
|
|
|
|
p1 := "foo"
|
2022-01-03 15:18:59 +01:00
|
|
|
p2, err := Once([]string{"echo", p1}, nil, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if p1 != string(p2) {
|
|
|
|
t.Errorf("p1=%q != p2=%q", p1, string(p2))
|
2019-03-03 13:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// extpass with three arguments
|
|
|
|
func TestOnceExtpass3(t *testing.T) {
|
|
|
|
p1 := "foo bar baz"
|
2022-01-03 15:18:59 +01:00
|
|
|
p2, err := Once([]string{"echo", "foo", "bar", "baz"}, nil, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if p1 != string(p2) {
|
|
|
|
t.Errorf("p1=%q != p2=%q", p1, string(p2))
|
2019-03-03 13:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOnceExtpassSpaces(t *testing.T) {
|
|
|
|
p1 := "mypassword"
|
2022-01-03 15:18:59 +01:00
|
|
|
p2, err := Once([]string{"cat", "passfile_test_files/file with spaces.txt"}, nil, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if p1 != string(p2) {
|
|
|
|
t.Errorf("p1=%q != p2=%q", p1, string(p2))
|
2016-06-15 22:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwiceExtpass(t *testing.T) {
|
|
|
|
p1 := "w5w44t3wfe45srz434"
|
2022-01-03 15:18:59 +01:00
|
|
|
p2, err := Once([]string{"echo " + p1}, nil, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if p1 != string(p2) {
|
|
|
|
t.Errorf("p1=%q != p2=%q", p1, string(p2))
|
2016-06-15 22:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:18:59 +01:00
|
|
|
// Empty extpass should fail
|
2016-06-15 22:43:31 +02:00
|
|
|
func TestExtpassEmpty(t *testing.T) {
|
2022-01-03 15:18:59 +01:00
|
|
|
_, err := readPasswordExtpass([]string{"echo"})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("empty password should have failed")
|
2016-06-15 22:43:31 +02:00
|
|
|
}
|
|
|
|
}
|