remove trailing whitespace

This commit is contained in:
Peter Thorson
2013-07-21 07:49:15 -05:00
parent df828914c7
commit c017331959
143 changed files with 3602 additions and 3602 deletions

View File

@@ -28,7 +28,7 @@ prgs += env.Program('test_extension_permessage_compress_boost', ["test_extension
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
BOOST_LIBS_CPP11 = boostlibs(['unit_test_framework'],env_cpp11) + [platform_libs] + [polyfill_libs] + ['z']
# no C++11 features are used in processor so there are no C++11 versions of
# no C++11 features are used in processor so there are no C++11 versions of
# these tests.
objs += env_cpp11.Object('test_processor_stl.o', ["processor.cpp"], LIBS = BOOST_LIBS_CPP11)
objs += env_cpp11.Object('test_hybi13_stl.o', ["hybi13.cpp"], LIBS = BOOST_LIBS_CPP11)
@@ -36,7 +36,7 @@ if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
objs += env_cpp11.Object('test_hybi07_stl.o', ["hybi07.cpp"], LIBS = BOOST_LIBS_CPP11)
objs += env_cpp11.Object('test_hybi00_stl.o', ["hybi00.cpp"], LIBS = BOOST_LIBS_CPP11)
objs += env_cpp11.Object('test_extension_permessage_compress_stl.o', ["extension_permessage_compress.cpp"], LIBS = BOOST_LIBS_CPP11 + ['z'])
prgs += env_cpp11.Program('test_processor_stl', ["test_processor_stl.o"], LIBS = BOOST_LIBS_CPP11)
prgs += env_cpp11.Program('test_hybi13_stl', ["test_hybi13_stl.o"], LIBS = BOOST_LIBS_CPP11)
prgs += env_cpp11.Program('test_hybi08_stl', ["test_hybi08_stl.o"], LIBS = BOOST_LIBS_CPP11)

View File

@@ -11,10 +11,10 @@
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -22,7 +22,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
//#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE extension_permessage_deflate
@@ -38,7 +38,7 @@
struct config {
typedef websocketpp::http::parser::request request_type;
};
typedef websocketpp::extensions::permessage_deflate::enabled<config>
typedef websocketpp::extensions::permessage_deflate::enabled<config>
compressor_type;
using namespace websocketpp;
@@ -50,23 +50,23 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
neg_ret = compressor.negotiate(attributes);
BOOST_CHECK_EQUAL( neg_ret.first,
BOOST_CHECK_EQUAL( neg_ret.first,
extensions::permessage_deflate::error::invalid_parameters );*/
/**
* Window size is primarily controlled by the writer. A stream can only be
* read by a window size equal to or greater than the one use to compress
* it initially. The default windows size is also the maximum window size.
* it initially. The default windows size is also the maximum window size.
* Thus:
*
* Outbound window size can be limited unilaterally under the assumption
* that the opposite end will be using the default (maximum size which can
* read anything)
*
* Inbound window size must be limited by asking the remote endpoint to
* Inbound window size must be limited by asking the remote endpoint to
* do so and it agreeing.
*
* Context takeover is also primarily controlled by the writer. If the
*
* Context takeover is also primarily controlled by the writer. If the
* compressor does not clear its context between messages then the reader
* can't either.
*
@@ -81,17 +81,17 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
* - whether or not to request that the server disallow context takeover
*
* Server must answer in the following ways
* - If client requested a window size limit, is the window size limit
* - If client requested a window size limit, is the window size limit
* acceptable?
* - If client allows window limit requests, should we send one?
* - If client requested no context takeover, should we accept?
*
*
*
*
*
*
* All Defaults
* Req: permessage-compress; method=deflate
* Ans: permessage-compress; method=deflate
*
*
* # Client wants to limit the size of inbound windows from server
* permessage-compress; method="deflate; s2c_max_window_bits=8, deflate"
* Ans: permessage-compress; method="deflate; s2c_max_window_bits=8"
@@ -99,13 +99,13 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
* Ans: permessage-compress; method=deflate
*
* # Server wants to limit the size of inbound windows from client
* Client:
* Client:
* permessage-compress; method="deflate; c2s_max_window_bits, deflate"
*
*
* Server:
* permessage-compress; method="deflate; c2s_max_window_bits=8"
*
* # Client wants to
*
* # Client wants to
*
*
*
@@ -113,7 +113,7 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
*
*
*/
@@ -144,30 +144,30 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
attributes.push_back(http::parser::attribute("s2c_max_window_bits","9"));
ec = d.init(attributes);
BOOST_CHECK( !ec);
attributes.clear();
ec = d.init(attributes);
BOOST_CHECK( !ec);
processor::extensions::deflate_engine de;
unsigned char test_in[] = "HelloHelloHelloHello";
unsigned char test_out[30];
uLongf test_out_size = 30;
int ret;
ret = compress(test_out, &test_out_size, test_in, 20);
ret = compress(test_out, &test_out_size, test_in, 20);
std::cout << ret << std::endl
<< websocketpp::utility::to_hex(test_in,20) << std::endl
<< websocketpp::utility::to_hex(test_out,test_out_size) << std::endl;
std::string input = "Hello";
std::string output = "";
ec = de.compress(input,output);
BOOST_CHECK( ec == processor::extensions::error::uninitialized );
//std::cout << ec.message() << websocketpp::utility::to_hex(output) << std::endl;
@@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
std::cout << ec.message() << std::endl
<< websocketpp::utility::to_hex(input) << std::endl
<< websocketpp::utility::to_hex(output) << std::endl;
output = "";
ec = de.compress(input,output);

View File

@@ -11,10 +11,10 @@
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -22,7 +22,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
//#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE hybi_00_processor
@@ -43,15 +43,15 @@ struct stub_config {
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
};
struct processor_setup {
processor_setup(bool server)
processor_setup(bool server)
: msg_manager(new stub_config::con_msg_manager_type())
, p(false,server,msg_manager) {}
websocketpp::lib::error_code ec;
stub_config::con_msg_manager_type::ptr msg_manager;
stub_config::request_type req;
@@ -63,44 +63,44 @@ typedef stub_config::message_type::ptr message_ptr;
BOOST_AUTO_TEST_CASE( exact_match ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
env.req.replace_header("Sec-WebSocket-Key3","WjN}|M(6");
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
env.ec = env.p.validate_handshake(env.req);
BOOST_CHECK(!env.ec);
websocketpp::uri_ptr u;
BOOST_CHECK_NO_THROW( u = env.p.get_uri(env.req) );
BOOST_CHECK_EQUAL(u->get_secure(), false);
BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
BOOST_CHECK_EQUAL(u->get_resource(), "/");
BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
env.p.process_handshake(env.req,"",env.res);
BOOST_CHECK_EQUAL(env.res.get_header("Connection"), "Upgrade");
BOOST_CHECK_EQUAL(env.res.get_header("Upgrade"), "WebSocket");
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Origin"), "http://example.com");
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Location"), "ws://www.example.com/");
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Key3"), "n`9eBk9z$R8pOtVb");
}
BOOST_AUTO_TEST_CASE( non_get_method ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_method );
@@ -108,12 +108,12 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
BOOST_AUTO_TEST_CASE( old_http_version ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_version );
@@ -121,12 +121,12 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
@@ -134,12 +134,12 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
@@ -148,12 +148,12 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
BOOST_AUTO_TEST_CASE( bad_host ) {
processor_setup env(true);
websocketpp::uri_ptr u;
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";
env.req.consume(handshake.c_str(),handshake.size());
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK( !env.p.validate_handshake(env.req) );
@@ -163,42 +163,42 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
BOOST_AUTO_TEST_CASE( extract_subprotocols ) {
processor_setup env(true);
std::vector<std::string> subps;
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
BOOST_CHECK_EQUAL( subps.size(), 0 );
}
BOOST_AUTO_TEST_CASE( prepare_data_frame_null ) {
processor_setup env(true);
message_ptr in = env.msg_manager->get_message();
message_ptr out = env.msg_manager->get_message();
message_ptr invalid;
// empty pointers arguements should return sane error
// empty pointers arguements should return sane error
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,invalid), websocketpp::processor::error::invalid_arguments );
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(in,invalid), websocketpp::processor::error::invalid_arguments );
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,out), websocketpp::processor::error::invalid_arguments );
// test valid opcodes
// text (1) should be the only valid opcode
for (int i = 0; i < 0xF; i++) {
in->set_opcode(websocketpp::frame::opcode::value(i));
env.ec = env.p.prepare_data_frame(in,out);
if (i != 1) {
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
} else {
BOOST_CHECK_NE( env.ec, websocketpp::processor::error::invalid_opcode );
}
}
/*
* TODO: tests for invalid UTF8
char buf[2] = {0x00, 0x00};
@@ -213,15 +213,15 @@ BOOST_AUTO_TEST_CASE( prepare_data_frame_null ) {
BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
processor_setup env(true);
message_ptr in = env.msg_manager->get_message();
message_ptr out = env.msg_manager->get_message();
in->set_opcode(websocketpp::frame::opcode::text);
in->set_payload("foo");
env.ec = env.p.prepare_data_frame(in,out);
unsigned char raw_header[1] = {0x00};
unsigned char raw_payload[4] = {0x66,0x6f,0x6f,0xff};

View File

@@ -11,10 +11,10 @@
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -22,7 +22,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
//#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE hybi_07_processor
@@ -45,16 +45,16 @@ struct stub_config {
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
/// Extension related config
static const bool enable_extensions = false;
/// Extension specific config
/// permessage_compress_config
struct permessage_deflate_config {
typedef stub_config::request_type request_type;
@@ -71,28 +71,28 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
BOOST_CHECK(!ec);
websocketpp::uri_ptr u;
u = p.get_uri(r);
BOOST_CHECK(u->get_valid());
BOOST_CHECK(!u->get_secure());
BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
BOOST_CHECK_EQUAL(u->get_resource(), "/");
BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
p.process_handshake(r,"",response);
BOOST_CHECK_EQUAL(response.get_header("Connection"), "upgrade");
BOOST_CHECK_EQUAL(response.get_header("Upgrade"), "websocket");
BOOST_CHECK_EQUAL(response.get_header("Sec-WebSocket-Accept"), "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
@@ -107,9 +107,9 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
websocketpp::lib::error_code ec;
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: foo\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -123,11 +123,11 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: foo\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -141,11 +141,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -159,11 +159,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -177,15 +177,15 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
stub_config::rng_type rng;
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: foo\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
BOOST_CHECK( !ec );
BOOST_CHECK( !p.get_uri(r)->get_valid() );
}

View File

@@ -11,10 +11,10 @@
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -22,7 +22,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
//#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE hybi_08_processor
@@ -45,16 +45,16 @@ struct stub_config {
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
/// Extension related config
static const bool enable_extensions = false;
/// Extension specific config
/// permessage_deflate_config
struct permessage_deflate_config {
typedef stub_config::request_type request_type;
@@ -71,28 +71,28 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
BOOST_CHECK(!ec);
websocketpp::uri_ptr u;
u = p.get_uri(r);
BOOST_CHECK(u->get_valid() == true);
BOOST_CHECK(u->get_secure() == false);
BOOST_CHECK(u->get_host() == "www.example.com");
BOOST_CHECK(u->get_resource() == "/");
BOOST_CHECK(u->get_port() == websocketpp::uri_default_port);
p.process_handshake(r,"",response);
BOOST_CHECK(response.get_header("Connection") == "upgrade");
BOOST_CHECK(response.get_header("Upgrade") == "websocket");
BOOST_CHECK(response.get_header("Sec-WebSocket-Accept") == "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
@@ -107,9 +107,9 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
websocketpp::lib::error_code ec;
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: foo\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -123,11 +123,11 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: foo\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -141,11 +141,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -159,11 +159,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
stub_config::rng_type rng;
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
@@ -178,18 +178,18 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
websocketpp::uri_ptr u;
websocketpp::lib::error_code ec;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: foo\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
ec = p.validate_handshake(r);
BOOST_CHECK( !ec );
u = p.get_uri(r);
BOOST_CHECK( !u->get_valid() );
}

View File

@@ -11,10 +11,10 @@
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -22,7 +22,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
//#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE hybi_13_processor
@@ -37,7 +37,7 @@
#include <websocketpp/http/response.hpp>
#include <websocketpp/message_buffer/message.hpp>
#include <websocketpp/message_buffer/alloc.hpp>
#include <websocketpp/random/none.hpp>
#include <websocketpp/random/none.hpp>
#include <websocketpp/extensions/permessage_deflate/disabled.hpp>
#include <websocketpp/extensions/permessage_deflate/enabled.hpp>
@@ -48,11 +48,11 @@ struct stub_config {
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
struct permessage_deflate_config {
typedef stub_config::request_type request_type;
};
@@ -69,15 +69,15 @@ struct stub_config_ext {
typedef websocketpp::message_buffer::message
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
struct permessage_deflate_config {
typedef stub_config_ext::request_type request_type;
};
typedef websocketpp::extensions::permessage_deflate::enabled
<permessage_deflate_config> permessage_deflate_type;
@@ -90,10 +90,10 @@ typedef stub_config::message_type::ptr message_ptr;
// Set up a structure that constructs new copies of all of the support structure
// for using connection processors
struct processor_setup {
processor_setup(bool server)
processor_setup(bool server)
: msg_manager(new con_msg_manager_type())
, p(false,server,msg_manager,rng) {}
websocketpp::lib::error_code ec;
con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
@@ -103,10 +103,10 @@ struct processor_setup {
};
struct processor_setup_ext {
processor_setup_ext(bool server)
processor_setup_ext(bool server)
: msg_manager(new con_msg_manager_type())
, p(false,server,msg_manager,rng) {}
websocketpp::lib::error_code ec;
con_msg_manager_type::ptr msg_manager;
stub_config::rng_type rng;
@@ -117,26 +117,26 @@ struct processor_setup_ext {
BOOST_AUTO_TEST_CASE( exact_match ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK(!env.p.validate_handshake(env.req));
websocketpp::uri_ptr u;
BOOST_CHECK_NO_THROW( u = env.p.get_uri(env.req) );
BOOST_CHECK_EQUAL(u->get_secure(), false);
BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
BOOST_CHECK_EQUAL(u->get_resource(), "/");
BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
env.p.process_handshake(env.req,"",env.res);
BOOST_CHECK_EQUAL(env.res.get_header("Connection"), "upgrade");
BOOST_CHECK_EQUAL(env.res.get_header("Upgrade"), "websocket");
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Accept"), "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
@@ -146,9 +146,9 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK( env.p.validate_handshake(env.req) == websocketpp::processor::error::invalid_http_method );
@@ -156,11 +156,11 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
BOOST_AUTO_TEST_CASE( old_http_version ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_version );
@@ -168,11 +168,11 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
BOOST_CHECK( websocketpp::processor::is_websocket_handshake(env.req) );
BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
@@ -180,11 +180,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
BOOST_CHECK( websocketpp::processor::is_websocket_handshake(env.req) );
BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
@@ -192,14 +192,14 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
BOOST_AUTO_TEST_CASE( bad_host ) {
processor_setup env(true);
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";
env.req.consume(handshake.c_str(),handshake.size());
BOOST_CHECK( websocketpp::processor::is_websocket_handshake(env.req) );
BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
BOOST_CHECK( !env.p.validate_handshake(env.req) );
BOOST_CHECK( !env.p.validate_handshake(env.req) );
BOOST_CHECK( !env.p.get_uri(env.req)->get_valid() );
}
@@ -224,11 +224,11 @@ BOOST_AUTO_TEST_CASE( frame_empty_binary_unmasked ) {
processor_setup env1(false);
size_t ret1 = env1.p.consume(frame,2,env1.ec);
BOOST_CHECK_EQUAL( ret1, 2 );
BOOST_CHECK( !env1.ec );
BOOST_CHECK_EQUAL( env1.p.ready(), true );
BOOST_CHECK_EQUAL( env1.p.ready(), true );
// two separate chunks
processor_setup env2(false);
@@ -245,12 +245,12 @@ BOOST_AUTO_TEST_CASE( frame_small_binary_unmasked ) {
processor_setup env(false);
uint8_t frame[4] = {0x82, 0x02, 0x2A, 0x2A};
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame,4,env.ec), 4 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
message_ptr foo = env.p.get_message();
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
@@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE( frame_extended_binary_unmasked ) {
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
message_ptr foo = env.p.get_message();
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
@@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE( frame_jumbo_binary_unmasked ) {
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
message_ptr foo = env.p.get_message();
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
@@ -315,7 +315,7 @@ BOOST_AUTO_TEST_CASE( rsv_bits_used ) {
for (int i = 0; i < 3; i++) {
processor_setup env(false);
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_rsv_bit );
@@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE( reserved_opcode_used ) {
for (int i = 0; i < 10; i++) {
processor_setup env(false);
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
@@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE( fragmented_binary_message ) {
BOOST_CHECK( !env0.ec );
BOOST_CHECK_EQUAL( env0.p.ready(), true );
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
// read fragmented message in two chunks
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env0.p.consume(frame0,3,env0.ec), 3 );
@@ -442,25 +442,25 @@ BOOST_AUTO_TEST_CASE( frame_small_binary_masked ) {
BOOST_AUTO_TEST_CASE( masked_fragmented_binary_message ) {
processor_setup env(true);
uint8_t frame0[14] = {0x02, 0x81, 0xAB, 0x23, 0x98, 0x45, 0x81,
uint8_t frame0[14] = {0x02, 0x81, 0xAB, 0x23, 0x98, 0x45, 0x81,
0x80, 0x81, 0xB8, 0x34, 0x12, 0xFF, 0x92};
// read fragmented message in one chunk
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
BOOST_CHECK_EQUAL( env.p.consume(frame0,14,env.ec), 14 );
BOOST_CHECK( !env.ec );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.ready(), true );
BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
}
BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
processor_setup env(true);
message_ptr in = env.msg_manager->get_message();
message_ptr out = env.msg_manager->get_message();
message_ptr invalid;
// empty pointers arguements should return sane error
// empty pointers arguements should return sane error
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,invalid), websocketpp::processor::error::invalid_arguments );
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(in,invalid), websocketpp::processor::error::invalid_arguments );
@@ -471,19 +471,19 @@ BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
// control opcodes should return an error, data ones shouldn't
for (int i = 0; i < 0xF; i++) {
in->set_opcode(websocketpp::frame::opcode::value(i));
env.ec = env.p.prepare_data_frame(in,out);
if (websocketpp::frame::opcode::is_control(in->get_opcode())) {
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
} else {
BOOST_CHECK_NE( env.ec, websocketpp::processor::error::invalid_opcode );
}
}
//in.set_payload("foo");
//e = prepare_data_frame(in,out);
@@ -492,22 +492,22 @@ BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
BOOST_AUTO_TEST_CASE( client_handshake_request ) {
processor_setup env(false);
websocketpp::uri_ptr u(new websocketpp::uri("ws://localhost/"));
env.p.client_handshake_request(env.req,u, std::vector<std::string>());
BOOST_CHECK_EQUAL( env.req.get_method(), "GET" );
BOOST_CHECK_EQUAL( env.req.get_version(), "HTTP/1.1");
BOOST_CHECK_EQUAL( env.req.get_uri(), "/");
BOOST_CHECK_EQUAL( env.req.get_header("Host"), "localhost");
BOOST_CHECK_EQUAL( env.req.get_header("Sec-WebSocket-Version"), "13");
BOOST_CHECK_EQUAL( env.req.get_header("Connection"), "Upgrade");
BOOST_CHECK_EQUAL( env.req.get_header("Upgrade"), "websocket");
}
// TODO:
// TODO:
// test cases
// - adding headers
// - adding Upgrade header
@@ -524,48 +524,48 @@ BOOST_AUTO_TEST_CASE( client_handshake_request ) {
BOOST_AUTO_TEST_CASE( client_handshake_response_404 ) {
processor_setup env(false);
std::string res = "HTTP/1.1 404 Not Found\r\n\r\n";
env.res.consume(res.data(),res.size());
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::invalid_http_status );
}
BOOST_AUTO_TEST_CASE( client_handshake_response_no_upgrade ) {
processor_setup env(false);
std::string res = "HTTP/1.1 101 Switching Protocols\r\n\r\n";
env.res.consume(res.data(),res.size());
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
}
BOOST_AUTO_TEST_CASE( client_handshake_response_no_connection ) {
processor_setup env(false);
std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\n\r\n";
env.res.consume(res.data(),res.size());
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
}
BOOST_AUTO_TEST_CASE( client_handshake_response_no_accept ) {
processor_setup env(false);
std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\nConnection: bar, UpGrAdE\r\n\r\n";
env.res.consume(res.data(),res.size());
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
}
BOOST_AUTO_TEST_CASE( client_handshake_response ) {
processor_setup env(false);
env.req.append_header("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
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";
env.res.consume(res.data(),res.size());
BOOST_CHECK( !env.p.validate_server_handshake_response(env.req,env.res) );
}
@@ -576,7 +576,7 @@ BOOST_AUTO_TEST_CASE( extensions_disabled ) {
std::pair<websocketpp::lib::error_code,std::string> neg_results;
neg_results = env.p.negotiate_extensions(env.req);
BOOST_CHECK_EQUAL( neg_results.first, websocketpp::processor::error::extensions_disabled );
BOOST_CHECK_EQUAL( neg_results.second, "" );
}
@@ -588,7 +588,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_blank ) {
std::pair<websocketpp::lib::error_code,std::string> neg_results;
neg_results = env.p.negotiate_extensions(env.req);
BOOST_CHECK( !neg_results.first );
BOOST_CHECK_EQUAL( neg_results.second, "" );
}
@@ -600,7 +600,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_unknown ) {
std::pair<websocketpp::lib::error_code,std::string> neg_results;
neg_results = env.p.negotiate_extensions(env.req);
BOOST_CHECK( !neg_results.first );
BOOST_CHECK_EQUAL( neg_results.second, "" );
}
@@ -608,7 +608,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_unknown ) {
BOOST_AUTO_TEST_CASE( extract_subprotocols_empty ) {
processor_setup env(true);
std::vector<std::string> subps;
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
BOOST_CHECK_EQUAL( subps.size(), 0 );
}
@@ -616,9 +616,9 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_empty ) {
BOOST_AUTO_TEST_CASE( extract_subprotocols_one ) {
processor_setup env(true);
std::vector<std::string> subps;
env.req.replace_header("Sec-WebSocket-Protocol","foo");
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
BOOST_REQUIRE_EQUAL( subps.size(), 1 );
BOOST_CHECK_EQUAL( subps[0], "foo" );
@@ -627,9 +627,9 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_one ) {
BOOST_AUTO_TEST_CASE( extract_subprotocols_multiple ) {
processor_setup env(true);
std::vector<std::string> subps;
env.req.replace_header("Sec-WebSocket-Protocol","foo,bar");
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
BOOST_REQUIRE_EQUAL( subps.size(), 2 );
BOOST_CHECK_EQUAL( subps[0], "foo" );
@@ -639,9 +639,9 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_multiple ) {
BOOST_AUTO_TEST_CASE( extract_subprotocols_invalid) {
processor_setup env(true);
std::vector<std::string> subps;
env.req.replace_header("Sec-WebSocket-Protocol","foo,bar,,,,");
BOOST_CHECK_EQUAL( env.p.extract_subprotocols(env.req,subps), websocketpp::processor::error::make_error_code(websocketpp::processor::error::subprotocol_parse_error) );
BOOST_CHECK_EQUAL( subps.size(), 0 );
}
@@ -654,7 +654,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_permessage_deflate ) {
std::pair<websocketpp::lib::error_code,std::string> neg_results;
neg_results = env.p.negotiate_extensions(env.req);
BOOST_CHECK( !neg_results.first );
BOOST_CHECK_EQUAL( neg_results.second, "permessage-deflate" );
}

View File

@@ -11,10 +11,10 @@
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -22,7 +22,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
//#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE processors
@@ -36,100 +36,100 @@
BOOST_AUTO_TEST_CASE( exact_match ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
}
BOOST_AUTO_TEST_CASE( non_match ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(!websocketpp::processor::is_websocket_handshake(r));
}
BOOST_AUTO_TEST_CASE( ci_exact_match ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: UpGrAde\r\nUpgrade: WebSocket\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
}
BOOST_AUTO_TEST_CASE( non_exact_match1 ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade,foo\r\nUpgrade: websocket,foo\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
}
BOOST_AUTO_TEST_CASE( non_exact_match2 ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: keep-alive,Upgrade,foo\r\nUpgrade: foo,websocket,bar\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
}
BOOST_AUTO_TEST_CASE( version_blank ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 0);
}
BOOST_AUTO_TEST_CASE( version_7 ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 7);
}
BOOST_AUTO_TEST_CASE( version_8 ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 8);
}
BOOST_AUTO_TEST_CASE( version_13 ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 13);
}
BOOST_AUTO_TEST_CASE( version_non_numeric ) {
websocketpp::http::parser::request r;
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: abc\r\n\r\n";
r.consume(handshake.c_str(),handshake.size());
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == -1);
}
}