blob: 938a6dde1f8d1920145ceee9c2b07522588d93f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#!/usr/bin/env bash
export test_description="Tests pass otp insert commands"
. ./setup.sh
test_expect_success 'Reads non-terminal input' '
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init &&
"$PASS" otp insert passfile <<< "$uri" &&
[[ $("$PASS" show passfile) == "$uri" ]]
'
test_expect_success 'Reads terminal input in noecho mode' '
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init
expect <<EOD
spawn "$PASS" otp insert passfile
expect {
"Enter" {
send "$uri\r"
exp_continue
}
"Retype" {
send "$uri\r"
exp_continue
}
eof
}
EOD
[[ $("$PASS" show passfile) == "$uri" ]]
'
test_expect_success 'Reads terminal input in echo mode' '
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init
expect <<EOD
spawn "$PASS" otp insert -e passfile
expect {
"Enter" {
send "$uri\r"
exp_continue
}
eof
}
EOD
[[ $("$PASS" show passfile) == "$uri" ]]
'
test_expect_success 'Prompts before overwriting key URI' '
uri1="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Foo"
uri2="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Bar"
test_pass_init
"$PASS" otp insert passfile <<< "$uri1" || return 1
expect <<EOD
spawn "$PASS" otp insert -e passfile
expect {
"Enter" {
send "$uri2\r"
exp_continue
}
"An entry already exists" {
send "n\r"
exp_continue
}
eof
}
EOD
[[ $("$PASS" show passfile) == "$uri1" ]]
'
test_expect_success 'Generates default pass-name from label' '
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init
"$PASS" otp insert <<< "$uri"
[[ $("$PASS" show "Example/alice@google.com") == "$uri" ]]
'
test_expect_success 'Prompts when inserting default pass-name from terminal' '
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init
expect <<EOD
spawn "$PASS" otp insert -e
expect {
"Enter" {
send "$uri\r"
exp_continue
}
"Insert into Example/alice@google.com?" {
send "y\r"
exp_continue
}
eof
}
EOD
[[ $("$PASS" show "Example/alice@google.com") == "$uri" ]]
'
test_expect_success 'Force overwrites key URI' '
uri1="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Foo"
uri2="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Bar"
test_pass_init &&
"$PASS" otp insert passfile <<< "$uri1" &&
"$PASS" otp insert -f passfile <<< "$uri2" &&
[[ $("$PASS" show passfile) == "$uri2" ]]
'
test_expect_success 'Insert passfile from secret with options(issuer, accountname)' '
secret="JBSWY3DPEHPK3PXP"
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init &&
"$PASS" otp insert -s -i Example -a alice@google.com passfile <<< "$secret" &&
echo [[ $("$PASS" show passfile) == "$uri" ]]
'
test_expect_success 'Insert from secret without passfile' '
secret="JBSWY3DPEHPK3PXP"
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init &&
"$PASS" otp insert -s -i Example -a alice@google.com <<< "$secret" &&
echo [[ $("$PASS" show Example/alice@google.com) == "$uri" ]]
'
test_expect_success 'Tolerates padding in secret' '
secret="JBSWY3DPEHPK3PXP=="
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init &&
"$PASS" otp insert -s -i Example -a alice@google.com <<< "$secret" &&
echo [[ $("$PASS" show Example/alice@google.com) == "$uri" ]]
'
test_expect_success 'Allow path prefixes in insert' '
secret="JBSWY3DPEHPK3PXP=="
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init &&
"$PASS" otp insert -s -p totp -i Example -a alice@google.com <<< "$secret" &&
echo [[ $("$PASS" show totp/Example/alice@google.com) == "$uri" ]]
'
test_expect_success 'Allow multiple levels in path prefix' '
secret="JBSWY3DPEHPK3PXP=="
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
test_pass_init &&
"$PASS" otp insert -s -p totp/pass-test -i Example -a alice@google.com <<< "$secret" &&
echo [[ $("$PASS" show totp/pass-test/Example/alice@google.com) == "$uri" ]]
'
test_done
|