@@ -13,16 +13,17 @@ import (
1313
1414var _ = Describe("Util Suite", func() {
1515 const (
16− proto = "http"
17− host = "www.oauth2proxy.test"
18− uri = "/test/endpoint"
16+ proto = "http"
17+ host = "www.oauth2proxy.test"
18+ uriWithQueryParams = "/test/endpoint?query=param"
19+ uriNoQueryParams = "/test/endpoint"
1920 )
2021 var req *http.Request
2122
2223 BeforeEach(func() {
2324 req = httptest.NewRequest(
2425 http.MethodGet,
25− fmt.Sprintf("%s://%s%s", proto, host, uri),
26+ fmt.Sprintf("%s://%s%s", proto, host, uriWithQueryParams),
2627 nil,
2728 )
2829 })
@@ -101,13 +102,13 @@ var _ = Describe("Util Suite", func() {
101102 req = middleware.AddRequestScope(req, &middleware.RequestScope{})
102103 })
103104
104− It("returns the URI", func() {
105− Expect(util.GetRequestURI(req)).To(Equal(uri))
105+ It("returns the URI (with query params)", func() {
106+ Expect(util.GetRequestURI(req)).To(Equal(uriWithQueryParams))
106107 })
107108
108− It("ignores X-Forwarded-Uri and returns the URI", func() {
109+ It("ignores X-Forwarded-Uri and returns the URI (with query params)", func() {
109110 req.Header.Add("X-Forwarded-Uri", "/some/other/path")
110− Expect(util.GetRequestURI(req)).To(Equal(uri))
111+ Expect(util.GetRequestURI(req)).To(Equal(uriWithQueryParams))
111112 })
112113 })
113114
@@ -118,13 +119,47 @@ var _ = Describe("Util Suite", func() {
118119 })
119120 })
120121
121− It("returns the URI if X-Forwarded-Uri is not present", func() {
122− Expect(util.GetRequestURI(req)).To(Equal(uri))
122+ It("returns the URI if X-Forwarded-Uri is not present (with query params)", func() {
123+ Expect(util.GetRequestURI(req)).To(Equal(uriWithQueryParams))
123124 })
124125
125− It("returns the X-Forwarded-Uri when present", func() {
126− req.Header.Add("X-Forwarded-Uri", "/some/other/path")
127− Expect(util.GetRequestURI(req)).To(Equal("/some/other/path"))
126+ It("returns the X-Forwarded-Uri when present (with query params)", func() {
127+ req.Header.Add("X-Forwarded-Uri", "/some/other/path?query=param")
128+ Expect(util.GetRequestURI(req)).To(Equal("/some/other/path?query=param"))
129+ })
130+ })
131+ })
132+
133+ Context("GetRequestPath", func() {
134+ Context("IsProxied is false", func() {
135+ BeforeEach(func() {
136+ req = middleware.AddRequestScope(req, &middleware.RequestScope{})
137+ })
138+
139+ It("returns the URI (without query params)", func() {
140+ Expect(util.GetRequestPath(req)).To(Equal(uriNoQueryParams))
141+ })
142+
143+ It("ignores X-Forwarded-Uri and returns the URI (without query params)", func() {
144+ req.Header.Add("X-Forwarded-Uri", "/some/other/path?query=param")
145+ Expect(util.GetRequestPath(req)).To(Equal(uriNoQueryParams))
146+ })
147+ })
148+
149+ Context("IsProxied is true", func() {
150+ BeforeEach(func() {
151+ req = middleware.AddRequestScope(req, &middleware.RequestScope{
152+ ReverseProxy: true,
153+ })
154+ })
155+
156+ It("returns the URI if X-Forwarded-Uri is not present (without query params)", func() {
157+ Expect(util.GetRequestPath(req)).To(Equal(uriNoQueryParams))
158+ })
159+
160+ It("returns the X-Forwarded-Uri when present (without query params)", func() {
161+ req.Header.Add("X-Forwarded-Uri", "/some/other/path?query=param")
162+ Expect(util.GetRequestPath(req)).To(Equal("/some/other/path"))
128163 })
129164 })
130165 })