// TestWebSocketClient_LoopbackStdinToStdout returns random data sent on the STDIN channel // back down the STDOUT channel. A subsequent comparison checks if the data // sent on the STDIN channel is the same as the data returned on the STDOUT // channel. This test can be run many times by the "stress" tool to check // if there is any data which would cause problems with the WebSocket streams. func TestWebSocketClient_LoopbackStdinToStdout(t *testing.T) { … } // TestWebSocketClient_DifferentBufferSizes runs the previous loopback (STDIN -> STDOUT) test with different // buffer sizes for reading from the opposite end of the websocket connection (in the websocket server). func TestWebSocketClient_DifferentBufferSizes(t *testing.T) { … } // TestWebSocketClient_LoopbackStdinAsPipe uses a pipe to send random data on the STDIN // channel, then closes the pipe. The fake server simply returns all STDIN data back // onto the STDOUT channel, and the received data on STDOUT is validated against the // random data initially sent. func TestWebSocketClient_LoopbackStdinAsPipe(t *testing.T) { … } // TestWebSocketClient_LoopbackStdinToStderr returns random data sent on the STDIN channel // back down the STDERR channel. A subsequent comparison checks if the data // sent on the STDIN channel is the same as the data returned on the STDERR // channel. This test can be run many times by the "stress" tool to check // if there is any data which would cause problems with the WebSocket streams. func TestWebSocketClient_LoopbackStdinToStderr(t *testing.T) { … } // TestWebSocketClient_MultipleReadChannels tests two streams (STDOUT, STDERR) reading from // the websocket connection at the same time. func TestWebSocketClient_MultipleReadChannels(t *testing.T) { … } // Returns a random exit code in the range(1-127). func randomExitCode() int { … } // TestWebSocketClient_ErrorStream tests the websocket error stream by hard-coding a // structured non-zero exit code error from the websocket server to the websocket client. func TestWebSocketClient_ErrorStream(t *testing.T) { … } type fakeTerminalSizeQueue … // newTerminalSizeQueue returns a pointer to a fakeTerminalSizeQueue passing // "max" number of random TerminalSizes created. func newTerminalSizeQueue(max int) *fakeTerminalSizeQueue { … } // Next returns a pointer to the next random TerminalSize, or nil if we have // already returned "maxSizes" TerminalSizes already. Stores the randomly // created TerminalSize in "terminalSizes" field for later validation. func (f *fakeTerminalSizeQueue) Next() *TerminalSize { … } // randomTerminalSize returns a TerminalSize with random values in the // range (0-65535) for the fields Width and Height. func randomTerminalSize() TerminalSize { … } type randReader … // Read implements the Reader interface filling the passed buffer with // random data, returning the number of bytes filled and an error // if one occurs. Return 0 and EOF if the randReader has been closed. func (r *randReader) Read(b []byte) (int, error) { … } // Close implements the Closer interface, setting the close field true. // Further calls to Read() after Close() will return 0, EOF. Returns // nil error. func (r *randReader) Close() (err error) { … } // TestWebSocketClient_MultipleWriteChannels tests two streams (STDIN, TTY resize) writing to the // websocket connection at the same time to exercise the connection write lock. func TestWebSocketClient_MultipleWriteChannels(t *testing.T) { … } // TestWebSocketClient_ProtocolVersions validates that remote command subprotocol versions V2-V4 // (V5 is already tested elsewhere) can be negotiated. func TestWebSocketClient_ProtocolVersions(t *testing.T) { … } // TestWebSocketClient_BadHandshake tests that a "bad handshake" error occurs when // the WebSocketExecutor attempts to upgrade the connection to a subprotocol version // (V4) that is not supported by the websocket server (only supports V5). func TestWebSocketClient_BadHandshake(t *testing.T) { … } // TestWebSocketClient_HeartbeatTimeout tests the heartbeat by forcing a // timeout by setting the ping period greater than the deadline. func TestWebSocketClient_HeartbeatTimeout(t *testing.T) { … } // TestWebSocketClient_TextMessageTypeError tests when the wrong message type is returned // from the other websocket endpoint. Remote command protocols use "BinaryMessage", but // this test hard-codes returning a "TextMessage". func TestWebSocketClient_TextMessageTypeError(t *testing.T) { … } // TestWebSocketClient_EmptyMessageHandled tests that the error of a completely empty message // is handled correctly. If the message is completely empty, the initial read of the stream id // should fail (followed by cleanup). func TestWebSocketClient_EmptyMessageHandled(t *testing.T) { … } func TestWebSocketClient_ExecutorErrors(t *testing.T) { … } func TestWebSocketClient_HeartbeatSucceeds(t *testing.T) { … } func TestLateStreamCreation(t *testing.T) { … } func TestWebSocketClient_StreamsAndExpectedErrors(t *testing.T) { … } type options … // Translates query params in request into options struct. func streamOptionsFromRequest(req *http.Request) *options { … } type websocketStreams … // Create WebSocket server streams to respond to a WebSocket client. Creates the streams passed // in the stream options. func webSocketServerStreams(req *http.Request, w http.ResponseWriter, opts *options) (*websocketStreams, error) { … } // Read terminal resize events off of passed stream and queue into passed channel. func handleResizeEvents(ctx context.Context, stream io.Reader, channel chan<- TerminalSize) { … } // createChannels returns the standard channel types for a shell connection (STDIN 0, STDOUT 1, STDERR 2) // along with the approximate duplex value. It also creates the error (3) and resize (4) channels. func createChannels(opts *options) []wsstream.ChannelType { … } // readChannel returns wsstream.ReadChannel if real is true, or wsstream.IgnoreChannel. func readChannel(real bool) wsstream.ChannelType { … } // writeChannel returns wsstream.WriteChannel if real is true, or wsstream.IgnoreChannel. func writeChannel(real bool) wsstream.ChannelType { … } // createWebSocketStreams returns a "channels" struct containing the websocket connection and // streams needed to perform an exec or an attach. func createWebSocketStreams(req *http.Request, w http.ResponseWriter, opts *options) (*websocketStreams, error) { … } // See (https://github.com/kubernetes/kubernetes/issues/126134). func TestWebSocketClient_HTTPSProxyErrorExpected(t *testing.T) { … }