Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sso_proxy: don't set timeout when flush interval is set #200

Merged
merged 1 commit into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/proxy/reverse_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func NewUpstreamReverseProxy(config *UpstreamConfig, signer *RequestSigner) (htt
var handler http.Handler = reverseProxy

// Apply a timeout handler if configured
if config.Timeout != 0 {
// http.TimeoutHandler doesn't support flushing, so only create one if no flush interval is set.
if config.FlushInterval == 0 && config.Timeout != 0 {
handler = newTimeoutHandler(handler, config)
}

Expand Down
71 changes: 54 additions & 17 deletions internal/proxy/reverse_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,57 +159,57 @@ func TestNewRewriteReverseProxy(t *testing.T) {
expectedStatus int
}{
{
name: "tls true skip verify false preserve host false",
name: "tls=true, skipVerify=false, preserveHost=false",
useTLS: true,
skipVerify: false,
preserveHost: false,
expectedStatus: 502,
},
{
name: "tls true skip verify true preserve host false",
name: "tls=true, skipVerify=true, preserveHost=false",
useTLS: true,
skipVerify: true,
preserveHost: false,
expectedStatus: 200,
},
{
name: "tls true skip verify false preserve host true",
name: "tls=true, skipVerify=false, preserveHost=true",
useTLS: true,
skipVerify: false,
preserveHost: true,
expectedStatus: 502,
},
{
name: "tls true skip verify true preserve host true",
name: "tls=true, skipVerify=true, preserveHost=true",
useTLS: true,
skipVerify: true,
preserveHost: true,
expectedStatus: 200,
},

{
name: "tls false skip verify false preserve host false",
name: "tls=false, skipVerify=false, preserveHost=false",
useTLS: false,
skipVerify: false,
preserveHost: false,
expectedStatus: 200,
},
{
name: "tls false skip verify true preserve host false",
name: "tls=false, skipVerif=true, preserveHost=false",
useTLS: false,
skipVerify: true,
preserveHost: false,
expectedStatus: 200,
},
{
name: "tls false skip verify false preserve host true",
name: "tls=false, skipVerify=false, preserveHost=true",
useTLS: false,
skipVerify: false,
preserveHost: true,
expectedStatus: 200,
},
{
name: "tls false skip verify true preserve host true",
name: "tls=false, skipVerify=true, preserveHost=true",
useTLS: false,
skipVerify: true,
preserveHost: true,
Expand Down Expand Up @@ -311,65 +311,89 @@ func TestNewReverseProxy(t *testing.T) {
useTLS bool
skipVerify bool
preserveHost bool
flushInterval time.Duration
timeout time.Duration
expectedStatus int
expectedBody string
}{
{
name: "tls true skip verify false preserve host false",
name: "tls=true, skipVerify=false, preserveHost=false",
useTLS: true,
skipVerify: false,
preserveHost: false,
expectedStatus: 502,
},
{
name: "tls true skip verify true preserve host false",
name: "tls=true, skipVerify=true, preserveHost=false",
useTLS: true,
skipVerify: true,
preserveHost: false,
expectedStatus: 200,
},
{
name: "tls true skip verify false preserve host true",
name: "tls=true, skipVerify=false, preserveHost=true",
useTLS: true,
skipVerify: false,
preserveHost: true,
expectedStatus: 502,
},
{
name: "tls true skip verify true preserve host true",
name: "tls=true, skipVerify=true, preserveHost=true",
useTLS: true,
skipVerify: true,
preserveHost: true,
expectedStatus: 200,
},

{
name: "tls false skip verify false preserve host false",
name: "tls=false, skipVerify=false, preserveHost=false",
useTLS: false,
skipVerify: false,
preserveHost: false,
expectedStatus: 200,
},
{
name: "tls false skip verify true preserve host false",
name: "tls=false, skipVerify=true, preserveHost=false",
useTLS: false,
skipVerify: true,
preserveHost: false,
expectedStatus: 200,
},
{
name: "tls false skip verify false preserve host true",
name: "tls=false, skipVerify=false, preserveHost=true",
useTLS: false,
skipVerify: false,
preserveHost: true,
expectedStatus: 200,
},
{
name: "tls false skip verify true preserve host true",
name: "tls=false, skipVerify=true, preserveHost=true",
useTLS: false,
skipVerify: true,
preserveHost: true,
expectedStatus: 200,
},
{
// When request flushing is enabled the timeout should be ignored, so force a timeout
// that would be met.
name: "tls=false, skipVerify=true, preserveHost=false, flush=enabled",
useTLS: false,
skipVerify: true,
preserveHost: false,
flushInterval: time.Duration(10) * time.Millisecond,
timeout: time.Duration(25) * time.Millisecond,
expectedStatus: 200,
},
{
name: "tls=false, skipVerify=true, preserveHost=false, flush=disabled",
useTLS: false,
skipVerify: true,
preserveHost: false,
flushInterval: 0,
timeout: time.Duration(25) * time.Millisecond,
expectedStatus: 503,
expectedBody: " failed to respond within the 25ms timeout period",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -389,6 +413,10 @@ func TestNewReverseProxy(t *testing.T) {
if err != nil {
t.Fatalf("expected to marshal json: %s", err)
}
if tc.timeout != 0 {
timer := time.NewTimer(tc.timeout + time.Duration(25)*time.Millisecond)
<-timer.C
}
rw.Write(body)
}))
defer to.Close()
Expand All @@ -404,6 +432,8 @@ func TestNewReverseProxy(t *testing.T) {
},
TLSSkipVerify: tc.skipVerify,
PreserveHost: tc.preserveHost,
FlushInterval: tc.flushInterval,
Timeout: tc.timeout,
}
reverseProxy, err := NewUpstreamReverseProxy(config, nil)
if err != nil {
Expand Down Expand Up @@ -439,7 +469,14 @@ func TestNewReverseProxy(t *testing.T) {
t.Logf(" got status code: %v", res.StatusCode)
t.Logf("want status code: %d", tc.expectedStatus)

t.Errorf("got unexpected response code for tls failure")
t.Errorf("got unexpected response code")
}

if tc.expectedBody != "" && string(body) != tc.expectedBody {
t.Logf(" got response body: %q", body)
t.Logf("want response body: %q", tc.expectedBody)

t.Errorf("got unexpected response body")
}

if res.StatusCode >= 200 && res.StatusCode < 300 {
Expand Down