-
Notifications
You must be signed in to change notification settings - Fork 1
/
categories_test.go
151 lines (116 loc) · 3.18 KB
/
categories_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
142
143
144
145
146
147
148
149
150
151
package main
import (
"io/ioutil"
"testing"
"github.com/keltia/ssllabs"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
)
func TestDisplayCategories(t *testing.T) {
cntrs := map[string]int{
"A": 666,
"B": 0,
"G": 1,
}
str := displayCategories(cntrs)
assert.NotEmpty(t, str)
}
func TestHTTPCountsNil(t *testing.T) {
cntrs := httpCounts(nil)
assert.Empty(t, cntrs)
}
func TestHTTPCountsEmpty(t *testing.T) {
cntrs := httpCounts(&TLSReport{})
assert.NotEmpty(t, cntrs)
assert.EqualValues(t, map[string]int{"Total": 0, "Broken": 0}, cntrs)
}
func TestHTTPCountsReport(t *testing.T) {
ji, err := ioutil.ReadFile("testdata/site.json")
require.NoError(t, err)
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = true
all, err := ssllabs.ParseResults(ji)
require.NoError(t, err)
sites, err := NewTLSReport(all)
require.NoError(t, err)
require.NotEmpty(t, sites)
// Fake it
sites.Sites[0].Mozilla = "A+"
cntrs := httpCounts(sites)
assert.NotEmpty(t, cntrs)
assert.EqualValues(t, map[string]int{"A+": 1, "Total": 1, "Broken": 1}, cntrs)
}
func TestHTTPCountsReport_1(t *testing.T) {
ji, err := ioutil.ReadFile("testdata/site.json")
require.NoError(t, err)
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = true
all, err := ssllabs.ParseResults(ji)
require.NoError(t, err)
sites, err := NewTLSReport(all)
require.NoError(t, err)
require.NotEmpty(t, sites)
// Fake it
sites.Sites[0].Mozilla = "H"
cntrs := httpCounts(sites)
assert.NotEmpty(t, cntrs)
assert.EqualValues(t, map[string]int{"H": 1, "Total": 0, "Broken": 1}, cntrs)
}
func TestCategoryCountsNil(t *testing.T) {
cntrs := categoryCounts(nil)
assert.Empty(t, cntrs)
}
func TestCategoryCountsEmpty(t *testing.T) {
cntrs := categoryCounts([]ssllabs.Host{})
assert.NotEmpty(t, cntrs)
assert.EqualValues(t, map[string]int{"Total": 0, "X": 0, "Z": 0}, cntrs)
}
func TestCategoryCountsReport(t *testing.T) {
ji, err := ioutil.ReadFile("testdata/site.json")
require.NoError(t, err)
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = true
all, err := ssllabs.ParseResults(ji)
require.NoError(t, err)
good := map[string]int{
"OCSP": 1, "Total": 1, "X": 0, "": 1, "Issues": 1,
"HSTS": 1, "Z": 1, "A+": 1, "PFS": 1,
}
cntrs := categoryCounts(all)
assert.NotEmpty(t, cntrs)
assert.EqualValues(t, good, cntrs)
}
func TestCategoryCountsReportDES(t *testing.T) {
ji, err := ioutil.ReadFile("testdata/reallybad.json")
require.NoError(t, err)
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = true
all, err := ssllabs.ParseResults(ji)
require.NoError(t, err)
good := map[string]int{
"OCSP": 1, "Total": 1, "X": 0, "Issues": 1,
"HSTS": 1, "Z": 0, "A+": 1, "PFS": 1, "Sweet32": 1,
}
cntrs := categoryCounts(all)
assert.NotEmpty(t, cntrs)
assert.EqualValues(t, good, cntrs)
}
func TestCategoryCountsReportNull(t *testing.T) {
ji, err := ioutil.ReadFile("testdata/null.json")
require.NoError(t, err)
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = true
all, err := ssllabs.ParseResults(ji)
require.NoError(t, err)
good := map[string]int{
"X": 1, "Z": 0, "Total": 0,
}
cntrs := categoryCounts(all)
assert.NotEmpty(t, cntrs)
assert.EqualValues(t, good, cntrs)
}