@@ -13,7 +13,9 @@ import (
1313 "strings"
1414 "time"
1515
16+ middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
1617 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
18+ "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/middleware"
1719 . "github.com/onsi/ginkgo"
1820 . "github.com/onsi/ginkgo/extensions/table"
1921 . "github.com/onsi/gomega"
@@ -36,6 +38,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
3638 signatureData *options.SignatureData
3739 existingHeaders map[string]string
3840 expectedResponse testHTTPResponse
41+ expectedUpstream string
3942 errorHandler ProxyErrorHandler
4043 }
4144
@@ -50,6 +53,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
5053 req.Header.Add(key, value)
5154 }
5255
56+ req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
5357 rw := httptest.NewRecorder()
5458
5559 flush := options.Duration(1 * time.Second)
@@ -71,6 +75,9 @@ var _ = Describe("HTTP Upstream Suite", func() {
7175
7276 Expect(rw.Code).To(Equal(in.expectedResponse.code))
7377
78+ scope := middlewareapi.GetRequestScope(req)
79+ Expect(scope.Upstream).To(Equal(in.expectedUpstream))
80+
7481 // Delete extra headers that aren't relevant to tests
7582 testSanitizeResponseHeader(rw.Header())
7683 Expect(rw.Header()).To(Equal(in.expectedResponse.header))
@@ -97,7 +104,6 @@ var _ = Describe("HTTP Upstream Suite", func() {
97104 expectedResponse: testHTTPResponse{
98105 code: 200,
99106 header: map[string][]string{
100− gapUpstream: {"default"},
101107 contentType: {applicationJSON},
102108 },
103109 request: testHTTPRequest{
@@ -109,6 +115,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
109115 RequestURI: "http://example.localhost/foo",
110116 },
111117 },
118+ expectedUpstream: "default",
112119 }),
113120 Entry("request a path with encoded slashes", &httpUpstreamTableInput{
114121 id: "encodedSlashes",
@@ -120,7 +127,6 @@ var _ = Describe("HTTP Upstream Suite", func() {
120127 expectedResponse: testHTTPResponse{
121128 code: 200,
122129 header: map[string][]string{
123− gapUpstream: {"encodedSlashes"},
124130 contentType: {applicationJSON},
125131 },
126132 request: testHTTPRequest{
@@ -132,6 +138,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
132138 RequestURI: "http://example.localhost/foo%2fbar/?baz=1",
133139 },
134140 },
141+ expectedUpstream: "encodedSlashes",
135142 }),
136143 Entry("when the request has a body", &httpUpstreamTableInput{
137144 id: "requestWithBody",
@@ -143,7 +150,6 @@ var _ = Describe("HTTP Upstream Suite", func() {
143150 expectedResponse: testHTTPResponse{
144151 code: 200,
145152 header: map[string][]string{
146− gapUpstream: {"requestWithBody"},
147153 contentType: {applicationJSON},
148154 },
149155 request: testHTTPRequest{
@@ -157,6 +163,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
157163 RequestURI: "http://example.localhost/withBody",
158164 },
159165 },
166+ expectedUpstream: "requestWithBody",
160167 }),
161168 Entry("when the upstream is unavailable", &httpUpstreamTableInput{
162169 id: "unavailableUpstream",
@@ -166,12 +173,11 @@ var _ = Describe("HTTP Upstream Suite", func() {
166173 body: []byte{},
167174 errorHandler: nil,
168175 expectedResponse: testHTTPResponse{
169− code: 502,
170− header: map[string][]string{
171− gapUpstream: {"unavailableUpstream"},
172− },
176+ code: 502,
177+ header: map[string][]string{},
173178 request: testHTTPRequest{},
174179 },
180+ expectedUpstream: "unavailableUpstream",
175181 }),
176182 Entry("when the upstream is unavailable and an error handler is set", &httpUpstreamTableInput{
177183 id: "withErrorHandler",
@@ -184,13 +190,12 @@ var _ = Describe("HTTP Upstream Suite", func() {
184190 rw.Write([]byte("error"))
185191 },
186192 expectedResponse: testHTTPResponse{
187− code: 502,
188− header: map[string][]string{
189− gapUpstream: {"withErrorHandler"},
190− },
193+ code: 502,
194+ header: map[string][]string{},
191195 raw: "error",
192196 request: testHTTPRequest{},
193197 },
198+ expectedUpstream: "withErrorHandler",
194199 }),
195200 Entry("with a signature", &httpUpstreamTableInput{
196201 id: "withSignature",
@@ -207,7 +212,6 @@ var _ = Describe("HTTP Upstream Suite", func() {
207212 code: 200,
208213 header: map[string][]string{
209214 contentType: {applicationJSON},
210− gapUpstream: {"withSignature"},
211215 },
212216 request: testHTTPRequest{
213217 Method: "GET",
@@ -221,6 +225,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
221225 RequestURI: "http://example.localhost/withSignature",
222226 },
223227 },
228+ expectedUpstream: "withSignature",
224229 }),
225230 Entry("with existing headers", &httpUpstreamTableInput{
226231 id: "existingHeaders",
@@ -236,7 +241,6 @@ var _ = Describe("HTTP Upstream Suite", func() {
236241 expectedResponse: testHTTPResponse{
237242 code: 200,
238243 header: map[string][]string{
239− gapUpstream: {"existingHeaders"},
240244 contentType: {applicationJSON},
241245 },
242246 request: testHTTPRequest{
@@ -251,11 +255,13 @@ var _ = Describe("HTTP Upstream Suite", func() {
251255 RequestURI: "http://example.localhost/existingHeaders",
252256 },
253257 },
258+ expectedUpstream: "existingHeaders",
254259 }),
255260 )
256261
257262 It("ServeHTTP, when not passing a host header", func() {
258263 req := httptest.NewRequest("", "http://example.localhost/foo", nil)
264+ req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
259265 rw := httptest.NewRecorder()
260266
261267 flush := options.Duration(1 * time.Second)
@@ -383,7 +389,8 @@ var _ = Describe("HTTP Upstream Suite", func() {
383389 Expect(err).ToNot(HaveOccurred())
384390
385391 handler := newHTTPUpstreamProxy(upstream, u, nil, nil)
386− proxyServer = httptest.NewServer(handler)
392+
393+ proxyServer = httptest.NewServer(middleware.NewScope(false)(handler))
387394 })
388395
389396 AfterEach(func() {
@@ -414,7 +421,6 @@ var _ = Describe("HTTP Upstream Suite", func() {
414421 response, err := http.Get(fmt.Sprintf("http://%s", proxyServer.Listener.Addr().String()))
415422 Expect(err).ToNot(HaveOccurred())
416423 Expect(response.StatusCode).To(Equal(200))
417− Expect(response.Header.Get(gapUpstream)).To(Equal("websocketProxy"))
418424 })
419425 })
420426})