Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
hybi13.cpp File Reference
Include dependency graph for hybi13.cpp:

Go to the source code of this file.

Classes

struct  stub_config
 
struct  stub_config::permessage_deflate_config
 Extension specific config. More...
 
struct  stub_config_ext
 
struct  stub_config_ext::permessage_deflate_config
 
struct  processor_setup
 
struct  processor_setup_ext
 

Macros

#define BOOST_TEST_MODULE   hybi_13_processor
 

Typedefs

typedef stub_config::con_msg_manager_type con_msg_manager_type
 

Functions

 BOOST_AUTO_TEST_CASE (exact_match)
 
 BOOST_AUTO_TEST_CASE (non_get_method)
 
 BOOST_AUTO_TEST_CASE (old_http_version)
 
 BOOST_AUTO_TEST_CASE (missing_handshake_key1)
 
 BOOST_AUTO_TEST_CASE (missing_handshake_key2)
 
 BOOST_AUTO_TEST_CASE (bad_host)
 
 BOOST_AUTO_TEST_CASE (frame_empty_binary_unmasked)
 
 BOOST_AUTO_TEST_CASE (frame_small_binary_unmasked)
 
 BOOST_AUTO_TEST_CASE (frame_extended_binary_unmasked)
 
 BOOST_AUTO_TEST_CASE (frame_jumbo_binary_unmasked)
 
 BOOST_AUTO_TEST_CASE (control_frame_too_large)
 
 BOOST_AUTO_TEST_CASE (rsv_bits_used)
 
 BOOST_AUTO_TEST_CASE (reserved_opcode_used)
 
 BOOST_AUTO_TEST_CASE (fragmented_control_message)
 
 BOOST_AUTO_TEST_CASE (fragmented_binary_message)
 
 BOOST_AUTO_TEST_CASE (unmasked_client_frame)
 
 BOOST_AUTO_TEST_CASE (masked_server_frame)
 
 BOOST_AUTO_TEST_CASE (frame_small_binary_masked)
 
 BOOST_AUTO_TEST_CASE (masked_fragmented_binary_message)
 
 BOOST_AUTO_TEST_CASE (prepare_data_frame)
 
 BOOST_AUTO_TEST_CASE (single_frame_message_too_large)
 
 BOOST_AUTO_TEST_CASE (multiple_frame_message_too_large)
 
 BOOST_AUTO_TEST_CASE (client_handshake_request)
 
 BOOST_AUTO_TEST_CASE (client_handshake_response_404)
 
 BOOST_AUTO_TEST_CASE (client_handshake_response_no_upgrade)
 
 BOOST_AUTO_TEST_CASE (client_handshake_response_no_connection)
 
 BOOST_AUTO_TEST_CASE (client_handshake_response_no_accept)
 
 BOOST_AUTO_TEST_CASE (client_handshake_response)
 
 BOOST_AUTO_TEST_CASE (extensions_disabled)
 
 BOOST_AUTO_TEST_CASE (extension_negotiation_blank)
 
 BOOST_AUTO_TEST_CASE (extension_negotiation_unknown)
 
 BOOST_AUTO_TEST_CASE (extract_subprotocols_empty)
 
 BOOST_AUTO_TEST_CASE (extract_subprotocols_one)
 
 BOOST_AUTO_TEST_CASE (extract_subprotocols_multiple)
 
 BOOST_AUTO_TEST_CASE (extract_subprotocols_invalid)
 
 BOOST_AUTO_TEST_CASE (extension_negotiation_permessage_deflate)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   hybi_13_processor

Definition at line 28 of file hybi13.cpp.

Typedef Documentation

◆ con_msg_manager_type

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/36]

BOOST_AUTO_TEST_CASE ( bad_host )

Definition at line 195 of file hybi13.cpp.

195 {
196 processor_setup env(true);
197
198 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
199
200 env.req.consume(handshake.c_str(),handshake.size());
201
203 BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
204 BOOST_CHECK( !env.p.validate_handshake(env.req) );
205 BOOST_CHECK( !env.p.get_uri(env.req)->get_valid() );
206}
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
bool is_websocket_handshake(request_type &r)
Determine whether or not a generic HTTP request is a WebSocket handshake.
Definition processor.hpp:68
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/36]

