forked from browserpass/browserpass-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browserpass_test.go
51 lines (41 loc) · 1.09 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
package main
import (
"os"
"testing"
"bytes"
)
func TestGetLogins(t *testing.T) {
domain := "this-most-definitely-does-not-exist"
logins := getLogins(domain)
if len(logins) > 0 {
t.Errorf("%s yielded results, but it should not", domain)
}
}
func TestGetPasswordStoreDir(t *testing.T) {
var home, expected, actual string
home = os.Getenv("HOME")
// default directory
os.Setenv("PASSWORD_STORE_DIR", "")
expected = home + "/.password-store/"
actual = getPasswordStoreDir()
if expected != actual {
t.Errorf("%s does not match %s", expected, actual)
}
// custom directory
expected = "/my/custom/dir"
os.Setenv("PASSWORD_STORE_DIR", expected)
actual = getPasswordStoreDir()
if expected != actual {
t.Errorf("%s does not match %s", expected, actual)
}
}
func TestParseLogin(t *testing.T) {
var b = bytes.NewBufferString("password\n\nfoo\nlogin: bar")
login := parseLogin(b)
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")
}
}