@@ -26,21 +26,78 @@ func TestInsert(t *testing.T) {
26
26
t .Run ("Regression test for #1573 without actual pipes" , func (t * testing.T ) {
27
27
out , err = ts .run ("show -f some/secret" )
28
28
assert .NoError (t , err )
29
- assert .Equal (t , out , "Password: moar" )
29
+ assert .Equal (t , "Password: moar" , out )
30
30
31
31
out , err = ts .run ("show -f some/newsecret" )
32
32
assert .NoError (t , err )
33
- assert .Equal (t , out , "Password: and\n \n moar" )
33
+ assert .Equal (t , "Password: and\n \n moar" , out )
34
34
35
35
_ , err := ts .run ("config mime false" )
36
36
assert .NoError (t , err )
37
37
38
38
out , err = ts .run ("show -f some/secret" )
39
39
assert .NoError (t , err )
40
- assert .Equal (t , out , "moar" )
40
+ assert .Equal (t , "moar" , out )
41
41
42
42
out , err = ts .run ("show -f some/newsecret" )
43
43
assert .NoError (t , err )
44
- assert .Equal (t , out , "and\n \n moar" )
44
+ assert .Equal (t , "and\n \n moar" , out )
45
+ })
46
+
47
+ t .Run ("Regression test for #1595" , func (t * testing.T ) {
48
+ _ , err = ts .runCmd ([]string {ts .Binary , "insert" , "some/other" }, []byte ("nope" ))
49
+ assert .NoError (t , err )
50
+
51
+ out , err = ts .run ("insert some/other" )
52
+ assert .Error (t , err )
53
+ assert .Equal (t , "\n Error: not overwriting your current secret\n " , out )
54
+
55
+ out , err = ts .run ("show -o some/other" )
56
+ assert .NoError (t , err )
57
+ assert .Equal (t , "nope" , out )
58
+
59
+ out , err = ts .run ("--yes insert some/other" )
60
+ assert .NoError (t , err )
61
+ assert .Equal (t , "Warning: Password is empty or all whitespace" , out )
62
+
63
+ out , err = ts .run ("insert -f some/other" )
64
+ assert .NoError (t , err )
65
+ assert .Equal (t , "Warning: Password is empty or all whitespace" , out )
66
+
67
+ out , err = ts .run ("show -o some/other" )
68
+ assert .Error (t , err )
69
+ assert .Equal (t , "\n Error: empty secret\n " , out )
70
+
71
+ _ , err = ts .runCmd ([]string {ts .Binary , "insert" , "-f" , "some/other" }, []byte ("final" ))
72
+ assert .NoError (t , err )
73
+
74
+ out , err = ts .run ("show -o some/other" )
75
+ assert .NoError (t , err )
76
+ assert .Equal (t , "final" , out )
77
+
78
+ // This is arguably not a good behaviour: it should not overwrite the password when we are only working on a key:value.
79
+ out , err = ts .run ("insert -f some/other test:inline" )
80
+ assert .NoError (t , err )
81
+ assert .Equal (t , "" , out )
82
+
83
+ out , err = ts .run ("show some/other Test" )
84
+ assert .NoError (t , err )
85
+ assert .Equal (t , "inline" , out )
86
+
87
+ out , err = ts .run ("insert some/other test:inline2" )
88
+ assert .Error (t , err )
89
+ assert .Equal (t , "\n Error: not overwriting your current secret\n " , out )
90
+
91
+ out , err = ts .run ("show some/other Test" )
92
+ assert .NoError (t , err )
93
+ assert .Equal (t , "inline" , out )
94
+
95
+ out , err = ts .run ("--yes insert some/other test:inline2" )
96
+ assert .NoError (t , err )
97
+ assert .Equal (t , "" , out )
98
+
99
+ out , err = ts .run ("show some/other Test" )
100
+ assert .NoError (t , err )
101
+ assert .Equal (t , "inline2" , out )
45
102
})
46
103
}
0 commit comments