mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
fix: timeout field in protobuf, add websocket tests
This commit is contained in:
parent
163e53823c
commit
3073146ff2
3 changed files with 23 additions and 15 deletions
|
@ -497,7 +497,7 @@ func getRouteTimeout(options *config.Options, policy *config.Policy) *durationpb
|
||||||
var routeTimeout *durationpb.Duration
|
var routeTimeout *durationpb.Duration
|
||||||
if policy.UpstreamTimeout != nil {
|
if policy.UpstreamTimeout != nil {
|
||||||
routeTimeout = durationpb.New(*policy.UpstreamTimeout)
|
routeTimeout = durationpb.New(*policy.UpstreamTimeout)
|
||||||
} else if shouldDisableTimeouts(policy) {
|
} else if shouldDisableStreamIdleTimeout(policy) {
|
||||||
// a non-zero value would conflict with idleTimeout and/or websocket / tcp calls
|
// a non-zero value would conflict with idleTimeout and/or websocket / tcp calls
|
||||||
routeTimeout = durationpb.New(0)
|
routeTimeout = durationpb.New(0)
|
||||||
} else {
|
} else {
|
||||||
|
@ -510,15 +510,14 @@ func getRouteIdleTimeout(policy *config.Policy) *durationpb.Duration {
|
||||||
var idleTimeout *durationpb.Duration
|
var idleTimeout *durationpb.Duration
|
||||||
if policy.IdleTimeout != nil {
|
if policy.IdleTimeout != nil {
|
||||||
idleTimeout = durationpb.New(*policy.IdleTimeout)
|
idleTimeout = durationpb.New(*policy.IdleTimeout)
|
||||||
} else if shouldDisableTimeouts(policy) {
|
} else if shouldDisableStreamIdleTimeout(policy) {
|
||||||
idleTimeout = durationpb.New(0)
|
idleTimeout = durationpb.New(0)
|
||||||
}
|
}
|
||||||
return idleTimeout
|
return idleTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldDisableTimeouts(policy *config.Policy) bool {
|
func shouldDisableStreamIdleTimeout(policy *config.Policy) bool {
|
||||||
return policy.IdleTimeout != nil ||
|
return policy.AllowWebsockets ||
|
||||||
policy.AllowWebsockets ||
|
|
||||||
urlutil.IsTCP(policy.Source.URL) ||
|
urlutil.IsTCP(policy.Source.URL) ||
|
||||||
policy.IsForKubernetes() // disable for kubernetes so that tailing logs works (#2182)
|
policy.IsForKubernetes() // disable for kubernetes so that tailing logs works (#2182)
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,14 +227,18 @@ func TestTimeouts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
upstream, idle, expect string
|
upstream, idle string
|
||||||
|
allowWebsockets bool
|
||||||
|
expect string
|
||||||
}{
|
}{
|
||||||
{"", "", `"timeout": "3s"`},
|
{"", "", false, `"timeout": "3s"`},
|
||||||
{"", "0s", `"timeout": "0s","idleTimeout": "0s"`},
|
{"", "", true, `"timeout": "0s", "idleTimeout": "0s"`},
|
||||||
{"", "5s", `"timeout": "0s","idleTimeout": "5s"`},
|
{"5s", "", true, `"timeout": "5s", "idleTimeout": "0s"`},
|
||||||
{"5s", "", `"timeout": "5s"`},
|
{"", "0s", false, `"timeout": "3s","idleTimeout": "0s"`},
|
||||||
{"5s", "4s", `"timeout": "5s","idleTimeout": "4s"`},
|
{"", "5s", false, `"timeout": "3s","idleTimeout": "5s"`},
|
||||||
{"0s", "4s", `"timeout": "0s","idleTimeout": "4s"`},
|
{"5s", "", false, `"timeout": "5s"`},
|
||||||
|
{"5s", "4s", false, `"timeout": "5s","idleTimeout": "4s"`},
|
||||||
|
{"0s", "4s", false, `"timeout": "0s","idleTimeout": "4s"`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
@ -248,20 +252,23 @@ func TestTimeouts(t *testing.T) {
|
||||||
Path: "/test",
|
Path: "/test",
|
||||||
UpstreamTimeout: getDuration(tc.upstream),
|
UpstreamTimeout: getDuration(tc.upstream),
|
||||||
IdleTimeout: getDuration(tc.idle),
|
IdleTimeout: getDuration(tc.idle),
|
||||||
|
AllowWebsockets: tc.allowWebsockets,
|
||||||
}},
|
}},
|
||||||
}, "example.com")
|
}, "example.com")
|
||||||
if !assert.NoError(t, err, "%v", tc) || !assert.Len(t, routes, 1, tc) || !assert.NotNil(t, routes[0].GetRoute(), "%v", tc) {
|
if !assert.NoError(t, err, "%v", tc) || !assert.Len(t, routes, 1, tc) || !assert.NotNil(t, routes[0].GetRoute(), "%v", tc) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
testutil.AssertProtoJSONEqual(t, fmt.Sprintf(`{
|
|
||||||
|
expect := fmt.Sprintf(`{
|
||||||
%s,
|
%s,
|
||||||
"autoHostRewrite": true,
|
"autoHostRewrite": true,
|
||||||
"cluster": "policy",
|
"cluster": "policy",
|
||||||
"upgradeConfigs": [
|
"upgradeConfigs": [
|
||||||
{ "enabled": false, "upgradeType": "websocket"},
|
{ "enabled": %v, "upgradeType": "websocket"},
|
||||||
{ "enabled": false, "upgradeType": "spdy/3.1"}
|
{ "enabled": false, "upgradeType": "spdy/3.1"}
|
||||||
]
|
]
|
||||||
}`, tc.expect), routes[0].GetRoute())
|
}`, tc.expect, tc.allowWebsockets)
|
||||||
|
testutil.AssertProtoJSONEqual(t, expect, routes[0].GetRoute())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,6 +296,8 @@ func (p *Policy) ToProto() (*configpb.Route, error) {
|
||||||
var timeout *durationpb.Duration
|
var timeout *durationpb.Duration
|
||||||
if p.UpstreamTimeout == nil {
|
if p.UpstreamTimeout == nil {
|
||||||
timeout = durationpb.New(defaultOptions.DefaultUpstreamTimeout)
|
timeout = durationpb.New(defaultOptions.DefaultUpstreamTimeout)
|
||||||
|
} else {
|
||||||
|
timeout = durationpb.New(*p.UpstreamTimeout)
|
||||||
}
|
}
|
||||||
var idleTimeout *durationpb.Duration
|
var idleTimeout *durationpb.Duration
|
||||||
if p.IdleTimeout != nil {
|
if p.IdleTimeout != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue