-
Notifications
You must be signed in to change notification settings - Fork 10
/
name_test.go
124 lines (105 loc) · 2.79 KB
/
name_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2014 Apcera Inc. All rights reserved.
package gssapi
import (
"testing"
)
// Tests importing exporting names
func TestNameImportExport(t *testing.T) {
l, err := testLoad()
if err != nil {
t.Fatal(err)
}
defer l.Unload()
names := []string{
`test@corp.example.com`,
`test@corp.ExAmple.com`,
`test@CORP.EXAMPLE.COM`,
}
makeName := func(n string) (name *Name) {
b, _ := l.MakeBufferString(n)
if err != nil {
t.Fatalf("%q: Got error %v, expected nil", n, err)
}
if b == nil {
t.Fatalf("%q: Got nil, expected non-nil", n)
}
defer b.Release()
name, err := b.Name(l.GSS_C_NT_HOSTBASED_SERVICE)
if err != nil {
t.Fatalf("%q: Got error %v, expected nil", n, err)
}
if name == nil {
t.Fatalf("%q: Got nil, expected non-nil", n)
}
return name
}
// Make the reference name
n0 := makeName(names[0])
defer n0.Release()
// Make sure we can have the krb mechanism, and normalize the reference
// name using it
mechs, err := n0.InquireMechs()
if err != nil {
//TODO: need a better test for OS X since this InquireMechs doesn't
// seem to work
t.Skipf("Couldn't get mechs for %q, error: %v", names[0], err.Error())
}
// This OID seems to be an avalable merch on linux
kerbOID, err := l.MakeOIDBytes([]byte{'\x2a', '\x86', '\x48', '\x86', '\xf7', '\x12', '\x01', '\x02', '\x02'})
if err != nil {
t.Fatalf("Got error %v, expected nil", err)
}
defer kerbOID.Release()
if !mechs.Contains(kerbOID) {
t.Fatalf("Expected %q to be in %q", kerbOID.DebugString(), mechs.DebugString())
}
makeNames := func(n string) (
name *Name, canonical *Name, display string, exported *Buffer) {
name = makeName(n)
if name == nil {
return nil, nil, "", nil
}
origDisplay, _, err := name.Display()
if err != nil {
t.Fatalf("Got error %q, expected nil", err.Error())
}
if origDisplay != n {
t.Fatalf("Got %q, expected %q", origDisplay, n)
}
canonical, err = name.Canonicalize(kerbOID)
if err != nil {
t.Fatalf("Got error %q, expected nil", err.Error())
}
if canonical == nil {
t.Fatal("Got nil, expected non-nil")
}
display, _, err = canonical.Display()
if err != nil {
t.Fatalf("Got error %q, expected nil", err.Error())
}
exported, err = canonical.Export()
if err != nil {
t.Fatalf("Got error %q, expected nil", err.Error())
}
if exported == nil {
t.Fatal("Got nil, expected non-nil")
}
return name, canonical, display, exported
}
n0, _, d0, e0 := makeNames(names[0])
if n0 == nil {
t.Fatal("Got nil, expected non-nil")
}
for _, n := range names {
n, _, d, e := makeNames(n)
if n == nil {
t.Fatalf("%s: Got nil, expected non-nil", n)
}
if d != d0 {
t.Fatalf("%s: Got %q, expected %q", n, d, d0)
}
if !e.Equal(e0) {
t.Fatalf("%s: Got %q, expected %q", n, e.String(), e0.String())
}
}
}