-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathreverseproxy_test.go
More file actions
48 lines (37 loc) · 1.38 KB
/
reverseproxy_test.go
File metadata and controls
48 lines (37 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package reverseproxy
import (
"net/http"
"net/http/httptest"
"net/http/httputil"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
// TestBuild_AddHeaders tests that Build's returned ReverseProxy Director adds the proper request headers
func TestBuild_AddHeaders(t *testing.T) {
u, err := url.Parse("http://172.16.200.81:80")
assert.Nil(t, err, "error should be nil")
proxy := Build(u)
assert.NotNil(t, proxy, "Build should not return nil")
req := httptest.NewRequest("GET", "/test", nil)
proxy.Director(req)
// Check that headers were added to req
assert.Equal(t, req.Header.Get(http.CanonicalHeaderKey("X-Forwarded-Proto")), "https",
"X-Forwarded-Proto should be present")
assert.Equal(t, req.Header.Get(http.CanonicalHeaderKey("X-Forwarded-Port")), "443",
"X-Forwarded-Port should be present")
}
func TestNewDirector(t *testing.T) {
u, err := url.Parse("http://172.16.200.81:80")
assert.Nil(t, err, "error should be nil")
director := newDirector(u, nil)
defaultProxy := httputil.NewSingleHostReverseProxy(u)
defaultDirector := defaultProxy.Director
expectedReq := httptest.NewRequest("GET", "/test", nil)
testReq := httptest.NewRequest("GET", "/test", nil)
defaultDirector(expectedReq)
director(testReq)
assert.EqualValues(t, expectedReq, testReq,
"default proxy and package directors should modify the request in the same way")
// TODO: add more test cases
}