Debian Codegraph @

packets/dot11_types_test.go

raw symbols SCIP
1 package packets
2
3 import (
4 "reflect"
5 "testing"
6 )
7
8 func TestDot11CipherTypes(t *testing.T) {
9 var units = []struct {
10 got interface{}
11 exp interface{}
12 }{
13 {uint8(Dot11CipherWep), uint8(1)},
14 {uint8(Dot11CipherTkip), uint8(2)},
15 {uint8(Dot11CipherWrap), uint8(3)},
16 {uint8(Dot11CipherCcmp), uint8(4)},
17 {uint8(Dot11CipherWep104), uint8(5)},
18 }
19 for _, u := range units {
20 if !reflect.DeepEqual(u.exp, u.got) {
21 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
22 }
23 }
24 }
25
26 func TestDot11CipherTypesAsString(t *testing.T) {
27 var units = []struct {
28 got interface{}
29 exp interface{}
30 }{
31 {Dot11CipherWep.String(), "WEP"},
32 {Dot11CipherTkip.String(), "TKIP"},
33 {Dot11CipherWrap.String(), "WRAP"},
34 {Dot11CipherCcmp.String(), "CCMP"},
35 {Dot11CipherWep104.String(), "WEP104"},
36 }
37 for _, u := range units {
38 if !reflect.DeepEqual(u.exp, u.got) {
39 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
40 }
41 }
42 }
43
44 func TestDot11AuthTypes(t *testing.T) {
45 var units = []struct {
46 got interface{}
47 exp interface{}
48 }{
49 {uint8(Dot11AuthMgt), uint8(1)},
50 {uint8(Dot11AuthPsk), uint8(2)},
51 }
52 for _, u := range units {
53 if !reflect.DeepEqual(u.exp, u.got) {
54 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
55 }
56 }
57 }
58
59 func TestDot11AuthTypesAsString(t *testing.T) {
60 var units = []struct {
61 got interface{}
62 exp interface{}
63 }{
64 {Dot11AuthMgt.String(), "MGT"},
65 {Dot11AuthPsk.String(), "PSK"},
66 }
67 for _, u := range units {
68 if !reflect.DeepEqual(u.exp, u.got) {
69 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
70 }
71 }
72 }
73
74 func TestDot11CipherSuite(t *testing.T) {
75 // must be three, but not currently
76 // implemented to really enforce [3]byte
77 bytes := []byte{1, 2, 3}
78 cs := CipherSuite{
79 OUI: bytes,
80 }
81 var units = []struct {
82 got interface{}
83 exp interface{}
84 }{
85 {cs.OUI, bytes},
86 }
87 for _, u := range units {
88 if !reflect.DeepEqual(u.exp, u.got) {
89 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
90 }
91 }
92 }
93
94 func TestDot11AuthSuite(t *testing.T) {
95 // must be three, but not currently
96 // implemented to really enforce [3]byte
97 bytes := []byte{1, 2, 3}
98 cs := AuthSuite{
99 OUI: bytes,
100 }
101 var units = []struct {
102 got interface{}
103 exp interface{}
104 }{
105 {cs.OUI, bytes},
106 }
107 for _, u := range units {
108 if !reflect.DeepEqual(u.exp, u.got) {
109 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
110 }
111 }
112 }
113
114 func TestDot11CipherSuiteSelector(t *testing.T) {
115 count := uint16(1)
116 cs := CipherSuiteSelector{
117 Count: count,
118 }
119 var units = []struct {
120 got interface{}
121 exp interface{}
122 }{
123 {cs.Count, count},
124 }
125 for _, u := range units {
126 if !reflect.DeepEqual(u.exp, u.got) {
127 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
128 }
129 }
130 }
131
132 func TestDot11AuthSuiteSelector(t *testing.T) {
133 count := uint16(1)
134 cs := AuthSuiteSelector{
135 Count: count,
136 }
137 var units = []struct {
138 got interface{}
139 exp interface{}
140 }{
141 {cs.Count, count},
142 }
143 for _, u := range units {
144 if !reflect.DeepEqual(u.exp, u.got) {
145 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
146 }
147 }
148 }
149
150 func TestDot11RSNInfo(t *testing.T) {
151 version := uint16(1)
152 rsn := RSNInfo{
153 Version: version,
154 }
155 var units = []struct {
156 got interface{}
157 exp interface{}
158 }{
159 {rsn.Version, version},
160 {rsn.Group, CipherSuite{}},
161 {rsn.Pairwise, CipherSuiteSelector{}},
162 {rsn.AuthKey, AuthSuiteSelector{}},
163 }
164 for _, u := range units {
165 if !reflect.DeepEqual(u.exp, u.got) {
166 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
167 }
168 }
169 }
170
171 func TestDot11VendorInfo(t *testing.T) {
172 version := uint16(1)
173 vendor := VendorInfo{
174 WPAVersion: version,
175 }
176 var units = []struct {
177 got interface{}
178 exp interface{}
179 }{
180 {vendor.WPAVersion, version},
181 {vendor.Multicast, CipherSuite{}},
182 {vendor.Unicast, CipherSuiteSelector{}},
183 {vendor.AuthKey, AuthSuiteSelector{}},
184 }
185 for _, u := range units {
186 if !reflect.DeepEqual(u.exp, u.got) {
187 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
188 }
189 }
190 }
191
192 func TestDot11canParse(t *testing.T) {
193 err := canParse("example", []byte{}, 0)
194 if err != nil {
195 t.Error("unable to check if able to parse")
196 }
197 }
198
199 func TestDot11parsePairwiseSuite(t *testing.T) {
200 buf := []byte{0, 0, 1, 1}
201 suite, err := parsePairwiseSuite(buf)
202 var units = []struct {
203 got interface{}
204 exp interface{}
205 }{
206 {suite.OUI, buf[0:3]},
207 {suite.Type, Dot11CipherType(buf[3])},
208 {err, nil},
209 }
210 for _, u := range units {
211 if !reflect.DeepEqual(u.exp, u.got) {
212 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
213 }
214 }
215 }
216
217 func TestDot11parseAuthkeySuite(t *testing.T) {
218 buf := []byte{0, 0, 1, 1}
219 suite, err := parseAuthkeySuite(buf)
220 var units = []struct {
221 got interface{}
222 exp interface{}
223 }{
224 {suite.OUI, buf[0:3]},
225 {suite.Type, Dot11AuthType(buf[3])},
226 {err, nil},
227 }
228 for _, u := range units {
229 if !reflect.DeepEqual(u.exp, u.got) {
230 t.Fatalf("expected '%v', got '%v'", u.exp, u.got)
231 }
232 }
233 }
234
235 // TODO: add test for Dot11InformationElementVendorInfoDecode
236 // TODO: add test for Dot11InformationElementIDDSSetDecode