Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
hybi00.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
#include <websocketpp/processors/hybi00.hpp>
#include <websocketpp/http/request.hpp>
#include <websocketpp/http/response.hpp>
#include <websocketpp/message_buffer/message.hpp>
#include <websocketpp/message_buffer/alloc.hpp>
Include dependency graph for hybi00.cpp:

Go to the source code of this file.

Classes

struct  stub_config
 
struct  processor_setup
 

Macros

#define BOOST_TEST_MODULE   hybi_00_processor
 

Typedefs

typedef stub_config::message_type::ptr message_ptr
 

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 (extract_subprotocols)
 
 BOOST_AUTO_TEST_CASE (prepare_data_frame_null)
 
 BOOST_AUTO_TEST_CASE (prepare_data_frame)
 
 BOOST_AUTO_TEST_CASE (empty_consume)
 
 BOOST_AUTO_TEST_CASE (empty_frame)
 
 BOOST_AUTO_TEST_CASE (short_frame)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   hybi_00_processor

Definition at line 28 of file hybi00.cpp.

Typedef Documentation

◆ message_ptr

typedef stub_config::message_type::ptr message_ptr

Definition at line 64 of file hybi00.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/12]

BOOST_AUTO_TEST_CASE ( bad_host )

Definition at line 150 of file hybi00.cpp.

150 {
151 processor_setup env(true);
153
154 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
155
156 env.req.consume(handshake.c_str(),handshake.size());
157 env.req.replace_header("Sec-WebSocket-Key3","janelle!");
158
160 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
161 BOOST_CHECK( !env.p.validate_handshake(env.req) );
162
163 BOOST_CHECK( !env.p.get_uri(env.req)->get_valid() );
164}
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
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() [2/12]

BOOST_AUTO_TEST_CASE ( empty_consume )

Definition at line 236 of file hybi00.cpp.

236 {
237 uint8_t frame[2] = {0x00,0x00};
238
239 processor_setup env(true);
240
241 size_t ret = env.p.consume(frame,0,env.ec);
242
243 BOOST_CHECK_EQUAL( ret, 0);
244 BOOST_CHECK( !env.ec );
245 BOOST_CHECK_EQUAL( env.p.ready(), false );
246}
unsigned char uint8_t
Definition stdint.h:124
CK_RV ret
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/12]

BOOST_AUTO_TEST_CASE ( empty_frame )

Definition at line 248 of file hybi00.cpp.

248 {
249 uint8_t frame[2] = {0x00, 0xff};
250
251 processor_setup env(true);
252
253 size_t ret = env.p.consume(frame,2,env.ec);
254
255 BOOST_CHECK_EQUAL( ret, 2);
256 BOOST_CHECK( !env.ec );
257 BOOST_CHECK_EQUAL( env.p.ready(), true );
258 BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "" );
259 BOOST_CHECK_EQUAL( env.p.ready(), false );
260}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/12]

BOOST_AUTO_TEST_CASE ( exact_match )

Definition at line 66 of file hybi00.cpp.

