forked from fcjr/aia-transport-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport_test.go
110 lines (106 loc) · 2.37 KB
/
transport_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
package aia_test
import (
"net/http"
"testing"
"github.com/jonee/aia-transport-go"
)
func TestTransport(t *testing.T) {
// test against badssl.com
testCases := []struct {
URL string
ErrExpected bool
}{
{
URL: "https://incomplete-chain.badssl.com/",
ErrExpected: false, // THIS IS THE TRUE TEST
},
{
URL: "https://expired.badssl.com/",
ErrExpected: true,
},
{
URL: "https://wrong.host.badssl.com/",
ErrExpected: true,
},
{
URL: "https://self-signed.host.badssl.com/",
ErrExpected: true,
},
{
URL: "https://untrusted-root.badssl.com/",
ErrExpected: true,
},
// TODO: go does not check revoked
// {
// URL: "https://revoked.badssl.com/",
// ErrExpected: true,
// },
// TODO: go does not check for this test
// {
// URL: "https://pinning-test.badssl.com/",
// ErrExpected: true,
// },
{
URL: "https://mitm-software.badssl.com/",
ErrExpected: true,
},
{
URL: "https://webpack-dev-server.badssl.com/",
ErrExpected: true,
},
{
URL: "https://preact-cli.badssl.com/",
ErrExpected: true,
},
{
URL: "https://dsdtestprovider.badssl.com/",
ErrExpected: true,
},
{
URL: "https://edellroot.badssl.com/",
ErrExpected: true,
},
{
URL: "https://superfish.badssl.com/",
ErrExpected: true,
},
{
URL: "https://long-extended-subdomain-name-containing-many-letters-and-dashes.badssl.com/",
ErrExpected: false,
},
{
URL: "https://longextendedsubdomainnamewithoutdashesinordertotestwordwrapping.badssl.com/",
ErrExpected: false,
},
{
URL: "https://https-everywhere.badssl.com/",
ErrExpected: false,
},
{
URL: "https://preloaded-hsts.badssl.com/",
ErrExpected: false,
},
{
URL: "https://tls-v1-2.badssl.com:1012/",
ErrExpected: false,
},
}
tr, err := aia.NewTransport()
if err != nil {
t.Fatalf("failed to build transport")
}
client := http.Client{
Transport: tr,
}
for _, tc := range testCases {
_, err := client.Get(tc.URL)
if err != nil && !tc.ErrExpected {
t.Errorf("%s: err not expected but got: %s", tc.URL, err.Error())
} else if err != nil {
t.Log(err.Error())
}
if err == nil && tc.ErrExpected {
t.Errorf("%s: expected error but request succeeded!", tc.URL)
}
}
}