BOOST_AUTO_TEST_CASE ( client_handshake_request )

Definition at line 525 of file hybi13.cpp.

525 {
526 processor_setup env(false);
527
528 websocketpp::uri_ptr u(new websocketpp::uri("ws://localhost/"));
529
530 env.p.client_handshake_request(env.req,u, std::vector<std::string>());
531
532 BOOST_CHECK_EQUAL( env.req.get_method(), "GET" );
533 BOOST_CHECK_EQUAL( env.req.get_version(), "HTTP/1.1");
534 BOOST_CHECK_EQUAL( env.req.get_uri(), "/");
535
536 BOOST_CHECK_EQUAL( env.req.get_header("Host"), "localhost");
537 BOOST_CHECK_EQUAL( env.req.get_header("Sec-WebSocket-Version"), "13");
538 BOOST_CHECK_EQUAL( env.req.get_header("Connection"), "Upgrade");
539 BOOST_CHECK_EQUAL( env.req.get_header("Upgrade"), "websocket");
540}
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition uri.hpp:351
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/36]

BOOST_AUTO_TEST_CASE ( client_handshake_response )

Definition at line 593 of file hybi13.cpp.

593 {
594 processor_setup env(false);
595
596 env.req.append_header("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
597
598 std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\nConnection: bar, UpGrAdE\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n";
599 env.res.consume(res.data(),res.size());
600
601 BOOST_CHECK( !env.p.validate_server_handshake_response(env.req,env.res) );
602}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/36]

BOOST_AUTO_TEST_CASE ( client_handshake_response_404 )

Definition at line 557 of file hybi13.cpp.

557 {
558 processor_setup env(false);
559
560 std::string res = "HTTP/1.1 404 Not Found\r\n\r\n";
561 env.res.consume(res.data(),res.size());
562
563 BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::invalid_http_status );
564}
@ invalid_http_status
Invalid HTTP status.
Definition base.hpp:126
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/36]

BOOST_AUTO_TEST_CASE ( client_handshake_response_no_accept )

Definition at line 584 of file hybi13.cpp.

584 {
585 processor_setup env(false);
586
587 std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\nConnection: bar, UpGrAdE\r\n\r\n";
588 env.res.consume(res.data(),res.size());
589
590 BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
591}
@ missing_required_header
Missing Required Header.
Definition base.hpp:129
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/36]

BOOST_AUTO_TEST_CASE ( client_handshake_response_no_connection )

Definition at line 575 of file hybi13.cpp.

575 {
576 processor_setup env(false);
577
578 std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\n\r\n";
579 env.res.consume(res.data(),res.size());
580
581 BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
582}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/36]

BOOST_AUTO_TEST_CASE ( client_handshake_response_no_upgrade )

Definition at line 566 of file hybi13.cpp.

566 {
567 processor_setup env(false);
568
569 std::string res = "HTTP/1.1 101 Switching Protocols\r\n\r\n";
570 env.res.consume(res.data(),res.size());
571
572 BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
573}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/36]

BOOST_AUTO_TEST_CASE ( control_frame_too_large )

Definition at line 301 of file hybi13.cpp.

301 {
302 processor_setup env(false);
303
304 uint8_t frame[130] = {0x88, 0x7E, 0x00, 0x7E};
305 std::fill_n(frame+4,126,0x2A);
306
307 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
308 BOOST_CHECK_GT( env.p.consume(frame,130,env.ec), 0 );
309 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::control_too_big );
310 BOOST_CHECK_EQUAL( env.p.ready(), false );
311}
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
@ control_too_big
Control frame too large.
Definition base.hpp:90
unsigned char uint8_t
Definition stdint.h:124
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/36]

BOOST_AUTO_TEST_CASE ( exact_match )

Definition at line 120 of file hybi13.cpp.

