-
Notifications
You must be signed in to change notification settings - Fork 31
/
nition_test.go
141 lines (124 loc) · 3.27 KB
/
nition_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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package recog
import (
"os"
"testing"
)
func TestLoad(t *testing.T) {
fset, err := LoadFingerprints()
if err != nil {
t.Errorf("LoadFingerprints() failed: %s", err)
}
if len(fset.Databases) == 0 {
t.Errorf("LoadFingerprints() returned an empty set")
}
}
func TestLoadDir(t *testing.T) {
xmlPath := "./test/xml"
if v := os.Getenv("RECOG_XML"); v != "" {
xmlPath = v
}
fset, err := LoadFingerprintsDir(xmlPath)
if err != nil {
t.Errorf("LoadFingerprintsDir() failed: %s", err)
}
if len(fset.Databases) == 0 {
t.Errorf("LoadFingerprintsDir() returned an empty set")
}
}
func TestExamples(t *testing.T) {
fset, err := LoadFingerprints()
if err != nil {
t.Errorf("LoadFingerprints() failed")
return
}
if len(fset.Databases) == 0 {
t.Errorf("LoadFingerprints() returned an empty set")
return
}
for name, fdb := range fset.Databases {
err := fdb.VerifyExamples(".")
if err != nil {
t.Errorf("VerifyExamples() failed for %s: %s", name, err)
}
}
}
func TestPJL(t *testing.T) {
fset, err := LoadFingerprints()
if err != nil {
t.Errorf("LoadFingerprints() failed")
return
}
if len(fset.Databases) == 0 {
t.Errorf("LoadFingerprints() returned an empty set")
return
}
m := fset.MatchFirst("hp_pjl_id.xml", "Xerox ColorQube 8570DT")
if !m.Matched {
t.Errorf("Failed to match 'Xerox ColorQube 8570DT': %#v", m)
return
}
if m.Values["os.product"] != "8570DT" || m.Values["os.vendor"] != "Xerox" {
t.Errorf("Failed to match 'Xerox ColorQube 8570DT' expected product or vendor")
}
}
func TestPJLv2(t *testing.T) {
fset, err := LoadFingerprints()
if err != nil {
t.Errorf("LoadFingerprints() failed")
return
}
if len(fset.Databases) == 0 {
t.Errorf("LoadFingerprints() returned an empty set")
return
}
ms := fset.MatchAll("hp_pjl_id.xml", "Xerox ColorQube 8570DT")
if len(ms) == 0 {
t.Errorf("Failed to match 'Xerox ColorQube 8570DT'")
}
m := ms[0]
if !m.Matched {
t.Errorf("Failed to match 'Xerox ColorQube 8570DT'")
return
}
if m.Values["os.product"] != "8570DT" || m.Values["os.vendor"] != "Xerox" {
t.Errorf("Failed to match 'Xerox ColorQube 8570DT' expected product or vendor")
}
}
func TestHTMLTitle(t *testing.T) {
fset, err := LoadFingerprints()
if err != nil {
t.Errorf("LoadFingerprints() failed")
return
}
if len(fset.Databases) == 0 {
t.Errorf("LoadFingerprints() returned an empty set")
return
}
m := fset.MatchFirst("html_title.xml", "CloudKey")
if !m.Matched {
t.Errorf("Failed to match 'CloudKey': %#v", m)
return
}
if m.Values["hw.product"] != "UniFi Cloud Key" || m.Values["hw.vendor"] != "Ubiquiti" {
t.Errorf("Failed to match 'CloudKey' expected product or vendor")
}
}
func TestX509Subjects(t *testing.T) {
fset, err := LoadFingerprints()
if err != nil {
t.Errorf("LoadFingerprints() failed")
return
}
if len(fset.Databases) == 0 {
t.Errorf("LoadFingerprints() returned an empty set")
return
}
m := fset.MatchFirst("x509.subject", "CN=iDRACdefault0023AEF89AD1,OU=iDRAC Group,O=Dell Inc.,L=Round Rock,C=US")
if !m.Matched {
t.Errorf("Failed to match 'CN=iDRACdefault0023AEF89AD1,OU=iDRAC Group,O=Dell Inc.,L=Round Rock,C=US': %#v", m)
return
}
if m.Values["hw.product"] != "iDRAC" || m.Values["hw.vendor"] != "Dell" {
t.Errorf("Failed to match 'iDRAC' expected product or vendor")
}
}