MCPcopy
hub / github.com/fabiolb/fabio / TestProxyTCPAndHTTPS

Function TestProxyTCPAndHTTPS

proxy/inetaf_tcpproxy_integration_test.go:27–169  ·  view source on GitHub ↗

to run this test, add the following to /etc/hosts: 127.0.0.1 example.com 127.0.0.1 example2.com and then set the environment FABIO_IHAVEHOSTENTRIES=true This also runs in Github Actions by default, since the workflow adds these aliases.

(t *testing.T)

Source from the content-addressed store, hash-verified

25// and then set the environment FABIO_IHAVEHOSTENTRIES=true
26// This also runs in Github Actions by default, since the workflow adds these aliases.
27func TestProxyTCPAndHTTPS(t *testing.T) {
28 if os.Getenv("TRAVIS") != "true" &&
29 os.Getenv("CI") != "true" &&
30 os.Getenv("FABIO_IHAVEHOSTENTRIES") != "true" {
31 t.Skip("skipping because env FABIO_IHAVEHOSTENTRIES is not set to true")
32 }
33
34 tlsCfg1 := tlsServerConfig()
35 tlsCfg2 := tlsServerConfig2()
36 tcpServer := httptest.NewUnstartedServer(okHandler)
37 tcpServer.TLS = tlsCfg2
38 tcpServer.StartTLS()
39 defer tcpServer.Close()
40
41 httpPayload := []byte(`OK HTTP`)
42
43 httpServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
44 w.Write(httpPayload)
45 }))
46 defer httpServer.Close()
47
48 tpl := `route add srv / %s opts "proto=https"
49route add tcproute example2.com/ tcp://%s opts "proto=tcp"`
50
51 table, _ := route.NewTable(bytes.NewBufferString(fmt.Sprintf(tpl, httpServer.URL, tcpServer.Listener.Addr())))
52 hp := &HTTPProxy{
53 Lookup: func(r *http.Request) *route.Target {
54 return table.Lookup(r, route.Picker["rr"], route.Matcher["prefix"], globCache, globEnabled)
55 },
56 }
57
58 tp := &tcp.SNIProxy{
59 Lookup: func(h string) *route.Target {
60 return table.LookupHost(h, route.Picker["rr"])
61 },
62 }
63 m := func(_ context.Context, h string) bool {
64 // TODO - matcher needs to move out of main
65 // so we can test it more easily. Probably
66 // the other functions too.
67 t := table.LookupHost(h, route.Picker["rr"])
68 if t == nil {
69 return false
70 }
71 // Make sure this is supposed to be a tcp proxy.
72 // opts proto= overrides scheme if present.
73 var (
74 ok bool
75 proto string
76 )
77 if proto, ok = t.Opts["proto"]; !ok && t.URL != nil {
78 proto = t.URL.Scheme
79 }
80 return proto == "tcp"
81 }
82
83 // get an unused port for use for the proxy. the rest of the tests just
84 // pick a high-numbered port, but this should be safer, if ugly. could

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
LookupMethod · 0.95
LookupHostMethod · 0.95
NewTableFunction · 0.92
NewRetryDialerFunction · 0.92
tlsServerConfigFunction · 0.85
tlsServerConfig2Function · 0.85
CloseFunction · 0.85
tlsClientConfigFunction · 0.85
foundDNSNameFunction · 0.85
StartTLSMethod · 0.80

Tested by

no test coverage detected