forked from keybase/go-keychain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macos_1.10_test.go
45 lines (39 loc) · 1.01 KB
/
macos_1.10_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
// +build darwin,!ios
// +build go1.10
package keychain
import "testing"
func TestGenericPasswordRef(t *testing.T) {
service, account, label, accessGroup, password := "TestGenericPasswordRef", "test", "", "", "toomanysecrets"
item := NewGenericPassword(service, account, label, []byte(password), accessGroup)
defer func() { _ = DeleteItem(item) }()
err := AddItem(item)
if err != nil {
t.Fatal(err)
}
// Query reference and delete by reference
query := NewItem()
query.SetSecClass(SecClassGenericPassword)
query.SetService(service)
query.SetAccount(account)
query.SetMatchLimit(MatchLimitOne)
query.SetReturnRef(true)
ref, err := QueryItemRef(query)
if err != nil {
t.Fatal(err)
} else if ref == 0 {
t.Fatal("Missing result")
} else {
err = DeleteItemRef(ref)
if err != nil {
t.Fatal(err)
}
Release(ref)
}
passwordAfter, err := GetGenericPassword(service, account, label, accessGroup)
if err != nil {
t.Fatal(err)
}
if passwordAfter != nil {
t.Fatal("Shouldn't have password")
}
}