forked from browserpass/browserpass-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browserpass_test.go
61 lines (48 loc) · 1.28 KB
/
browserpass_test.go
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
package browserpass
import (
"strings"
"testing"
"github.com/gokyle/twofactor"
)
func TestParseLogin(t *testing.T) {
r := strings.NewReader("password\n\nfoo\nlogin: bar")
login, err := parseLogin(r)
if err != nil {
t.Fatal(err)
}
if login.Password != "password" {
t.Errorf("Password is %s, expected %s", login.Password, "password")
}
if login.Username != "bar" {
t.Errorf("Username is %s, expected %s", login.Username, "bar")
}
}
func TestOtp(t *testing.T) {
r := strings.NewReader("password\n\nfoo\nlogin: bar\notpauth://totp/totp-secret?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=test")
login, err := parseLogin(r)
if err != nil {
t.Fatal(err)
}
if login.OTPLabel != "totp-secret" {
t.Errorf("OTPLabel is '%s', expected '%s'", login.OTPLabel, "totp-secret")
}
o, err := twofactor.NewGoogleTOTP("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ")
if err != nil {
t.Error(err)
}
otp := o.OTP()
if login.OTP != otp {
t.Errorf("OTP is %s, expected %s", login.OTP, otp)
}
}
func TestGuessUsername(t *testing.T) {
tests := map[string]string{
"foo": "",
"foo/bar": "bar",
}
for input, expected := range tests {
if username := guessUsername(input); username != expected {
t.Errorf("guessUsername(%s): expected %s, got %s", input, expected, username)
}
}
}