MCPcopy
hub / github.com/zalando/skipper / TestHTTPSServer

Function TestHTTPSServer

skipper_test.go:257–318  ·  view source on GitHub ↗

to run this test, set `-args listener` for the test command

(t *testing.T)

Source from the content-addressed store, hash-verified

255
256// to run this test, set `-args listener` for the test command
257func TestHTTPSServer(t *testing.T) {
258 // TODO: figure why sometimes cannot connect
259 if !testListener() {
260 t.Log("Failed to get testListener skip test TestHTTPSServer")
261 t.Skip()
262 }
263
264 MuFindAddress.Lock()
265 a := FindAddress(t)
266 i := FindAddress(t)
267
268 o := Options{
269 Address: a,
270 InsecureAddress: i,
271 CertPathTLS: "fixtures/test.crt",
272 KeyPathTLS: "fixtures/test.key",
273 }
274
275 rt := routing.New(routing.Options{
276 FilterRegistry: builtin.MakeRegistry(),
277 DataClients: []routing.DataClient{}})
278 defer rt.Close()
279
280 proxy := proxy.WithParams(proxy.Params{
281 Routing: rt,
282 Flags: proxy.Flags(proxy.OptionsNone),
283 Metrics: &metricstest.MockMetrics{},
284 })
285 defer proxy.Close()
286 go listenAndServe(proxy, &o)
287
288 r, err := waitConnGet("https://" + o.Address)
289 if r != nil {
290 defer r.Body.Close()
291 }
292 if err != nil {
293 t.Fatalf("Cannot connect to the local server for testing: %s ", err.Error())
294 }
295 if r.StatusCode != 404 {
296 t.Fatalf("Status code should be 404, instead got: %d\n", r.StatusCode)
297 }
298 _, err = io.ReadAll(r.Body)
299 if err != nil {
300 t.Fatalf("Failed to stream response body: %v", err)
301 }
302
303 r, err = waitConnGet("http://" + o.InsecureAddress)
304 MuFindAddress.Unlock()
305 if r != nil {
306 defer r.Body.Close()
307 }
308 if err != nil {
309 t.Fatalf("Cannot connect to the local server for testing: %s ", err.Error())
310 }
311 if r.StatusCode != 404 {
312 t.Fatalf("Status code should be 404, instead got: %d\n", r.StatusCode)
313 }
314 _, err = io.ReadAll(r.Body)

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
MakeRegistryFunction · 0.92
WithParamsFunction · 0.92
FlagsTypeAlias · 0.92
FindAddressFunction · 0.85
listenAndServeFunction · 0.85
waitConnGetFunction · 0.85
LogMethod · 0.80
testListenerFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…