This repository was archived by the owner on Mar 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathosxkeychain_test.go
69 lines (67 loc) · 2.15 KB
/
osxkeychain_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
62
63
64
65
66
67
68
69
package osxkeychain
import (
"testing"
)
func TestInternetPassword(t *testing.T) {
passwordVal := "longfakepassword with invalid UTF-8 \xc3\x28 and \000 embedded nuls \000"
accountNameVal := "bgentry"
serverNameVal := "go-osxkeychain-test.example.com"
securityDomainVal := ""
portVal := 886
pathVal := "/fake"
pass := InternetPassword{
ServerName: serverNameVal,
SecurityDomain: securityDomainVal,
AccountName: accountNameVal,
Port: portVal,
Path: pathVal,
Protocol: ProtocolHTTPS,
AuthType: AuthenticationHTTPBasic,
Password: passwordVal,
}
// Add the password
err := AddInternetPassword(&pass)
if err != nil {
t.Error(err)
}
// Try adding again, expect it to fail as a duplicate
err = AddInternetPassword(&pass)
if err != ErrDuplicateItem {
t.Errorf("expected ErrDuplicateItem on 2nd save, got %s", err)
}
// Find the password
pass2 := InternetPassword{
ServerName: serverNameVal,
Path: pathVal,
Protocol: ProtocolHTTPS,
AuthType: AuthenticationHTTPBasic,
}
resp, err := FindInternetPassword(&pass2)
if err != nil {
t.Error(err)
}
if resp.Password != passwordVal {
t.Errorf("FindInternetPassword expected Password=%s, got %s", passwordVal, resp.Password)
}
if resp.AccountName != accountNameVal {
t.Errorf("FindInternetPassword expected AccountName=%q, got %q", accountNameVal, resp.AccountName)
}
if resp.ServerName != serverNameVal {
t.Errorf("FindInternetPassword expected ServerName=%q, got %q", serverNameVal, resp.ServerName)
}
if resp.SecurityDomain != securityDomainVal {
t.Errorf("FindInternetPassword expected SecurityDomain=%q, got %q", securityDomainVal, resp.SecurityDomain)
}
if resp.Protocol != ProtocolHTTPS {
t.Errorf("FindInternetPassword expected Protocol=https, got %q", resp.Protocol)
}
if resp.Port != portVal {
t.Errorf("FindInternetPassword expected Port=%d, got %d", portVal, resp.Port)
}
if resp.AuthType != AuthenticationHTTPBasic {
t.Errorf("FindInternetPassword expected AuthType=HTTPBasic, got %q", resp.AuthType)
}
if resp.Path != pathVal {
t.Errorf("FindInternetPassword expected Path=%q, got %q", pathVal, resp.Path)
}
}