120 {
121 processor_setup env(true);
122
123 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
124
125 env.req.consume(handshake.c_str(),handshake.size());
126
128 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
129 BOOST_CHECK(!env.p.validate_handshake(env.req));
130
132
133 BOOST_CHECK_NO_THROW( u = env.p.get_uri(env.req) );
134
135 BOOST_CHECK_EQUAL(u->get_secure(), false);
136 BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
137 BOOST_CHECK_EQUAL(u->get_resource(), "/");
138 BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
139
140 env.p.process_handshake(env.req,"",env.res);
141
142 BOOST_CHECK_EQUAL(env.res.get_header("Connection"), "upgrade");
143 BOOST_CHECK_EQUAL(env.res.get_header("Upgrade"), "websocket");
144 BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Accept"), "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
145}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [10/36]

BOOST_AUTO_TEST_CASE ( extension_negotiation_blank )

Definition at line 616 of file hybi13.cpp.

616 {
617 processor_setup_ext env(true);
618
619 env.req.replace_header("Sec-WebSocket-Extensions","");
620
621 std::pair<websocketpp::lib::error_code,std::string> neg_results;
622 neg_results = env.p.negotiate_extensions(env.req);
623
624 BOOST_CHECK( !neg_results.first );
625 BOOST_CHECK_EQUAL( neg_results.second, "" );
626}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [11/36]

BOOST_AUTO_TEST_CASE ( extension_negotiation_permessage_deflate )

Definition at line 681 of file hybi13.cpp.

681 {
682 processor_setup_ext env(true);
683
684 env.req.replace_header("Sec-WebSocket-Extensions",
685 "permessage-deflate; client_max_window_bits");
686
687 std::pair<websocketpp::lib::error_code,std::string> neg_results;
688 neg_results = env.p.negotiate_extensions(env.req);
689
690 BOOST_CHECK( !neg_results.first );
691 BOOST_CHECK_EQUAL( neg_results.second, "permessage-deflate" );
692}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [12/36]

BOOST_AUTO_TEST_CASE ( extension_negotiation_unknown )

Definition at line 628 of file hybi13.cpp.

628 {
629 processor_setup_ext env(true);
630
631 env.req.replace_header("Sec-WebSocket-Extensions","foo");
632
633 std::pair<websocketpp::lib::error_code,std::string> neg_results;
634 neg_results = env.p.negotiate_extensions(env.req);
635
636 BOOST_CHECK( !neg_results.first );
637 BOOST_CHECK_EQUAL( neg_results.second, "" );
638}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [13/36]

BOOST_AUTO_TEST_CASE ( extensions_disabled )

Definition at line 604 of file hybi13.cpp.

604 {
605 processor_setup env(true);
606
607 env.req.replace_header("Sec-WebSocket-Extensions","");
608
609 std::pair<websocketpp::lib::error_code,std::string> neg_results;
610 neg_results = env.p.negotiate_extensions(env.req);
611
612 BOOST_CHECK_EQUAL( neg_results.first, websocketpp::processor::error::extensions_disabled );
613 BOOST_CHECK_EQUAL( neg_results.second, "" );
614}
@ extensions_disabled
Extension related operation was ignored because extensions are disabled.
Definition base.hpp:153
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [14/36]

BOOST_AUTO_TEST_CASE ( extract_subprotocols_empty )

Definition at line 640 of file hybi13.cpp.

640 {
641 processor_setup env(true);
642 std::vector<std::string> subps;
643
644 BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
645 BOOST_CHECK_EQUAL( subps.size(), 0 );
646}
void subps(const Xmm &xmm, const Operand &op)
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [15/36]

BOOST_AUTO_TEST_CASE ( extract_subprotocols_invalid )

Definition at line 671 of file hybi13.cpp.

671 {
672 processor_setup env(true);
673 std::vector<std::string> subps;
674
675 env.req.replace_header("Sec-WebSocket-Protocol","foo,bar,,,,");
676
678 BOOST_CHECK_EQUAL( subps.size(), 0 );
679}
@ subprotocol_parse_error
Error parsing subprotocols.
Definition base.hpp:147
lib::error_code make_error_code(error::processor_errors e)
Create an error code with the given value and the processor category.
Definition base.hpp:244
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [16/36]

