-
Notifications
You must be signed in to change notification settings - Fork 48
/
client_test.go
114 lines (101 loc) · 2.46 KB
/
client_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
package snmpgo_test
import (
"math"
"testing"
"github.com/k-sone/snmpgo"
)
func TestSNMPArguments(t *testing.T) {
args := &snmpgo.SNMPArguments{Version: 2}
err := snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - version check")
}
args = &snmpgo.SNMPArguments{MessageMaxSize: -1}
err = snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - message size(min)")
}
// skip on 32 bit arch
if (^uint(0) >> 63) > 0 {
s := int64(math.MaxInt32) + 1
args = &snmpgo.SNMPArguments{MessageMaxSize: int(s)}
err = snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - message size(max)")
}
}
args = &snmpgo.SNMPArguments{Version: snmpgo.V3}
err = snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - user name")
}
args = &snmpgo.SNMPArguments{
Version: snmpgo.V3,
UserName: "MyName",
SecurityLevel: snmpgo.AuthNoPriv,
}
err = snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - auth password")
}
args = &snmpgo.SNMPArguments{
Version: snmpgo.V3,
UserName: "MyName",
SecurityLevel: snmpgo.AuthNoPriv,
AuthPassword: "aaaaaaaa",
}
err = snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - auth protocol")
}
args = &snmpgo.SNMPArguments{
Version: snmpgo.V3,
UserName: "MyName",
SecurityLevel: snmpgo.AuthPriv,
AuthPassword: "aaaaaaaa",
AuthProtocol: snmpgo.Md5,
}
err = snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - priv password")
}
args = &snmpgo.SNMPArguments{
Version: snmpgo.V3,
UserName: "MyName",
SecurityLevel: snmpgo.AuthPriv,
AuthPassword: "aaaaaaaa",
AuthProtocol: snmpgo.Md5,
PrivPassword: "bbbbbbbb",
}
err = snmpgo.ArgsValidate(args)
if err == nil {
t.Error("validate() - priv protocol")
}
args = &snmpgo.SNMPArguments{
Version: snmpgo.V3,
UserName: "MyName",
SecurityLevel: snmpgo.AuthPriv,
AuthPassword: "aaaaaaaa",
AuthProtocol: snmpgo.Md5,
PrivPassword: "bbbbbbbb",
PrivProtocol: snmpgo.Des,
}
err = snmpgo.ArgsValidate(args)
if err != nil {
t.Errorf("validate() - has error %v", err)
}
}
func TestSNMP(t *testing.T) {
_, err := snmpgo.NewSNMP(snmpgo.SNMPArguments{
Version: snmpgo.V3,
UserName: "MyName",
SecurityLevel: snmpgo.AuthPriv,
AuthPassword: "aaaaaaaa",
AuthProtocol: snmpgo.Md5,
PrivPassword: "bbbbbbbb",
PrivProtocol: snmpgo.Des,
})
if err != nil {
t.Error("checkPdu() - report oid")
}
}