-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserver_test.go
255 lines (217 loc) · 16.3 KB
/
server_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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package j8a
import (
"crypto/tls"
"github.com/rs/zerolog"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"
)
// takes 76μs to load a certificate that's way too long to do every incoming request.
func BenchmarkLoadTlsCert(b *testing.B) {
certPem := "-----BEGIN CERTIFICATE-----\nMIIEkzCCAvugAwIBAgIRANiwkh9AuRgrvYh7Y5DtWIUwDQYJKoZIhvcNAQELBQAw\ngYExHjAcBgNVBAoTFW1rY2VydCBkZXZlbG9wbWVudCBDQTErMCkGA1UECwwic2lt\nb25taXR0YWdAdHJvb3BlciAoU2ltb24gTWl0dGFnKTEyMDAGA1UEAwwpbWtjZXJ0\nIHNpbW9ubWl0dGFnQHRyb29wZXIgKFNpbW9uIE1pdHRhZykwHhcNMTkwNjAxMDAw\nMDAwWhcNMzAwNzMwMDExNDU5WjB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3kmXhTcq2bJn3FJ289ULon0\nhXd4ZDRGIAJ1EYADqyv7TkppI0MStBt+UqdbtG/NBIPqAOxFjRmw47JgcHR6oKgR\nqYSxSbAGFhW6Zi9ocPY1Y57xNZrvlKxvXIZl98gY69h6EsDDIAyoviRpOQKBgC0g\nRjlv+EZ2tt6+VhqTjzzjClF03ikuD+1dzjUDDrwCiXDJSWjS2P5E9fzv8CY0+7o3\nVm8yZY2hUUH9hycg+QPeoeCcqQp5+HoRE99SmM+DegFj+AOdHgGsX0Jiy6UTgUyc\nK5UaaVfvHJ0emv85z72u4ir1w3YwVr4LFf+N5ogtAoGAHODQpVC7sg+nlbeSKsPf\nRbULfOG4YD5pHszNM+nCjNWs00ofJoZOFA64qXwTIc4Vrh8JLiwAkXiTGYM2guv5\nQnp+HbFi/tAc+rQu4SGBaVIglnIj7jFNdgJOb68Vw/L9v2jW1Y8VoAC0eCRWpHud\nGsMkN4GFOfQKoBI/aCXn4DM=\n-----END PRIVATE KEY-----\n"
for i := 0; i < b.N; i++ {
cert, err := tls.X509KeyPair([]byte(chain), []byte(keyPem))
if err != nil {
b.Errorf("performance test error during cert load cert: %v, cause: %v", cert, err)
}
}
}
func BenchmarkHandlerDelegate_ServeHTTP_Acme(b *testing.B) {
Runner = mockRuntime()
r := mockRequest()
Runner.AcmeHandler.Active["123"] = true
Runner.AcmeHandler.Domains["123"] = "123.com"
Runner.AcmeHandler.KeyAuths["123"] = []byte("response")
r.RequestURI = "/.well-known/acme-challenge/123"
r.URL.Path = "/.well-known/acme-challenge/123"
h := HandlerDelegate{}
w := httptest.NewRecorder()
zerolog.SetGlobalLevel(zerolog.WarnLevel)
for i := 0; i < b.N; i++ {
h.ServeHTTP(w, &r)
}
}
func BenchmarkHandlerDelegate_ServeHTTP_About(b *testing.B) {
Runner = mockRuntime()
r := mockRequest()
h := HandlerDelegate{}
w := httptest.NewRecorder()
zerolog.SetGlobalLevel(zerolog.WarnLevel)
for i := 0; i < b.N; i++ {
h.ServeHTTP(w, &r)
}
}
func TestHandlerDelegate_ServeHTTP_About(t *testing.T) {
Runner = mockRuntime()
r := mockRequest()
h := HandlerDelegate{}
w := httptest.NewRecorder()
h.ServeHTTP(w, &r)
resp := w.Result()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != 200 {
t.Errorf("should have returned 200 ok")
}
if !strings.Contains(string(body), "Version") {
t.Errorf("should have returned about response but got this instead: %s", body)
}
}
func TestHandlerDelegate_ServeHTTP_Acme(t *testing.T) {
Runner = mockRuntime()
Runner.AcmeHandler.Active["tokentest"] = true
Runner.AcmeHandler.Domains["tokentest"] = "localhost.com"
Runner.AcmeHandler.KeyAuths["tokentest"] = []byte("keyauthtest")
r := mockRequest()
r.RequestURI = "/.well-known/acme-challenge/tokentest"
r.URL.Path = "/.well-known/acme-challenge/tokentest"
h := HandlerDelegate{}
w := httptest.NewRecorder()
h.ServeHTTP(w, &r)
resp := w.Result()
if resp.StatusCode != 200 {
t.Errorf("should have returned 200 ok")
}
body, _ := ioutil.ReadAll(resp.Body)
if string(body) != "keyauthtest" {
t.Errorf("wanted keyauth response but got %s", string(body))
} else {
t.Logf("normal. key auth challenge responded with %s", string(body))
}
resp.Body.Close()
}
func TestServerBootStrap(t *testing.T) {
ConfigFile = "./j8acfg.yml"
before := time.Now()
//we need to nuke the other Runners that may have been created by previous unit tests
Runner = nil
//this triggers the Bootstrap process and results in the StateHandler to go through Bootstrap, then into Daemon state
go BootStrap()
//we need this because Runner is initialised by the goroutine above
for {
if Runner != nil && Runner.StateHandler != nil {
break
} else {
time.Sleep(time.Millisecond * 100)
}
}
//this blocks until we reach Daemon state or dies after 10 seconds
testTimeOutSeconds := 10
Runner.StateHandler.waitState(Daemon, testTimeOutSeconds)
delta := time.Now().Sub(before)
if delta > time.Second*time.Duration(testTimeOutSeconds) {
t.Errorf("should not have timed out waiting for Daemon state")
} else {
t.Logf("normal. returned from StateHandler wait state in %v", delta)
}
resp, err := http.Get("http://localhost:8080/about")
if resp != nil && resp.StatusCode != 200 {
t.Errorf("server does not return ok status response after starting, want 200, got %v", resp.StatusCode)
}
if err != nil {
t.Errorf("GET req to /about returned error, %v", err)
} else {
t.Logf("normal. GET req against Bootstrapped server")
}
}
func TestServerTlsConfig(t *testing.T) {
certPem := "-----BEGIN CERTIFICATE-----\nMIIEkzCCAvugAwIBAgIRANiwkh9AuRgrvYh7Y5DtWIUwDQYJKoZIhvcNAQELBQAw\ngYExHjAcBgNVBAoTFW1rY2VydCBkZXZlbG9wbWVudCBDQTErMCkGA1UECwwic2lt\nb25taXR0YWdAdHJvb3BlciAoU2ltb24gTWl0dGFnKTEyMDAGA1UEAwwpbWtjZXJ0\nIHNpbW9ubWl0dGFnQHRyb29wZXIgKFNpbW9uIE1pdHRhZykwHhcNMTkwNjAxMDAw\nMDAwWhcNMzAwNzMwMDExNDU5WjBjMScwJQYDVQQKEx5ta2NlcnQgZGV2ZWxvcG1l\nbnQgY2VydGlmaWNhdGUxODA2BgNVBAsML3NpbW9ubWl0dGFnQE1hY0Jvb2stUHJv\nLTE2LmxvY2FsIChTaW1vbiBNaXR0YWcpMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A\nMIIBCgKCAQEAsCTQ9rLTQYjIlGF7EOrTJux8E514TUoAuQ0xo1NOSssptjmDyGhb\n8K7+A/TgdU/xlPMcJf22nNDQ2MpqpgHGlDcuXt3SmVrcsTeby1Pa81gxKp23a51B\n8xAoHoHwXVSWdiMWk3H/Jjv/dtYL1L180neewcWvK26ANUwlzWG6BW1QVUXXNdRo\ndmxQ1eg2S/qMBASFj6QjCsWWJiEfmz4PQpsP8q5IqCcX85BUqGO919JlE/eXEAgk\n9Yuh61/50n39B/sPC0mU5s6vH0SPCBvz1g8SiXa8jj3jCXxa/0ZsYtAVqPe5BoRP\nvK2q1sbKbJVr7EpmiOdKxKPHonRHasweGwIDAQABo4GiMIGfMA4GA1UdDwEB/wQE\nAwIFoDATBgNVHSUEDDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAM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Zz4KRwnaGqh+wiAjO0PHAfrbrhNsFB6P1/Zk\nCqzclj3TXdkMDaXhSvt0qJPEpNIPQMkvj9GROom7hExZUT7t7LPOZwODtiR2VjM3\nDDehfLqpNPRrxU3aOR7b4lFVtEL1+9NXKc3rnR5T2xPVVvBxx8FqYAxFmQtkGqpA\nYlRxImBONBreIr5/fdkr5xqd/S0s1pb8ubuK7x5COfqf0Mv++j+UjMptBQ3kYvOh\ntNrbnEI1q/7kvHNB8ETtJ4hqXikl9EHMYWdOo4nyGd4P8jo9jmGVAgMBAAGjRTBD\nMA4GA1UdDwEB/wQEAwICBDASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBTD\nRHJaFeI4PnqJweaJrib0F4qokTANBgkqhkiG9w0BAQsFAAOCAYEAb+K3HO2AlDed\nS2yT7GnxD75Hcjnv1tMvMIlh1EOmRMHrzbsi7jv3Z7SDe2R5s1qRku3nxbVWj8i8\noRBi5GeRE+q/HkVloi4WPmgFGxUUbkWszAFSSGN5TAs72e5sCG/wMyEa0Gj8cOO1\ndK5SH3thP8+OjSpgQXToYfOimILlk7Hj7EgKE5Y8YX8UV+41LhGkzeK2UX9dBZn1\nof9qBc0dAQVlAA/O3dOgXorgiDbNT38cjignWEwVYzjeuJCYB91Ixf0CfHJZKHZR\nZCdIAHTJqW1tx7vsbrcl0PVAMgm+rkHLL0Dh9cp4fvONXWygVSjbqKM1s8UI9bFA\nbWU5Z3MhEn25wZCXLQDIq0uC+FwCxyS9e/exL4wmYpCLmRKVCp2gUa78Rlr/FJNa\nH9kfvP41Ya+fLzDWNKAlYQgizpZJmZuhPZu7O6n0UusaI+0WTKblCFUQJkx4aKEv\nio8QmLzoedmvVpO9Zp44Lyabmc7VnjoYTOcZczx4ECwEdKH/jswc\n-----END CERTIFICATE-----\n"
Runner = mockRuntime()
Runner.Connection.Downstream.Tls.Cert = certPem + cAPem
Runner.Connection.Downstream.Tls.Key = keyPem
Runner.Connection.Downstream.Tls.Port = 8443
//this fugly code loads the cert for the first time.
Runner.ReloadableCert.triggerInit()
cert := *Runner.ReloadableCert.Cert
if cert.Leaf != nil && cert.Leaf.DNSNames[0] != "*.jabbatest.com" {
t.Errorf("failed to read TLS certificate")
}
}
func TestZerologAdapter_Write(t *testing.T) {
zla := zerologAdapter{}
//this shouldn't crash
zla.Write([]byte("i'm a log line from 127.0.0.1 there's no place like it"))
}
// test this on windows. Go doco says it should work:
func TestServerInitDotDir(t *testing.T) {
Runner := mockRuntime()
Runner.initCacheDir()
if !Runner.cacheDirIsActive() {
t.Error("cache dir not set")
} else {
t.Logf("cache dir is: %v", Runner.cacheDir)
}
if len(Runner.cacheDir) == 0 {
t.Error("cache dir not set")
} else {
t.Logf("cache dir is: %v", Runner.cacheDir)
}
home, e1 := os.UserHomeDir()
if e1 != nil {
t.Errorf("cannot access user home? cause: %v", e1)
}
if _, e2 := os.Stat(filepath.FromSlash(home + "/.j8a")); os.IsNotExist(e2) {
t.Errorf("cannot create .j8a dir in user home? cause: %v", e2)
}
}
func BenchmarkConnectionWatcher_OnStateChange(b *testing.B) {
cw := ConnectionWatcher{dwnOpenConns: 0}
for i := 0; i < b.N; i++ {
cw.OnStateChange(nil, http.StateNew)
}
}
func TestConnectionWatcher_OnStateChange(t *testing.T) {
cw := ConnectionWatcher{dwnOpenConns: 0, dwnMaxOpenConns: 0}
cw.OnStateChange(nil, http.StateNew)
if cw.DwnCount() != 1 {
t.Error("count should be 1")
}
if cw.DwnMaxCount() != 1 {
t.Error("maxcount should be 1")
}
cw.OnStateChange(nil, http.StateNew)
if cw.DwnCount() != 2 {
t.Error("count should be 2")
}
if cw.DwnMaxCount() != 2 {
t.Error("maxcount should be 2")
}
cw.OnStateChange(nil, http.StateClosed)
if cw.DwnCount() != 1 {
t.Error("count should be 1")
}
if cw.DwnMaxCount() != 2 {
t.Error("maxcount should still be 2")
}
}
func mockRequest() http.Request {
return http.Request{
Method: "GET",
URL: &url.URL{
Host: "localhost",
Path: "/about",
},
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: http.Header{
"key": []string{"value"},
},
ContentLength: 0,
Close: false,
Host: "localhost",
RemoteAddr: "10.1.1.1",
RequestURI: "/about",
}
}