@@ -16,96 +16,94 @@ import (
18var _ = Describe("Proxy Suite", func() {
18var _ = Describe("Proxy Suite", func() {
19− var upstreamServer http.Handler
19+ type proxyTableInput struct {
21+ response testHTTPResponse
23+ upstreams options.Upstreams
21 Context("multiUpstreamProxy", func() {
26 Context("multiUpstreamProxy", func() {
22− BeforeEach(func() {
27+ DescribeTable("Proxy ServeHTTP",
28+ func(in *proxyTableInput) {
23− sigData := &options.SignatureData{Hash: crypto.SHA256, Key: "secret"}
29+ sigData := &options.SignatureData{Hash: crypto.SHA256, Key: "secret"}
25− writer := &pagewriter.WriterFuncs{
26− ProxyErrorFunc: func(rw http.ResponseWriter, _ *http.Request, _ error) {
28− rw.Write([]byte("Proxy Error"))
33− accepted := http.StatusAccepted
35− upstreams := options.Upstreams{
31+ writer := &pagewriter.WriterFuncs{
36− Configs: []options.Upstream{
32+ ProxyErrorFunc: func(rw http.ResponseWriter, _ *http.Request, _ error) {
37− {
33+ rw.WriteHeader(502)
38− ID: "http-backend",
34+ rw.Write([]byte("Proxy Error"))
45− URI: fmt.Sprintf("file:///%s", filesDir),
48− ID: "static-backend",
54− ID: "static-backend-no-trailing-slash",
57− StaticCode: &accepted,
60− ID: "static-backend-long",
61− Path: "/static/long",
63− StaticCode: &accepted,
66− ID: "bad-http-backend",
71− ID: "single-path-backend",
72− Path: "/single-path",
77− ID: "backend-with-rewrite-prefix",
78− Path: "^/rewrite-prefix/(.*)",
79− RewriteTarget: "/different/backend/path/$1",
83− ID: "double-match-plain",
84− Path: "/double-match/",
88− ID: "double-match-rewrite",
89− Path: "^/double-match/(.*)",
90− RewriteTarget: "/double-match/rewrite/$1",
96− var err error
38+ ok := http.StatusOK
97− upstreamServer, err = NewProxy(upstreams, sigData, writer)
39+ accepted := http.StatusAccepted
98− Expect(err).ToNot(HaveOccurred())
101− type proxyTableInput struct {
41+ // Allows for specifying settings and even individual upstreams for specific tests and uses the default upstreams/configs otherwise
102− target string
42+ upstreams := in.upstreams
103− response testHTTPResponse
43+ if len(in.upstreams.Configs) == 0 {
104− upstream string
44+ upstreams.Configs = []options.Upstream{
53+ URI: fmt.Sprintf("file:///%s", filesDir),
56+ ID: "static-backend",
62+ ID: "static-backend-no-trailing-slash",
65+ StaticCode: &accepted,
68+ ID: "static-backend-long",
69+ Path: "/static/long",
71+ StaticCode: &accepted,
74+ ID: "bad-http-backend",
79+ ID: "single-path-backend",
80+ Path: "/single-path",
85+ ID: "backend-with-rewrite-prefix",
86+ Path: "^/rewrite-prefix/(.*)",
87+ RewriteTarget: "/different/backend/path/$1",
91+ ID: "double-match-plain",
92+ Path: "/double-match/",
96+ ID: "double-match-rewrite",
97+ Path: "^/double-match/(.*)",
98+ RewriteTarget: "/double-match/rewrite/$1",
104+ upstreamServer, err := NewProxy(upstreams, sigData, writer)
105+ Expect(err).ToNot(HaveOccurred())
107− DescribeTable("Proxy ServeHTTP",
108− func(in *proxyTableInput) {
109 req := middlewareapi.AddRequestScope(
107 req := middlewareapi.AddRequestScope(
110 httptest.NewRequest("", in.target, nil),
108 httptest.NewRequest("", in.target, nil),
111 &middlewareapi.RequestScope{},
109 &middlewareapi.RequestScope{},
@@ -133,10 +131,12 @@ var _ = Describe("Proxy Suite", func() {
135 // Compare the reflected request to the upstream
133 // Compare the reflected request to the upstream
136− request := testHTTPRequest{}
135+ request := testHTTPRequest{}
137− Expect(json.Unmarshal(body, &request)).To(Succeed())
136+ Expect(json.Unmarshal(body, &request)).To(Succeed())
138− testSanitizeRequestHeader(request.Header)
137+ testSanitizeRequestHeader(request.Header)
139− Expect(request).To(Equal(in.response.request))
138+ Expect(request).To(Equal(in.response.request))
141 Entry("with a request to the HTTP service", &proxyTableInput{
141 Entry("with a request to the HTTP service", &proxyTableInput{
142 target: "http://example.localhost/http/1234",
142 target: "http://example.localhost/http/1234",
@@ -312,6 +312,31 @@ var _ = Describe("Proxy Suite", func() {
313 upstream: "double-match-rewrite",
313 upstream: "double-match-rewrite",
315+ Entry("containing an escaped '/' without ProxyRawPath", &proxyTableInput{
316+ target: "http://example.localhost/%2F/test1/%2F/test2",
317+ response: testHTTPResponse{
319+ header: map[string][]string{
321+ "http://example.localhost/test1/test2",
327+ Entry("containing an escaped '/' with ProxyRawPath", &proxyTableInput{
328+ upstreams: options.Upstreams{ProxyRawPath: true},
329+ target: "http://example.localhost/%2F/test1/%2F/test2",
330+ response: testHTTPResponse{
332+ header: map[string][]string{
333+ "X-Content-Type-Options": {"nosniff"},
334+ contentType: {textPlainUTF8},
336+ raw: "404 page not found\n",
@@ -321,24 +346,24 @@ var _ = Describe("Proxy Suite", func() {
321 expectedOutput []options.Upstream
346 expectedOutput []options.Upstream
324− var httpPath = options.Upstream{
349+ httpPath := options.Upstream{
325 Path: "/http/",
350 Path: "/http/",
328− var httpSubPath = options.Upstream{
353+ httpSubPath := options.Upstream{
329 Path: "/http/subpath/",
354 Path: "/http/subpath/",
332− var longerPath = options.Upstream{
357+ longerPath := options.Upstream{
333 Path: "/longer-than-http",
358 Path: "/longer-than-http",
336− var shortPathWithRewrite = options.Upstream{
361+ shortPathWithRewrite := options.Upstream{
337 Path: "^/h/(.*)",
362 Path: "^/h/(.*)",
338 RewriteTarget: "/$1",
363 RewriteTarget: "/$1",
341− var shortSubPathWithRewrite = options.Upstream{
366+ shortSubPathWithRewrite := options.Upstream{
342 Path: "^/h/bar/(.*)",
367 Path: "^/h/bar/(.*)",
343 RewriteTarget: "/$1",
368 RewriteTarget: "/$1",