forked from jsipprell/keyctl
-
Notifications
You must be signed in to change notification settings - Fork 4
/
keyring_test.go
50 lines (43 loc) · 854 Bytes
/
keyring_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
package keyctl
import (
"testing"
)
func TestAdd100BytesToSessionKeyring(t *testing.T) {
ring, err := SessionKeyring()
if err != nil {
t.Fatal(err)
}
key, err := ring.Add("blank", make([]byte, 100))
if err != nil {
t.Fatal(err)
}
t.Logf("added 100 byte empty key as: %v\n", key.Id())
buf, err := key.Get()
if err != nil {
t.Fatal(err)
}
t.Logf("read %d octets from key: %v\n", len(buf), buf)
}
func TestFetchKeyFail(t *testing.T) {
ring, err := SessionKeyring()
if err != nil {
t.Fatal(err)
}
_, err = ring.Search("abigbunchofnonsense")
if err == nil {
t.Fatal("search expected to fail")
}
}
func TestUnlinkKey(t *testing.T) {
ring, err := SessionKeyring()
if err != nil {
t.Fatal(err)
}
key, err := ring.Search("blank")
if err != nil {
t.Fatal(err)
}
if err = key.Unlink(); err != nil {
t.Fatal(err)
}
}