mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 16:30:17 +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
|
||||
if policy.UpstreamTimeout != nil {
|
||||
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
|
||||
routeTimeout = durationpb.New(0)
|
||||
} else {
|
||||
|
@ -510,15 +510,14 @@ func getRouteIdleTimeout(policy *config.Policy) *durationpb.Duration {
|
|||
var idleTimeout *durationpb.Duration
|
||||
if policy.IdleTimeout != nil {
|
||||
idleTimeout = durationpb.New(*policy.IdleTimeout)
|
||||
} else if shouldDisableTimeouts(policy) {
|
||||
} else if shouldDisableStreamIdleTimeout(policy) {
|
||||
idleTimeout = durationpb.New(0)
|
||||
}
|
||||
return idleTimeout
|
||||
}
|
||||
|
||||
func shouldDisableTimeouts(policy *config.Policy) bool {
|
||||
return policy.IdleTimeout != nil ||
|
||||
policy.AllowWebsockets ||
|
||||
func shouldDisableStreamIdleTimeout(policy *config.Policy) bool {
|
||||
return policy.AllowWebsockets ||
|
||||
urlutil.IsTCP(policy.Source.URL) ||
|
||||
policy.IsForKubernetes() // disable for kubernetes so that tailing logs works (#2182)
|
||||
}
|
||||
|
|
|
@ -227,14 +227,18 @@ func TestTimeouts(t *testing.T) {
|
|||
}
|
||||
|
||||
testCases := []struct {
|
||||
upstream, idle, expect string
|
||||
upstream, idle string
|
||||
allowWebsockets bool
|
||||
expect string
|
||||
}{
|
||||
{"", "", `"timeout": "3s"`},
|
||||
{"", "0s", `"timeout": "0s","idleTimeout": "0s"`},
|
||||
{"", "5s", `"timeout": "0s","idleTimeout": "5s"`},
|
||||
{"5s", "", `"timeout": "5s"`},
|
||||
{"5s", "4s", `"timeout": "5s","idleTimeout": "4s"`},
|
||||
{"0s", "4s", `"timeout": "0s","idleTimeout": "4s"`},
|
||||
{"", "", false, `"timeout": "3s"`},
|
||||
{"", "", true, `"timeout": "0s", "idleTimeout": "0s"`},
|
||||
{"5s", "", true, `"timeout": "5s", "idleTimeout": "0s"`},
|
||||
{"", "0s", false, `"timeout": "3s","idleTimeout": "0s"`},
|
||||
{"", "5s", false, `"timeout": "3s","idleTimeout": "5s"`},
|
||||
{"5s", "", false, `"timeout": "5s"`},
|
||||
{"5s", "4s", false, `"timeout": "5s","idleTimeout": "4s"`},
|
||||
{"0s", "4s", false, `"timeout": "0s","idleTimeout": "4s"`},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
@ -248,20 +252,23 @@ func TestTimeouts(t *testing.T) {
|
|||
Path: "/test",
|
||||
UpstreamTimeout: getDuration(tc.upstream),
|
||||
IdleTimeout: getDuration(tc.idle),
|
||||
AllowWebsockets: tc.allowWebsockets,
|
||||
}},
|
||||
}, "example.com")
|
||||
if !assert.NoError(t, err, "%v", tc) || !assert.Len(t, routes, 1, tc) || !assert.NotNil(t, routes[0].GetRoute(), "%v", tc) {
|
||||
continue
|
||||
}
|
||||
testutil.AssertProtoJSONEqual(t, fmt.Sprintf(`{
|
||||
|
||||
expect := fmt.Sprintf(`{
|
||||
%s,
|
||||
"autoHostRewrite": true,
|
||||
"cluster": "policy",
|
||||
"upgradeConfigs": [
|
||||
{ "enabled": false, "upgradeType": "websocket"},
|
||||
{ "enabled": %v, "upgradeType": "websocket"},
|
||||
{ "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
|
||||
if p.UpstreamTimeout == nil {
|
||||
timeout = durationpb.New(defaultOptions.DefaultUpstreamTimeout)
|
||||
} else {
|
||||
timeout = durationpb.New(*p.UpstreamTimeout)
|
||||
}
|
||||
var idleTimeout *durationpb.Duration
|
||||
if p.IdleTimeout != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue