git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #650 from jordancrawfordnz/issue-649
215aeecJoel Speed
CHANGELOG.md+1
@@ -16,6 +16,7 @@
16- [#542](https://github.com/oauth2-proxy/oauth2-proxy/pull/542) Move SessionStore tests to independent package (@JoelSpeed)
16- [#542](https://github.com/oauth2-proxy/oauth2-proxy/pull/542) Move SessionStore tests to independent package (@JoelSpeed)
17- [#577](https://github.com/oauth2-proxy/oauth2-proxy/pull/577) Move Cipher and Session Store initialisation out of Validation (@JoelSpeed)
17- [#577](https://github.com/oauth2-proxy/oauth2-proxy/pull/577) Move Cipher and Session Store initialisation out of Validation (@JoelSpeed)
18- [#635](https://github.com/oauth2-proxy/oauth2-proxy/pull/635) Support specifying alternative provider TLS trust source(s) (@k-wall)
18- [#635](https://github.com/oauth2-proxy/oauth2-proxy/pull/635) Support specifying alternative provider TLS trust source(s) (@k-wall)
19+- [#649](https://github.com/oauth2-proxy/oauth2-proxy/pull/650) Resolve an issue where an empty healthcheck URL and ping-user-agent returns the healthcheck response (@jordancrawfordnz)
19
20
20# v6.0.0
21# v6.0.0
21
22
pkg/middleware/healthcheck.go+6−2
@@ -17,13 +17,17 @@ func healthCheck(paths, userAgents []string, next http.Handler) http.Handler {
17 // Use a map as a set to check health check paths
17 // Use a map as a set to check health check paths
18 pathSet := make(map[string]struct{})
18 pathSet := make(map[string]struct{})
19 for _, path := range paths {
19 for _, path := range paths {
20+ if len(path) > 0 {
20− pathSet[path] = struct{}{}
21+ pathSet[path] = struct{}{}
22+ }
21 }
23 }
22
24
23 // Use a map as a set to check health check paths
25 // Use a map as a set to check health check paths
24 userAgentSet := make(map[string]struct{})
26 userAgentSet := make(map[string]struct{})
25 for _, userAgent := range userAgents {
27 for _, userAgent := range userAgents {
28+ if len(userAgent) > 0 {
26− userAgentSet[userAgent] = struct{}{}
29+ userAgentSet[userAgent] = struct{}{}
30+ }
27 }
31 }
28
32
29 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
33 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
pkg/middleware/healthcheck_test.go+39−5
@@ -34,6 +34,14 @@ var _ = Describe("HealthCheck suite", func() {
34 Expect(rw.Code).To(Equal(in.expectedStatus))
34 Expect(rw.Code).To(Equal(in.expectedStatus))
35 Expect(rw.Body.String()).To(Equal(in.expectedBody))
35 Expect(rw.Body.String()).To(Equal(in.expectedBody))
36 },
36 },
37+ Entry("when no health check paths are configured", &requestTableInput{
38+ healthCheckPaths: []string{},
39+ healthCheckUserAgents: []string{"hc/1.0"},
40+ requestString: "http://example.com/ping",
41+ headers: map[string]string{},
42+ expectedStatus: 404,
43+ expectedBody: "404 page not found\n",
44+ }),
37 Entry("when requesting the healthcheck path", &requestTableInput{
45 Entry("when requesting the healthcheck path", &requestTableInput{
38 healthCheckPaths: []string{"/ping"},
46 healthCheckPaths: []string{"/ping"},
39 healthCheckUserAgents: []string{"hc/1.0"},
47 healthCheckUserAgents: []string{"hc/1.0"},
@@ -50,15 +58,23 @@ var _ = Describe("HealthCheck suite", func() {
50 expectedStatus: 404,
58 expectedStatus: 404,
51 expectedBody: "404 page not found\n",
59 expectedBody: "404 page not found\n",
52 }),
60 }),
53− Entry("with a request from the health check user agent", &requestTableInput{
61+ Entry("when a blank string is configured as a health check path and the request has no specific path", &requestTableInput{
54− healthCheckPaths: []string{"/ping"},
62+ healthCheckPaths: []string{""},
55 healthCheckUserAgents: []string{"hc/1.0"},
63 healthCheckUserAgents: []string{"hc/1.0"},
64+ requestString: "http://example.com",
65+ headers: map[string]string{},
66+ expectedStatus: 404,
67+ expectedBody: "404 page not found\n",
68+ }),
69+ Entry("with no health check user agents configured", &requestTableInput{
70+ healthCheckPaths: []string{"/ping"},
71+ healthCheckUserAgents: []string{},
56 requestString: "http://example.com/abc",
72 requestString: "http://example.com/abc",
57 headers: map[string]string{
73 headers: map[string]string{
58− "User-Agent": "hc/1.0",
74+ "User-Agent": "user",
59 },
75 },
60− expectedStatus: 200,
76+ expectedStatus: 404,
61− expectedBody: "OK",
77+ expectedBody: "404 page not found\n",
62 }),
78 }),
63 Entry("with a request from a different user agent", &requestTableInput{
79 Entry("with a request from a different user agent", &requestTableInput{
64 healthCheckPaths: []string{"/ping"},
80 healthCheckPaths: []string{"/ping"},
@@ -70,6 +86,24 @@ var _ = Describe("HealthCheck suite", func() {
70 expectedStatus: 404,
86 expectedStatus: 404,
71 expectedBody: "404 page not found\n",
87 expectedBody: "404 page not found\n",
72 }),
88 }),
89+ Entry("with a request from the health check user agent", &requestTableInput{
90+ healthCheckPaths: []string{"/ping"},
91+ healthCheckUserAgents: []string{"hc/1.0"},
92+ requestString: "http://example.com/abc",
93+ headers: map[string]string{
94+ "User-Agent": "hc/1.0",
95+ },
96+ expectedStatus: 200,
97+ expectedBody: "OK",
98+ }),
99+ Entry("when a blank string is configured as a health check agent and a request has no user agent", &requestTableInput{
100+ healthCheckPaths: []string{"/ping"},
101+ healthCheckUserAgents: []string{""},
102+ requestString: "http://example.com/abc",
103+ headers: map[string]string{},
104+ expectedStatus: 404,
105+ expectedBody: "404 page not found\n",
106+ }),
73 Entry("with multiple paths, request one of the healthcheck paths", &requestTableInput{
107 Entry("with multiple paths, request one of the healthcheck paths", &requestTableInput{
74 healthCheckPaths: []string{"/ping", "/liveness_check", "/readiness_check"},
108 healthCheckPaths: []string{"/ping", "/liveness_check", "/readiness_check"},
75 healthCheckUserAgents: []string{"hc/1.0"},
109 healthCheckUserAgents: []string{"hc/1.0"},