forked from simonmittag/j8a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy_test.go
86 lines (76 loc) · 1.56 KB
/
proxy_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 jabba
import (
"crypto/tls"
"fmt"
"net/http"
"testing"
"time"
)
func TestAbortAllUpstreamAttempts(t *testing.T) {
Runner = mockRuntime()
want := true
got := false
mockAtmpt := func() Atmpt {
return Atmpt{
URL: nil,
Label: "",
Count: 1,
StatusCode: 0,
isGzip: false,
resp: nil,
respBody: nil,
CompleteHeader: nil,
CompleteBody: nil,
Aborted: nil,
AbortedFlag: false,
CancelFunc: func() {
fmt.Println("cancelfunc called")
got = true
},
startDate: time.Now(),
}
}
atmpt := mockAtmpt()
proxy := Proxy{
XRequestID: "",
XRequestDebug: false,
Up: Up{
Atmpts: []Atmpt{mockAtmpt()},
Atmpt: &atmpt,
},
Dwn: Down{
Req: nil,
Resp: Resp{},
Method: "",
Path: "",
URI: "",
UserAgent: "",
Body: nil,
Aborted: nil,
AbortedFlag: false,
startDate: time.Now(),
},
}
proxy.abortAllUpstreamAttempts()
if want != got {
t.Errorf("cancel func on proxy upstream attempt not triggered")
}
}
func TestParseTlsVersionV12(t *testing.T) {
req, _ := http.NewRequest("GET", "/hello", nil)
req.TLS = &tls.ConnectionState{
Version: tls.VersionTLS12,
}
if "TLS1.2" != parseTlsVersion(req) {
t.Errorf("wrong TLS version")
}
}
func TestParseTlsVersionV13(t *testing.T) {
req, _ := http.NewRequest("GET", "/hello", nil)
req.TLS = &tls.ConnectionState{
Version: tls.VersionTLS13,
}
if "TLS1.3" != parseTlsVersion(req) {
t.Errorf("wrong TLS version")
}
}