BOOST_AUTO_TEST_CASE ( extract_subprotocols_multiple )

Definition at line 659 of file hybi13.cpp.

659 {
660 processor_setup env(true);
661 std::vector<std::string> subps;
662
663 env.req.replace_header("Sec-WebSocket-Protocol","foo,bar");
664
665 BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
666 BOOST_REQUIRE_EQUAL( subps.size(), 2 );
667 BOOST_CHECK_EQUAL( subps[0], "foo" );
668 BOOST_CHECK_EQUAL( subps[1], "bar" );
669}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [17/36]

BOOST_AUTO_TEST_CASE ( extract_subprotocols_one )

Definition at line 648 of file hybi13.cpp.

648 {
649 processor_setup env(true);
650 std::vector<std::string> subps;
651
652 env.req.replace_header("Sec-WebSocket-Protocol","foo");
653
654 BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
655 BOOST_REQUIRE_EQUAL( subps.size(), 1 );
656 BOOST_CHECK_EQUAL( subps[0], "foo" );
657}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [18/36]

BOOST_AUTO_TEST_CASE ( fragmented_binary_message )

Definition at line 362 of file hybi13.cpp.

362 {
363 processor_setup env0(false);
364 processor_setup env1(false);
365
366 uint8_t frame0[6] = {0x02, 0x01, 0x2A, 0x80, 0x01, 0x2A};
367 uint8_t frame1[8] = {0x02, 0x01, 0x2A, 0x89, 0x00, 0x80, 0x01, 0x2A};
368
369 // read fragmented message in one chunk
370 BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
371 BOOST_CHECK_EQUAL( env0.p.consume(frame0,6,env0.ec), 6 );
372 BOOST_CHECK( !env0.ec );
373 BOOST_CHECK_EQUAL( env0.p.ready(), true );
374 BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
375
376 // read fragmented message in two chunks
377 BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
378 BOOST_CHECK_EQUAL( env0.p.consume(frame0,3,env0.ec), 3 );
379 BOOST_CHECK( !env0.ec );
380 BOOST_CHECK_EQUAL( env0.p.ready(), false );
381 BOOST_CHECK_EQUAL( env0.p.consume(frame0+3,3,env0.ec), 3 );
382 BOOST_CHECK( !env0.ec );
383 BOOST_CHECK_EQUAL( env0.p.ready(), true );
384 BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
385
386 // read fragmented message with control message in between
387 BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
388 BOOST_CHECK_EQUAL( env0.p.consume(frame1,8,env0.ec), 5 );
389 BOOST_CHECK( !env0.ec );
390 BOOST_CHECK_EQUAL( env0.p.ready(), true );
391 BOOST_CHECK_EQUAL( env0.p.get_message()->get_opcode(), websocketpp::frame::opcode::PING);
392 BOOST_CHECK_EQUAL( env0.p.consume(frame1+5,3,env0.ec), 3 );
393 BOOST_CHECK( !env0.ec );
394 BOOST_CHECK_EQUAL( env0.p.ready(), true );
395 BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
396
397 // read lone continuation frame
398 BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
399 BOOST_CHECK_GT( env0.p.consume(frame0+3,3,env0.ec), 0);
400 BOOST_CHECK_EQUAL( env0.ec, websocketpp::processor::error::invalid_continuation );
401
402 // read two start frames in a row
403 BOOST_CHECK_EQUAL( env1.p.get_message(), message_ptr() );
404 BOOST_CHECK_EQUAL( env1.p.consume(frame0,3,env1.ec), 3);
405 BOOST_CHECK( !env1.ec );
406 BOOST_CHECK_GT( env1.p.consume(frame0,3,env1.ec), 0);
407 BOOST_CHECK_EQUAL( env1.ec, websocketpp::processor::error::invalid_continuation );
408}
@ invalid_continuation
Continuation without message.
Definition base.hpp:99
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [19/36]

