git.iko.soy/typeable/oauth2-proxy
on master help sign in
Use bool pointers for upstream options that default to true
d43b372Joel Speed
pkg/apis/options/legacy_options.go+4−4
@@ -77,8 +77,8 @@ func (l *LegacyUpstreams) convert() (Upstreams, error) {
77 Path: u.Path,
77 Path: u.Path,
78 URI: upstreamString,
78 URI: upstreamString,
79 InsecureSkipTLSVerify: l.SSLUpstreamInsecureSkipVerify,
79 InsecureSkipTLSVerify: l.SSLUpstreamInsecureSkipVerify,
80− PassHostHeader: l.PassHostHeader,
80+ PassHostHeader: &l.PassHostHeader,
81− ProxyWebSockets: l.ProxyWebSockets,
81+ ProxyWebSockets: &l.ProxyWebSockets,
82 FlushInterval: &l.FlushInterval,
82 FlushInterval: &l.FlushInterval,
83 }
83 }
84
84
@@ -104,8 +104,8 @@ func (l *LegacyUpstreams) convert() (Upstreams, error) {
104 // Force defaults compatible with static responses
104 // Force defaults compatible with static responses
105 upstream.URI = ""
105 upstream.URI = ""
106 upstream.InsecureSkipTLSVerify = false
106 upstream.InsecureSkipTLSVerify = false
107− upstream.PassHostHeader = true
107+ upstream.PassHostHeader = nil
108− upstream.ProxyWebSockets = false
108+ upstream.ProxyWebSockets = nil
109 flush := 1 * time.Second
109 flush := 1 * time.Second
110 upstream.FlushInterval = &flush
110 upstream.FlushInterval = &flush
111 }
111 }
pkg/apis/options/legacy_options_test.go+15−14
@@ -23,6 +23,7 @@ var _ = Describe("Legacy Options", func() {
23 legacyOpts.LegacyUpstreams.SSLUpstreamInsecureSkipVerify = true
23 legacyOpts.LegacyUpstreams.SSLUpstreamInsecureSkipVerify = true
24 legacyOpts.LegacyUpstreams.Upstreams = []string{"http://foo.bar/baz", "file://var/lib/website#/bar"}
24 legacyOpts.LegacyUpstreams.Upstreams = []string{"http://foo.bar/baz", "file://var/lib/website#/bar"}
25
25
26+ truth := true
26 opts.UpstreamServers = Upstreams{
27 opts.UpstreamServers = Upstreams{
27 {
28 {
28 ID: "/baz",
29 ID: "/baz",
@@ -30,8 +31,8 @@ var _ = Describe("Legacy Options", func() {
30 URI: "http://foo.bar/baz",
31 URI: "http://foo.bar/baz",
31 FlushInterval: &flushInterval,
32 FlushInterval: &flushInterval,
32 InsecureSkipTLSVerify: true,
33 InsecureSkipTLSVerify: true,
33− PassHostHeader: true,
34+ PassHostHeader: &truth,
34− ProxyWebSockets: true,
35+ ProxyWebSockets: &truth,
35 },
36 },
36 {
37 {
37 ID: "/bar",
38 ID: "/bar",
@@ -39,8 +40,8 @@ var _ = Describe("Legacy Options", func() {
39 URI: "file://var/lib/website#/bar",
40 URI: "file://var/lib/website#/bar",
40 FlushInterval: &flushInterval,
41 FlushInterval: &flushInterval,
41 InsecureSkipTLSVerify: true,
42 InsecureSkipTLSVerify: true,
42− PassHostHeader: true,
43+ PassHostHeader: &truth,
43− ProxyWebSockets: true,
44+ ProxyWebSockets: &truth,
44 },
45 },
45 }
46 }
46
47
@@ -72,8 +73,8 @@ var _ = Describe("Legacy Options", func() {
72 Path: "/baz",
73 Path: "/baz",
73 URI: validHTTP,
74 URI: validHTTP,
74 InsecureSkipTLSVerify: skipVerify,
75 InsecureSkipTLSVerify: skipVerify,
75− PassHostHeader: passHostHeader,
76+ PassHostHeader: &passHostHeader,
76− ProxyWebSockets: proxyWebSockets,
77+ ProxyWebSockets: &proxyWebSockets,
77 FlushInterval: &flushInterval,
78 FlushInterval: &flushInterval,
78 }
79 }
79
80
@@ -84,8 +85,8 @@ var _ = Describe("Legacy Options", func() {
84 Path: "/",
85 Path: "/",
85 URI: emptyPathHTTP,
86 URI: emptyPathHTTP,
86 InsecureSkipTLSVerify: skipVerify,
87 InsecureSkipTLSVerify: skipVerify,
87− PassHostHeader: passHostHeader,
88+ PassHostHeader: &passHostHeader,
88− ProxyWebSockets: proxyWebSockets,
89+ ProxyWebSockets: &proxyWebSockets,
89 FlushInterval: &flushInterval,
90 FlushInterval: &flushInterval,
90 }
91 }
91
92
@@ -95,8 +96,8 @@ var _ = Describe("Legacy Options", func() {
95 Path: "/bar",
96 Path: "/bar",
96 URI: validFileWithFragment,
97 URI: validFileWithFragment,
97 InsecureSkipTLSVerify: skipVerify,
98 InsecureSkipTLSVerify: skipVerify,
98− PassHostHeader: passHostHeader,
99+ PassHostHeader: &passHostHeader,
99− ProxyWebSockets: proxyWebSockets,
100+ ProxyWebSockets: &proxyWebSockets,
100 FlushInterval: &flushInterval,
101 FlushInterval: &flushInterval,
101 }
102 }
102
103
@@ -109,8 +110,8 @@ var _ = Describe("Legacy Options", func() {
109 Static: true,
110 Static: true,
110 StaticCode: &validStaticCode,
111 StaticCode: &validStaticCode,
111 InsecureSkipTLSVerify: false,
112 InsecureSkipTLSVerify: false,
112− PassHostHeader: true,
113+ PassHostHeader: nil,
113− ProxyWebSockets: false,
114+ ProxyWebSockets: nil,
114 FlushInterval: &defaultFlushInterval,
115 FlushInterval: &defaultFlushInterval,
115 }
116 }
116
117
@@ -123,8 +124,8 @@ var _ = Describe("Legacy Options", func() {
123 Static: true,
124 Static: true,
124 StaticCode: &invalidStaticCode,
125 StaticCode: &invalidStaticCode,
125 InsecureSkipTLSVerify: false,
126 InsecureSkipTLSVerify: false,
126− PassHostHeader: true,
127+ PassHostHeader: nil,
127− ProxyWebSockets: false,
128+ ProxyWebSockets: nil,
128 FlushInterval: &defaultFlushInterval,
129 FlushInterval: &defaultFlushInterval,
129 }
130 }
130
131
pkg/apis/options/upstreams.go+2−2
@@ -52,9 +52,9 @@ type Upstream struct {
52 // PassHostHeader determines whether the request host header should be proxied
52 // PassHostHeader determines whether the request host header should be proxied
53 // to the upstream server.
53 // to the upstream server.
54 // Defaults to true.
54 // Defaults to true.
55− PassHostHeader bool `json:"passHostHeader"`
55+ PassHostHeader *bool `json:"passHostHeader"`
56
56
57 // ProxyWebSockets enables proxying of websockets to upstream servers
57 // ProxyWebSockets enables proxying of websockets to upstream servers
58 // Defaults to true.
58 // Defaults to true.
59− ProxyWebSockets bool `json:"proxyWebSockets"`
59+ ProxyWebSockets *bool `json:"proxyWebSockets"`
60}
60}
pkg/upstream/http.go+2−2
@@ -49,7 +49,7 @@ func newHTTPUpstreamProxy(upstream options.Upstream, u *url.URL, sigData *option
49
49
50 // Set up a WebSocket proxy if required
50 // Set up a WebSocket proxy if required
51 var wsProxy http.Handler
51 var wsProxy http.Handler
52− if upstream.ProxyWebSockets {
52+ if upstream.ProxyWebSockets == nil || *upstream.ProxyWebSockets {
53 wsProxy = newWebSocketReverseProxy(u, upstream.InsecureSkipTLSVerify)
53 wsProxy = newWebSocketReverseProxy(u, upstream.InsecureSkipTLSVerify)
54 }
54 }
55
55
@@ -110,7 +110,7 @@ func newReverseProxy(target *url.URL, upstream options.Upstream, errorHandler Pr
110 }
110 }
111
111
112 // Set the request director based on the PassHostHeader option
112 // Set the request director based on the PassHostHeader option
113− if !upstream.PassHostHeader {
113+ if upstream.PassHostHeader != nil && !*upstream.PassHostHeader {
114 setProxyUpstreamHostHeader(proxy, target)
114 setProxyUpstreamHostHeader(proxy, target)
115 } else {
115 } else {
116 setProxyDirector(proxy)
116 setProxyDirector(proxy)
pkg/upstream/http_test.go+10−7
@@ -24,6 +24,8 @@ var _ = Describe("HTTP Upstream Suite", func() {
24
24
25 const flushInterval5s = 5 * time.Second
25 const flushInterval5s = 5 * time.Second
26 const flushInterval1s = 1 * time.Second
26 const flushInterval1s = 1 * time.Second
27+ truth := true
28+ falsum := false
27
29
28 type httpUpstreamTableInput struct {
30 type httpUpstreamTableInput struct {
29 id string
31 id string
@@ -51,10 +53,11 @@ var _ = Describe("HTTP Upstream Suite", func() {
51 rw := httptest.NewRecorder()
53 rw := httptest.NewRecorder()
52
54
53 flush := 1 * time.Second
55 flush := 1 * time.Second
56+
54 upstream := options.Upstream{
57 upstream := options.Upstream{
55 ID: in.id,
58 ID: in.id,
56− PassHostHeader: true,
59+ PassHostHeader: &truth,
57− ProxyWebSockets: false,
60+ ProxyWebSockets: &falsum,
58 InsecureSkipTLSVerify: false,
61 InsecureSkipTLSVerify: false,
59 FlushInterval: &flush,
62 FlushInterval: &flush,
60 }
63 }
@@ -258,8 +261,8 @@ var _ = Describe("HTTP Upstream Suite", func() {
258 flush := 1 * time.Second
261 flush := 1 * time.Second
259 upstream := options.Upstream{
262 upstream := options.Upstream{
260 ID: "noPassHost",
263 ID: "noPassHost",
261− PassHostHeader: false,
264+ PassHostHeader: &falsum,
262− ProxyWebSockets: false,
265+ ProxyWebSockets: &falsum,
263 InsecureSkipTLSVerify: false,
266 InsecureSkipTLSVerify: false,
264 FlushInterval: &flush,
267 FlushInterval: &flush,
265 }
268 }
@@ -302,7 +305,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
302 ID: "foo123",
305 ID: "foo123",
303 FlushInterval: &in.flushInterval,
306 FlushInterval: &in.flushInterval,
304 InsecureSkipTLSVerify: in.skipVerify,
307 InsecureSkipTLSVerify: in.skipVerify,
305− ProxyWebSockets: in.proxyWebSockets,
308+ ProxyWebSockets: &in.proxyWebSockets,
306 }
309 }
307
310
308 handler := newHTTPUpstreamProxy(upstream, u, in.sigData, in.errorHandler)
311 handler := newHTTPUpstreamProxy(upstream, u, in.sigData, in.errorHandler)
@@ -370,8 +373,8 @@ var _ = Describe("HTTP Upstream Suite", func() {
370 flush := 1 * time.Second
373 flush := 1 * time.Second
371 upstream := options.Upstream{
374 upstream := options.Upstream{
372 ID: "websocketProxy",
375 ID: "websocketProxy",
373− PassHostHeader: true,
376+ PassHostHeader: &truth,
374− ProxyWebSockets: true,
377+ ProxyWebSockets: &truth,
375 InsecureSkipTLSVerify: false,
378 InsecureSkipTLSVerify: false,
376 FlushInterval: &flush,
379 FlushInterval: &flush,
377 }
380 }
pkg/validation/upstreams.go+2−2
@@ -73,10 +73,10 @@ func validateStaticUpstream(upstream options.Upstream) []string {
73 if upstream.FlushInterval != nil && *upstream.FlushInterval != time.Second {
73 if upstream.FlushInterval != nil && *upstream.FlushInterval != time.Second {
74 msgs = append(msgs, fmt.Sprintf("upstream %q has flushInterval, but is a static upstream, this will have no effect.", upstream.ID))
74 msgs = append(msgs, fmt.Sprintf("upstream %q has flushInterval, but is a static upstream, this will have no effect.", upstream.ID))
75 }
75 }
76− if !upstream.PassHostHeader {
76+ if upstream.PassHostHeader != nil {
77 msgs = append(msgs, fmt.Sprintf("upstream %q has passHostHeader, but is a static upstream, this will have no effect.", upstream.ID))
77 msgs = append(msgs, fmt.Sprintf("upstream %q has passHostHeader, but is a static upstream, this will have no effect.", upstream.ID))
78 }
78 }
79− if !upstream.ProxyWebSockets {
79+ if upstream.ProxyWebSockets != nil {
80 msgs = append(msgs, fmt.Sprintf("upstream %q has proxyWebSockets, but is a static upstream, this will have no effect.", upstream.ID))
80 msgs = append(msgs, fmt.Sprintf("upstream %q has proxyWebSockets, but is a static upstream, this will have no effect.", upstream.ID))
81 }
81 }
82
82
pkg/validation/upstreams_test.go+6−7
@@ -17,6 +17,7 @@ var _ = Describe("Upstreams", func() {
17
17
18 flushInterval := 5 * time.Second
18 flushInterval := 5 * time.Second
19 staticCode200 := 200
19 staticCode200 := 200
20+ truth := true
20
21
21 validHTTPUpstream := options.Upstream{
22 validHTTPUpstream := options.Upstream{
22 ID: "validHTTPUpstream",
23 ID: "validHTTPUpstream",
@@ -24,11 +25,9 @@ var _ = Describe("Upstreams", func() {
24 URI: "http://localhost:8080",
25 URI: "http://localhost:8080",
25 }
26 }
26 validStaticUpstream := options.Upstream{
27 validStaticUpstream := options.Upstream{
27− ID: "validStaticUpstream",
28+ ID: "validStaticUpstream",
28− Path: "/validStaticUpstream",
29+ Path: "/validStaticUpstream",
29− Static: true,
30+ Static: true,
30− PassHostHeader: true, // This would normally be defaulted
31− ProxyWebSockets: true, // this would normally be defaulted
32 }
31 }
33 validFileUpstream := options.Upstream{
32 validFileUpstream := options.Upstream{
34 ID: "validFileUpstream",
33 ID: "validFileUpstream",
@@ -134,8 +133,8 @@ var _ = Describe("Upstreams", func() {
134 URI: "ftp://foo",
133 URI: "ftp://foo",
135 Static: true,
134 Static: true,
136 FlushInterval: &flushInterval,
135 FlushInterval: &flushInterval,
137− PassHostHeader: false,
136+ PassHostHeader: &truth,
138− ProxyWebSockets: false,
137+ ProxyWebSockets: &truth,
139 InsecureSkipTLSVerify: true,
138 InsecureSkipTLSVerify: true,
140 },
139 },
141 },
140 },