-
Notifications
You must be signed in to change notification settings - Fork 0
/
oid_test.go
110 lines (94 loc) · 2.4 KB
/
oid_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
package dirsyn
/*
NOTE: a bulk of the desirable test cases are already handled in
JesseCoretta/go-objectid, which is imported.
*/
import (
"testing"
)
func TestOID(t *testing.T) {
var r RFC4512
for idx, raw := range []string{
`1.3.6.1.4.1.56521`,
`cn`,
`2.5.4.3`,
`l`,
} {
if err := r.OID(raw); err != nil {
t.Errorf("%s[%d] failed: %v\n", t.Name(), idx, err)
}
}
}
func TestNumericOID(t *testing.T) {
var r RFC4512
for idx, raw := range []string{
`1.3.6.1.4.1.56521`,
`2.5.4.3`,
} {
if _, err := r.NumericOID(raw); err != nil {
t.Errorf("%s[%d] failed: %v\n", t.Name(), idx, err)
}
}
}
func TestDescriptor(t *testing.T) {
var r RFC4512
for idx, raw := range []string{
`cn`,
`sn`,
`randomAttr-v2`,
`l`,
`n`,
} {
if _, err := r.Descriptor(raw); err != nil {
t.Errorf("%s[%d] failed: %v\n", t.Name(), idx, err)
}
}
}
func TestOID_codecov(t *testing.T) {
var x RFC4517
x.NumericOID(`2.5.4.3`)
x.Descriptor(`cn`)
x.Descriptor(`cn#`)
x.Descriptor(`c--n`)
x.Descriptor(`c@n`)
result, err := objectIdentifierMatch(`2.5.4.3`, `2.5.4.3`)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !result.True() {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), `TRUE`, result)
}
result, err = objectIdentifierMatch(`2.5.4.3`, `2.5.4.0`)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !result.False() {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), `FALSE`, result)
}
_, _ = objectIdentifierMatch(`2.5.4.3`, struct{}{})
_, _ = objectIdentifierMatch(struct{}{}, struct{}{})
type fakeType struct {
Id string
}
fake := fakeType{`2.5.4.3`}
result, err = objectIdentifierFirstComponentMatch(fake, `2.5.4.3`)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !result.True() {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), `TRUE`, result)
}
type bogusType struct {
Id int
}
_, _ = objectIdentifierFirstComponentMatch(nil, `.`)
_, _ = objectIdentifierFirstComponentMatch(`2.3.4.5`, `1.2.3.4`)
_, _ = objectIdentifierFirstComponentMatch(bogusType{5}, `.`)
_, _ = objectIdentifierFirstComponentMatch(DITStructureRuleDescription{RuleID: `4`}, `4`)
_, _ = objectIdentifierFirstComponentMatch(fakeType{`descr`}, `2.5.4.3`)
_, _ = objectIdentifierFirstComponentMatch(fakeType{`descr`}, nil)
_, _ = objectIdentifierFirstComponentMatch(fakeType{`descr`}, `2..4.3`)
}