Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: net/websockets/websocket_channel_test.cc

Issue 157033013: Check for invalid use of data frame opcodes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove |expecting_continuation| parameter from HandleDataFrame() Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/websockets/websocket_channel.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_channel.h" 5 #include "net/websockets/websocket_channel.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 #include <string> 10 #include <string>
(...skipping 2830 matching lines...) Expand 10 before | Expand all | Expand 10 after
2841 static const InitFrame frames[] = { 2841 static const InitFrame frames[] = {
2842 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "foo"}, 2842 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "foo"},
2843 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "bar"}}; 2843 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "bar"}};
2844 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2844 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2845 .WillOnce(ReturnFrames(&frames)) 2845 .WillOnce(ReturnFrames(&frames))
2846 .WillRepeatedly(Return(ERR_IO_PENDING)); 2846 .WillRepeatedly(Return(ERR_IO_PENDING));
2847 2847
2848 CreateChannelAndConnectSuccessfully(); 2848 CreateChannelAndConnectSuccessfully();
2849 } 2849 }
2850 2850
2851 // A new data message cannot start in the middle of another data message.
2852 TEST_F(WebSocketChannelEventInterfaceTest, BogusContinuation) {
2853 scoped_ptr<ReadableFakeWebSocketStream> stream(
2854 new ReadableFakeWebSocketStream);
2855 static const InitFrame frames[] = {
2856 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeBinary,
2857 NOT_MASKED, "frame1"},
2858 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
2859 NOT_MASKED, "frame2"}};
2860 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2861 set_stream(stream.Pass());
2862
2863 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _));
2864 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota));
2865 EXPECT_CALL(
2866 *event_interface_,
2867 OnDataFrame(
2868 false, WebSocketFrameHeader::kOpCodeBinary, AsVector("frame1")));
2869 EXPECT_CALL(
2870 *event_interface_,
2871 OnFailChannel(
2872 "Received start of new message but previous message is unfinished."));
2873
2874 CreateChannelAndConnectSuccessfully();
2875 }
2876
2877 // A new message cannot start with a Continuation frame.
2878 TEST_F(WebSocketChannelEventInterfaceTest, MessageStartingWithContinuation) {
2879 scoped_ptr<ReadableFakeWebSocketStream> stream(
2880 new ReadableFakeWebSocketStream);
2881 static const InitFrame frames[] = {
2882 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
2883 NOT_MASKED, "continuation"}};
2884 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2885 set_stream(stream.Pass());
2886
2887 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _));
2888 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota));
2889 EXPECT_CALL(*event_interface_,
2890 OnFailChannel("Received unexpected continuation frame."));
2891
2892 CreateChannelAndConnectSuccessfully();
2893 }
2894
2851 // If we receive another frame after Close, it is not valid. It is not 2895 // If we receive another frame after Close, it is not valid. It is not
2852 // completely clear what behaviour is required from the standard in this case, 2896 // completely clear what behaviour is required from the standard in this case,
2853 // but the current implementation fails the connection. Since a Close has 2897 // but the current implementation fails the connection. Since a Close has
2854 // already been sent, this just means closing the connection. 2898 // already been sent, this just means closing the connection.
2855 TEST_F(WebSocketChannelStreamTest, PingAfterCloseIsRejected) { 2899 TEST_F(WebSocketChannelStreamTest, PingAfterCloseIsRejected) {
2856 static const InitFrame frames[] = { 2900 static const InitFrame frames[] = {
2857 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 2901 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
2858 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}, 2902 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")},
2859 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePing, 2903 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePing,
2860 NOT_MASKED, "Ping body"}}; 2904 NOT_MASKED, "Ping body"}};
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); 3056 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK");
3013 ASSERT_TRUE(read_frames); 3057 ASSERT_TRUE(read_frames);
3014 // Provide the "Close" message from the server. 3058 // Provide the "Close" message from the server.
3015 *read_frames = CreateFrameVector(frames); 3059 *read_frames = CreateFrameVector(frames);
3016 read_callback.Run(OK); 3060 read_callback.Run(OK);
3017 completion.WaitForResult(); 3061 completion.WaitForResult();
3018 } 3062 }
3019 3063
3020 } // namespace 3064 } // namespace
3021 } // namespace net 3065 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_channel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698