mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-08 02:19:33 +00:00
Falls back to SPDY for gorilla/websocket https proxy error
Kubernetes-commit: 6450174ac9a07f15aecfa5f05d58755efc2192b7
This commit is contained in:
committed by
Kubernetes Publisher
parent
4e1652b143
commit
b6e8438bf5
@@ -17,10 +17,12 @@ limitations under the License.
|
||||
package portforward
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/util/httpstream"
|
||||
)
|
||||
|
||||
@@ -36,7 +38,7 @@ func TestFallbackDialer(t *testing.T) {
|
||||
assert.True(t, primary.dialed, "no fallback; primary should have dialed")
|
||||
assert.False(t, secondary.dialed, "no fallback; secondary should *not* have dialed")
|
||||
assert.Equal(t, primaryProtocol, negotiated, "primary negotiated protocol returned")
|
||||
assert.Nil(t, err, "error from primary dialer should be nil")
|
||||
require.NoError(t, err, "error from primary dialer should be nil")
|
||||
// If primary dialer error is upgrade error, then fallback returning secondary dial response.
|
||||
primary = &fakeDialer{dialed: false, negotiatedProtocol: primaryProtocol, err: &httpstream.UpgradeFailureError{}}
|
||||
secondary = &fakeDialer{dialed: false, negotiatedProtocol: secondaryProtocol}
|
||||
@@ -45,7 +47,18 @@ func TestFallbackDialer(t *testing.T) {
|
||||
assert.True(t, primary.dialed, "fallback; primary should have dialed")
|
||||
assert.True(t, secondary.dialed, "fallback; secondary should have dialed")
|
||||
assert.Equal(t, secondaryProtocol, negotiated, "negotiated protocol is from secondary dialer")
|
||||
assert.Nil(t, err, "error from secondary dialer should be nil")
|
||||
require.NoError(t, err, "error from secondary dialer should be nil")
|
||||
// If primary dialer error is https proxy dialing error, then fallback returning secondary dial response.
|
||||
primary = &fakeDialer{negotiatedProtocol: primaryProtocol, err: errors.New("proxy: unknown scheme: https")}
|
||||
secondary = &fakeDialer{negotiatedProtocol: secondaryProtocol}
|
||||
fallbackDialer = NewFallbackDialer(primary, secondary, func(err error) bool {
|
||||
return httpstream.IsUpgradeFailure(err) || httpstream.IsHTTPSProxyError(err)
|
||||
})
|
||||
_, negotiated, err = fallbackDialer.Dial(protocols...)
|
||||
assert.True(t, primary.dialed, "fallback; primary should have dialed")
|
||||
assert.True(t, secondary.dialed, "fallback; secondary should have dialed")
|
||||
assert.Equal(t, secondaryProtocol, negotiated, "negotiated protocol is from secondary dialer")
|
||||
require.NoError(t, err, "error from secondary dialer should be nil")
|
||||
// If primary dialer returns non-upgrade error, then primary error is returned.
|
||||
nonUpgradeErr := fmt.Errorf("This is a non-upgrade error")
|
||||
primary = &fakeDialer{dialed: false, err: nonUpgradeErr}
|
||||
|
Reference in New Issue
Block a user