BOOST_AUTO_TEST_CASE ( fragmented_control_message )

Definition at line 351 of file hybi13.cpp.

351 {
352 processor_setup env(false);
353
354 uint8_t frame[2] = {0x08, 0x00};
355
356 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
357 BOOST_CHECK_GT( env.p.consume(frame,2,env.ec), 0 );
358 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::fragmented_control );
359 BOOST_CHECK_EQUAL( env.p.ready(), false );
360}
@ fragmented_control
Fragmented control message.
Definition base.hpp:96
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [20/36]

BOOST_AUTO_TEST_CASE ( frame_empty_binary_unmasked )

Definition at line 222 of file hybi13.cpp.

222 {
223 uint8_t frame[2] = {0x82, 0x00};
224
225 // all in one chunk
226 processor_setup env1(false);
227
228 size_t ret1 = env1.p.consume(frame,2,env1.ec);
229
230 BOOST_CHECK_EQUAL( ret1, 2 );
231 BOOST_CHECK( !env1.ec );
232 BOOST_CHECK_EQUAL( env1.p.ready(), true );
233
234 // two separate chunks
235 processor_setup env2(false);
236
237 BOOST_CHECK_EQUAL( env2.p.consume(frame,1,env2.ec), 1 );
238 BOOST_CHECK( !env2.ec );
239 BOOST_CHECK_EQUAL( env2.p.ready(), false );
240
241 BOOST_CHECK_EQUAL( env2.p.consume(frame+1,1,env2.ec), 1 );
242 BOOST_CHECK( !env2.ec );
243 BOOST_CHECK_EQUAL( env2.p.ready(), true );
244}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [21/36]

BOOST_AUTO_TEST_CASE ( frame_extended_binary_unmasked )

Definition at line 263 of file hybi13.cpp.

263 {
264 processor_setup env(false);
265
266 uint8_t frame[130] = {0x82, 0x7E, 0x00, 0x7E};
267 frame[0] = 0x82;
268 frame[1] = 0x7E;
269 frame[2] = 0x00;
270 frame[3] = 0x7E;
271 std::fill_n(frame+4,126,0x2A);
272
273 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
274 BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
275 BOOST_CHECK( !env.ec );
276 BOOST_CHECK_EQUAL( env.p.ready(), true );
277
278 message_ptr foo = env.p.get_message();
279
280 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
281 BOOST_CHECK_EQUAL( foo->get_payload().size(), 126 );
282}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [22/36]

BOOST_AUTO_TEST_CASE ( frame_jumbo_binary_unmasked )

Definition at line 284 of file hybi13.cpp.

284 {
285 processor_setup env(false);
286
287 uint8_t frame[130] = {0x82, 0x7E, 0x00, 0x7E};
288 std::fill_n(frame+4,126,0x2A);
289
290 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
291 BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
292 BOOST_CHECK( !env.ec );
293 BOOST_CHECK_EQUAL( env.p.ready(), true );
294
295 message_ptr foo = env.p.get_message();
296
297 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
298 BOOST_CHECK_EQUAL( foo->get_payload().size(), 126 );
299}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [23/36]

BOOST_AUTO_TEST_CASE ( frame_small_binary_masked )

Definition at line 432 of file hybi13.cpp.

432 {
433 processor_setup env(true);
434
435 uint8_t frame[8] = {0x82, 0x82, 0xFF, 0xFF, 0xFF, 0xFF, 0xD5, 0xD5};
436
437 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
438 BOOST_CHECK_EQUAL( env.p.consume(frame,8,env.ec), 8 );
439 BOOST_CHECK( !env.ec );
440 BOOST_CHECK_EQUAL( env.p.ready(), true );
441 BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
442}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [24/36]

BOOST_AUTO_TEST_CASE ( frame_small_binary_unmasked )

Definition at line 246 of file hybi13.cpp.

