-
Notifications
You must be signed in to change notification settings - Fork 3
/
keytab_test.go
75 lines (62 loc) · 1.45 KB
/
keytab_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
70
71
72
73
74
75
package gokrb5
import (
"fmt"
"testing"
"io/ioutil"
"encoding/base64"
)
const (
testServicePrinc = "http/localhost@LOCALHOST"
testKeytab = `BQIAAABLAAIACUxPQ0FMSE9TVAAEaHR0cAAJbG9jYWxob3N0AAAAAVggQiYEABIAIMkX5Jau//Xz
SwWZAlOucx0ROMl3BP6TVGD08H3CUbSOAAAAOwACAAlMT0NBTEhPU1QABGh0dHAACWxvY2FsaG9z
dAAAAAFYIEImBAARABBHkETIIzVpt/S7ZPdwiyJtAAAAQwACAAlMT0NBTEhPU1QABGh0dHAACWxv
Y2FsaG9zdAAAAAFYIEImBAAQABiAsIM4imsxpMhbjDgZbiDcRtV200ZdwiwAAAA7AAIACUxPQ0FM
SE9TVAAEaHR0cAAJbG9jYWxob3N0AAAAAVggQiYEABcAEDsDb3W9J7J8lXYcOwU3tHM=`
)
var _ = fmt.Println
func TestKeytab(t *testing.T) {
kctx, e := InitContext()
if e != nil {
t.Fatal(e)
}
file, err := ioutil.TempFile("","test_keytab_")
if err != nil {
t.Fatal(err)
}
data, err := base64.StdEncoding.DecodeString(testKeytab)
if err != nil {
t.Fatal(err)
}
_, err = file.Write(data)
if err != nil {
t.Fatal(err)
}
kt, err := kctx.KtResolve("FILE:" + file.Name())
if err != nil {
t.Fatal(err)
}
cursor, err := kt.StartSeqGet()
if err != nil {
t.Fatal(err)
}
for {
entry, err := kt.NextEntry(cursor)
if err != nil {
if kerr, ok := err.(ErrorCode); ok && kerr.Code() == KRB5_KT_END {
break
}
t.Fatal(err)
}
if entry == nil {
break
}
princ, err := entry.Principal()
if err != nil {
t.Fatal(err)
}
pstr := princ.String()
if pstr != testServicePrinc && entry.Kvno() != 4 {
t.Fatal("Unexpected principal keys in keytab: (kvno:%d) %s", pstr, entry.Kvno())
}
}
}