-
Notifications
You must be signed in to change notification settings - Fork 1
/
site_test.go
133 lines (106 loc) · 2.66 KB
/
site_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
package main
import (
"io/ioutil"
"testing"
"github.com/keltia/ssllabs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewTLSSite(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)
tls := NewTLSSite(all[0])
require.NotEmpty(t, tls)
}
func TestNewTLSSite1(t *testing.T) {
tls := NewTLSSite(ssllabs.Host{})
require.Empty(t, tls)
}
func TestInitAPI(t *testing.T) {
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = true
initAPIs()
assert.Empty(t, fnMozilla(ssllabs.Host{}))
assert.Empty(t, fnImirhil(ssllabs.Host{}))
}
func TestInitAPI1(t *testing.T) {
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = false
initAPIs()
assert.Empty(t, fnMozilla(ssllabs.Host{}))
g := fnImirhil(ssllabs.Host{})
assert.NotEmpty(t, g)
assert.Equal(t, "Z", g)
}
func TestInitAPI2(t *testing.T) {
// Simulate
fIgnoreMozilla = false
fIgnoreImirhil = true
initAPIs()
assert.Empty(t, fnMozilla(ssllabs.Host{}))
assert.Empty(t, fnImirhil(ssllabs.Host{}))
}
func TestInitAPI3(t *testing.T) {
// Simulate
fIgnoreMozilla = false
fIgnoreImirhil = false
initAPIs()
assert.Empty(t, fnMozilla(ssllabs.Host{}))
g := fnImirhil(ssllabs.Host{})
assert.NotEmpty(t, g)
assert.Equal(t, "Z", g)
}
func TestTLSSite_HasExpiredTrue(t *testing.T) {
tm := int64(1536423013000)
assert.True(t, hasExpired(tm))
}
func TestTLSSite_HasExpiredFalse(t *testing.T) {
tm := int64(1855828800000)
assert.False(t, hasExpired(tm))
}
func TestDisplayWildcards(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)
str := displayWildcards(all)
assert.NotEmpty(t, str)
}
func TestSweet32(t *testing.T) {
ji, err := ioutil.ReadFile("testdata/reallybad.json")
require.NoError(t, err)
// Simulate
fIgnoreMozilla = true
fIgnoreImirhil = true
bad, err := ssllabs.ParseResults(ji)
require.NoError(t, err)
assert.True(t, checkSweet32(bad[0].Endpoints[0].Details))
}
const (
mozURL = "https://http-observatory.security.mozilla.org/api/v1"
)
func TestFindServerTypeEmpty(t *testing.T) {
tt := findServerType(ssllabs.Host{})
require.Equal(t, TypeHTTP, tt)
}
func TestFindServerType(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)
tt := findServerType(all[0])
require.Equal(t, TypeHTTP, tt)
}