246 {
247 processor_setup env(false);
248
249 uint8_t frame[4] = {0x82, 0x02, 0x2A, 0x2A};
250
251 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
252 BOOST_CHECK_EQUAL( env.p.consume(frame,4,env.ec), 4 );
253 BOOST_CHECK( !env.ec );
254 BOOST_CHECK_EQUAL( env.p.ready(), true );
255
256 message_ptr foo = env.p.get_message();
257
258 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
259 BOOST_CHECK_EQUAL( foo->get_payload(), "**" );
260
261}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [25/36]

BOOST_AUTO_TEST_CASE ( masked_fragmented_binary_message )

Definition at line 444 of file hybi13.cpp.

444 {
445 processor_setup env(true);
446
447 uint8_t frame0[14] = {0x02, 0x81, 0xAB, 0x23, 0x98, 0x45, 0x81,
448 0x80, 0x81, 0xB8, 0x34, 0x12, 0xFF, 0x92};
449
450 // read fragmented message in one chunk
451 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
452 BOOST_CHECK_EQUAL( env.p.consume(frame0,14,env.ec), 14 );
453 BOOST_CHECK( !env.ec );
454 BOOST_CHECK_EQUAL( env.p.ready(), true );
455 BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
456}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [26/36]

BOOST_AUTO_TEST_CASE ( masked_server_frame )

Definition at line 421 of file hybi13.cpp.

421 {
422 processor_setup env(false);
423
424 uint8_t frame[8] = {0x82, 0x82, 0xFF, 0xFF, 0xFF, 0xFF, 0xD5, 0xD5};
425
426 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
427 BOOST_CHECK_GT( env.p.consume(frame,8,env.ec), 0 );
428 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::masking_forbidden );
429 BOOST_CHECK_EQUAL( env.p.ready(), false );
430}
@ masking_forbidden
Servers may not send masked frames.
Definition base.hpp:105
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [27/36]

BOOST_AUTO_TEST_CASE ( missing_handshake_key1 )

Definition at line 171 of file hybi13.cpp.

171 {
172 processor_setup env(true);
173
174 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\n\r\n";
175
176 env.req.consume(handshake.c_str(),handshake.size());
177
179 BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
180 BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
181}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [28/36]

BOOST_AUTO_TEST_CASE ( missing_handshake_key2 )

Definition at line 183 of file hybi13.cpp.

183 {
184 processor_setup env(true);
185
186 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\n\r\n";
187
188 env.req.consume(handshake.c_str(),handshake.size());
189
191 BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
192 BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
193}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [29/36]

BOOST_AUTO_TEST_CASE ( multiple_frame_message_too_large )

Definition at line 506 of file hybi13.cpp.

506 {
507 processor_setup env(true);
508
509 env.p.set_max_message_size(4);
510
511 uint8_t frame0[8] = {0x02, 0x82, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01};
512 uint8_t frame1[9] = {0x80, 0x83, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01};
513
514 // read first message frame with size under the limit
515 BOOST_CHECK_EQUAL( env.p.consume(frame0,8,env.ec), 8 );
516 BOOST_CHECK( !env.ec );
517
518 // read second message frame that puts the size over the limit
519 BOOST_CHECK_EQUAL( env.p.consume(frame1,9,env.ec), 6 );
520 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::message_too_big );
521}
@ message_too_big
Processor encountered a message that was too large.
Definition base.hpp:78
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [30/36]

BOOST_AUTO_TEST_CASE ( non_get_method )

Definition at line 147 of file hybi13.cpp.

147 {
148 processor_setup env(true);
149
150 std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
151
152 env.req.consume(handshake.c_str(),handshake.size());
153
155 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
156 BOOST_CHECK( env.p.validate_handshake(env.req) == websocketpp::processor::error::invalid_http_method );
157}
@ invalid_http_method
Invalid HTTP method.
Definition base.hpp:120
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [31/36]

BOOST_AUTO_TEST_CASE ( old_http_version )

Definition at line 159 of file hybi13.cpp.

159 {
160 processor_setup env(true);
161
162 std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
163
164 env.req.consume(handshake.c_str(),handshake.size());
165
167 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
168 BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_version );
169}
@ invalid_http_version
Invalid HTTP version.
Definition base.hpp:123
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [32/36]