66 {
67 processor_setup env(true);
68
69 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
70
71 env.req.consume(handshake.c_str(),handshake.size());
72 env.req.replace_header("Sec-WebSocket-Key3","WjN}|M(6");
73
75 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
76 env.ec = env.p.validate_handshake(env.req);
77 BOOST_CHECK(!env.ec);
78
80
81 BOOST_CHECK_NO_THROW( u = env.p.get_uri(env.req) );
82
83 BOOST_CHECK_EQUAL(u->get_secure(), false);
84 BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
85 BOOST_CHECK_EQUAL(u->get_resource(), "/");
86 BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
87
88 env.p.process_handshake(env.req,"",env.res);
89
90 BOOST_CHECK_EQUAL(env.res.get_header("Connection"), "Upgrade");
91 BOOST_CHECK_EQUAL(env.res.get_header("Upgrade"), "WebSocket");
92 BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Origin"), "http://example.com");
93
94 BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Location"), "ws://www.example.com/");
95 BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Key3"), "n`9eBk9z$R8pOtVb");
96}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/12]

BOOST_AUTO_TEST_CASE ( extract_subprotocols )

Definition at line 166 of file hybi00.cpp.

166 {
167 processor_setup env(true);
168
169 std::vector<std::string> subps;
170
171 BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
172 BOOST_CHECK_EQUAL( subps.size(), 0 );
173}
void subps(const Xmm &xmm, const Operand &op)
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/12]

BOOST_AUTO_TEST_CASE ( missing_handshake_key1 )

Definition at line 124 of file hybi00.cpp.

124 {
125 processor_setup env(true);
126
127 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\n\r\n";
128
129 env.req.consume(handshake.c_str(),handshake.size());
130 env.req.replace_header("Sec-WebSocket-Key3","janelle!");
131
133 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
134 BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
135}
@ missing_required_header
Missing Required Header.
Definition base.hpp:129
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/12]

BOOST_AUTO_TEST_CASE ( missing_handshake_key2 )

Definition at line 137 of file hybi00.cpp.

137 {
138 processor_setup env(true);
139
140 std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
141
142 env.req.consume(handshake.c_str(),handshake.size());
143 env.req.replace_header("Sec-WebSocket-Key3","janelle!");
144
146 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
147 BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
148}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/12]

BOOST_AUTO_TEST_CASE ( non_get_method )

Definition at line 98 of file hybi00.cpp.

98 {
99 processor_setup env(true);
100
101 std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
102
103 env.req.consume(handshake.c_str(),handshake.size());
104 env.req.replace_header("Sec-WebSocket-Key3","janelle!");
105
107 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
108 BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_method );
109}
@ invalid_http_method
Invalid HTTP method.
Definition base.hpp:120
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/12]

BOOST_AUTO_TEST_CASE ( old_http_version )

Definition at line 111 of file hybi00.cpp.

111 {
112 processor_setup env(true);
113
114 std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
115
116 env.req.consume(handshake.c_str(),handshake.size());
117 env.req.replace_header("Sec-WebSocket-Key3","janelle!");
118
120 BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
121 BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_version );
122}
@ invalid_http_version
Invalid HTTP version.
Definition base.hpp:123
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [10/12]

BOOST_AUTO_TEST_CASE ( prepare_data_frame )

Definition at line 216 of file hybi00.cpp.

216 {
217 processor_setup env(true);
218
219 message_ptr in = env.msg_manager->get_message();
220 message_ptr out = env.msg_manager->get_message();
221
222 in->set_opcode(websocketpp::frame::opcode::text);
223 in->set_payload("foo");
224
225 env.ec = env.p.prepare_data_frame(in,out);
226
227 unsigned char raw_header[1] = {0x00};
228 unsigned char raw_payload[4] = {0x66,0x6f,0x6f,0xff};
229
230 BOOST_CHECK( !env.ec );
231 BOOST_CHECK_EQUAL( out->get_header(), std::string(reinterpret_cast<char*>(raw_header),1) );
232 BOOST_CHECK_EQUAL( out->get_payload(), std::string(reinterpret_cast<char*>(raw_payload),4) );
233}
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [11/12]

BOOST_AUTO_TEST_CASE ( prepare_data_frame_null )

Definition at line 175 of file hybi00.cpp.

175 {
176 processor_setup env(true);
177
178 message_ptr in = env.msg_manager->get_message();
179 message_ptr out = env.msg_manager->get_message();
180 message_ptr invalid;
181
182
183 // empty pointers arguements should return sane error
184 BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,invalid), websocketpp::processor::error::invalid_arguments );
185
186 BOOST_CHECK_EQUAL( env.p.prepare_data_frame(in,invalid), websocketpp::processor::error::invalid_arguments );
187
188 BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,out), websocketpp::processor::error::invalid_arguments );
189
190 // test valid opcodes
191 // text (1) should be the only valid opcode
192 for (int i = 0; i < 0xF; i++) {
193 in->set_opcode(websocketpp::frame::opcode::value(i));
194
195 env.ec = env.p.prepare_data_frame(in,out);
196
197 if (i != 1) {
198 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
199 } else {
200 BOOST_CHECK_NE( env.ec, websocketpp::processor::error::invalid_opcode );
201 }
202 }
203
204 /*
205 * TODO: tests for invalid UTF8
206 char buf[2] = {0x00, 0x00};
207
208 in->set_opcode(websocketpp::frame::opcode::text);
209 in->set_payload("foo");
210
211 env.ec = env.p.prepare_data_frame(in,out);
212 BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_payload );
213 */
214}
@ 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() [12/12]

BOOST_AUTO_TEST_CASE ( short_frame )

Definition at line 262 of file hybi00.cpp.

262 {
263 uint8_t frame[5] = {0x00, 0x66, 0x6f, 0x6f, 0xff};
264
265 processor_setup env(true);
266
267 size_t ret = env.p.consume(frame,5,env.ec);
268
269 BOOST_CHECK_EQUAL( ret, 5);
270 BOOST_CHECK( !env.ec );
271 BOOST_CHECK_EQUAL( env.p.ready(), true );
272 BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "foo" );
273 BOOST_CHECK_EQUAL( env.p.ready(), false );
274}
Here is the call graph for this function: