11 "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/options"
12 . "github.com/onsi/ginkgo"
13 . "github.com/onsi/ginkgo/extensions/table"
14 . "github.com/onsi/gomega"
17var _ = Describe("Proxy Suite", func() {
18 var upstreamServer http.Handler
21 sigData := &options.SignatureData{Hash: crypto.SHA256, Key: "secret"}
23 tmpl, err := template.New("").Parse("{{ .Title }}\n{{ .Message }}\n{{ .ProxyPrefix }}")
24 Expect(err).ToNot(HaveOccurred())
25 errorHandler := NewProxyErrorHandler(tmpl, "prefix")
29 upstreams := options.Upstreams{
38 URI: fmt.Sprintf("file:///%s", filesDir),
47 ID: "bad-http-backend",
52 ID: "single-path-backend",
59 upstreamServer, err = NewProxy(upstreams, sigData, errorHandler)
60 Expect(err).ToNot(HaveOccurred())
63 type proxyTableInput struct {
65 response testHTTPResponse
68 DescribeTable("Proxy ServerHTTP",
69 func(in *proxyTableInput) {
70 req := httptest.NewRequest("", in.target, nil)
71 rw := httptest.NewRecorder()
72 // Don't mock the remote Address
75 upstreamServer.ServeHTTP(rw, req)
77 Expect(rw.Code).To(Equal(in.response.code))
79 // Delete extra headers that aren't relevant to tests
80 testSanitizeResponseHeader(rw.Header())
81 Expect(rw.Header()).To(Equal(in.response.header))
83 body := rw.Body.Bytes()
84 // If the raw body is set, check that, else check the Request object
85 if in.response.raw != "" {
86 Expect(string(body)).To(Equal(in.response.raw))
90 // Compare the reflected request to the upstream
91 request := testHTTPRequest{}
92 Expect(json.Unmarshal(body, &request)).To(Succeed())
93 testSanitizeRequestHeader(request.Header)
94 Expect(request).To(Equal(in.response.request))
96 Entry("with a request to the HTTP service", &proxyTableInput{
97 target: "http://example.localhost/http/1234",
98 response: testHTTPResponse{
100 header: map[string][]string{
101 gapUpstream: {"http-backend"},
102 contentType: {applicationJSON},
104 request: testHTTPRequest{
106 URL: "http://example.localhost/http/1234",
107 Header: map[string][]string{
109 "Gap-Signature": {"sha256 ofB1u6+FhEUbFLc3/uGbJVkl7GaN4egFqVvyO3+2I1w="},
112 Host: "example.localhost",
113 RequestURI: "http://example.localhost/http/1234",
117 Entry("with a request to the File backend", &proxyTableInput{
118 target: "http://example.localhost/files/foo",
119 response: testHTTPResponse{
121 header: map[string][]string{
122 contentType: {textPlainUTF8},
123 gapUpstream: {"file-backend"},
128 Entry("with a request to the Static backend", &proxyTableInput{
129 target: "http://example.localhost/static/bar",
130 response: testHTTPResponse{
132 header: map[string][]string{
133 gapUpstream: {"static-backend"},
135 raw: "Authenticated",
138 Entry("with a request to the bad HTTP backend", &proxyTableInput{
139 target: "http://example.localhost/bad-http/bad",
140 response: testHTTPResponse{
142 header: map[string][]string{
143 gapUpstream: {"bad-http-backend"},
145 // This tests the error handler
146 raw: "Bad Gateway\nError proxying to upstream server\nprefix",
149 Entry("with a request to the to an unregistered path", &proxyTableInput{
150 target: "http://example.localhost/unregistered",
151 response: testHTTPResponse{
153 header: map[string][]string{
154 "X-Content-Type-Options": {"nosniff"},
155 contentType: {textPlainUTF8},
157 raw: "404 page not found\n",
160 Entry("with a request to the to backend registered to a single path", &proxyTableInput{
161 target: "http://example.localhost/single-path",
162 response: testHTTPResponse{
164 header: map[string][]string{
165 gapUpstream: {"single-path-backend"},
167 raw: "Authenticated",
170 Entry("with a request to the to a subpath of a backend registered to a single path", &proxyTableInput{
171 target: "http://example.localhost/single-path/unregistered",
172 response: testHTTPResponse{
174 header: map[string][]string{
175 "X-Content-Type-Options": {"nosniff"},
176 contentType: {textPlainUTF8},
178 raw: "404 page not found\n",
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list