BOOST_AUTO_TEST_CASE ( prepare_data_frame )

Definition at line 458 of file hybi13.cpp.

458 {
459 processor_setup env(true);
460
461 message_ptr in = env.msg_manager->get_message();
462 message_ptr out = env.msg_manager->get_message();
463 message_ptr invalid;
464
465 // empty pointers arguements should return sane error
466 BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,invalid), websocketpp::processor::error::invalid_arguments );
467
468 BOOST_CHECK_EQUAL( env.p.prepare_data_frame(in,invalid), websocketpp::processor::error::invalid_arguments );
469
470 BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,out), websocketpp::processor::error::invalid_arguments );
471
472 // test valid opcodes
473 // control opcodes should return an error, data ones shouldn't
474 for (int i = 0; i < 0xF; i++) {
475 in->set_opcode(websocketpp::frame::opcode::value(i));
476
477 env.ec = env.p.prepare_data_frame(in,out);
478
479 if (websocketpp::frame::opcode::is_control(in->get_opcode())) {
480 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
481 } else {
482 BOOST_CHECK_NE( env.ec, websocketpp::processor::error::invalid_opcode );
483 }
484 }
485
486
487 //in.set_payload("foo");
488
489 //e = prepare_data_frame(in,out);
490
491
492}
bool is_control(value v)
Check if an opcode is for a control frame.
Definition frame.hpp:139
@ invalid_opcode
Opcode was invalid for requested operation.
Definition base.hpp:87
@ invalid_arguments
The processor method was called with invalid arguments.
Definition base.hpp:84
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [33/36]

BOOST_AUTO_TEST_CASE ( reserved_opcode_used )

Definition at line 329 of file hybi13.cpp.

329 {
330 uint8_t frame[10][2] = {{0x83, 0x00},
331 {0x84, 0x00},
332 {0x85, 0x00},
333 {0x86, 0x00},
334 {0x87, 0x00},
335 {0x8B, 0x00},
336 {0x8C, 0x00},
337 {0x8D, 0x00},
338 {0x8E, 0x00},
339 {0x8F, 0x00}};
340
341 for (int i = 0; i < 10; i++) {
342 processor_setup env(false);
343
344 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
345 BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
346 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
347 BOOST_CHECK_EQUAL( env.p.ready(), false );
348 }
349}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [34/36]

BOOST_AUTO_TEST_CASE ( rsv_bits_used )

Definition at line 313 of file hybi13.cpp.

313 {
314 uint8_t frame[3][2] = {{0x90, 0x00},
315 {0xA0, 0x00},
316 {0xC0, 0x00}};
317
318 for (int i = 0; i < 3; i++) {
319 processor_setup env(false);
320
321 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
322 BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
323 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_rsv_bit );
324 BOOST_CHECK_EQUAL( env.p.ready(), false );
325 }
326}
@ invalid_rsv_bit
Illegal use of reserved bit.
Definition base.hpp:93
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [35/36]

BOOST_AUTO_TEST_CASE ( single_frame_message_too_large )

Definition at line 494 of file hybi13.cpp.

494 {
495 processor_setup env(true);
496
497 env.p.set_max_message_size(3);
498
499 uint8_t frame0[10] = {0x82, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01};
500
501 // read message that is one byte too large
502 BOOST_CHECK_EQUAL( env.p.consume(frame0,10,env.ec), 6 );
503 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::message_too_big );
504}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [36/36]

BOOST_AUTO_TEST_CASE ( unmasked_client_frame )

Definition at line 410 of file hybi13.cpp.

410 {
411 processor_setup env(true);
412
413 uint8_t frame[2] = {0x82, 0x00};
414
415 BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
416 BOOST_CHECK_GT( env.p.consume(frame,2,env.ec), 0 );
417 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::masking_required );
418 BOOST_CHECK_EQUAL( env.p.ready(), false );
419}
@ masking_required
Clients may not send unmasked frames.
Definition base.hpp:102
Here is the call graph for this function: