-
Notifications
You must be signed in to change notification settings - Fork 20
/
cipher_suites_test.go
86 lines (82 loc) · 1.74 KB
/
cipher_suites_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
package bmc
import (
"testing"
"github.com/gebn/bmc/pkg/ipmi"
"github.com/google/go-cmp/cmp"
)
func TestParseCipherSuiteRecordData(t *testing.T) {
tests := []struct {
in []byte
want []ipmi.CipherSuiteRecord // nil if error
}{
// missing auth algo
{
in: []byte{
0xc0, 0x00,
},
},
// integrity and confidentiality implicitly "none"
{
[]byte{
0xc0, 0x00, 0x00,
},
[]ipmi.CipherSuiteRecord{
{},
},
},
// everything explicitly specified, still "none"
{
[]byte{
0xc0, 0x00, 0x00, 0x40, 0x80,
},
[]ipmi.CipherSuiteRecord{
{},
},
},
// second record truncated after start of record
{
in: []byte{
0xc0, 0x00, 0x00, 0x40, 0x80,
0xc0,
},
},
// second record truncated after cipher suite ID
{
in: []byte{
0xc0, 0x00, 0x00, 0x40, 0x80,
0xc0, 0x00,
},
},
{
[]byte{
0xc0, 0x11, 0x03, 0x44, 0x81, // cipher suite 17
0xc1, 0x16, 0x00, 0x01, 0x02, 0x01, 0x41, 0x81, // OEM equivalent of cipher suite 3
},
[]ipmi.CipherSuiteRecord{
{
CipherSuiteID: 17,
CipherSuite: ipmi.CipherSuite17,
},
{
CipherSuiteID: 22,
CipherSuite: ipmi.CipherSuite3,
Enterprise: 0x020100,
},
},
},
}
for _, test := range tests {
got, err := parseCipherSuiteRecordData(test.in)
if err != nil && test.want != nil {
t.Errorf("parseCipherSuiteRecordData(%v) failed with %v, wanted %v", test.in, err, test.want)
continue
}
if err == nil && test.want == nil {
t.Errorf("parseCipherSuiteRecordData(%v) returned %v, wanted error", test.in, got)
continue
}
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("parseCipherSuiteRecordData(%v) returned %v, want %v: %v", test.in, got, test.want, diff)
}
}
}