first commit
This commit is contained in:
17
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/CMakeLists.txt
vendored
Normal file
17
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Test client role
|
||||
file (GLOB SOURCE client.cpp)
|
||||
|
||||
init_target (test_roles_client)
|
||||
build_test (${TARGET_NAME} ${SOURCE})
|
||||
link_boost ()
|
||||
final_target ()
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "test")
|
||||
|
||||
# Test server role
|
||||
file (GLOB SOURCE server.cpp)
|
||||
|
||||
init_target (test_roles_server)
|
||||
build_test (${TARGET_NAME} ${SOURCE})
|
||||
link_boost ()
|
||||
final_target ()
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "test")
|
||||
27
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/SConscript
vendored
Normal file
27
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/SConscript
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
## role unit tests
|
||||
##
|
||||
|
||||
Import('env')
|
||||
Import('env_cpp11')
|
||||
Import('boostlibs')
|
||||
Import('platform_libs')
|
||||
Import('polyfill_libs')
|
||||
|
||||
env = env.Clone ()
|
||||
env_cpp11 = env_cpp11.Clone ()
|
||||
|
||||
BOOST_LIBS = boostlibs(['unit_test_framework','system','random'],env) + [platform_libs]
|
||||
|
||||
objs = env.Object('client_boost.o', ["client.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('server_boost.o', ["server.cpp"], LIBS = BOOST_LIBS)
|
||||
prgs = env.Program('test_client_boost', ["client_boost.o"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_server_boost', ["server_boost.o"], LIBS = BOOST_LIBS)
|
||||
|
||||
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
|
||||
BOOST_LIBS_CPP11 = boostlibs(['unit_test_framework'],env_cpp11) + [platform_libs] + [polyfill_libs]
|
||||
objs += env_cpp11.Object('client_stl.o', ["client.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('server_stl.o', ["server.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_client_stl', ["client_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_server_stl', ["server_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
|
||||
Return('prgs')
|
||||
194
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/client.cpp
vendored
Normal file
194
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/client.cpp
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * 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
|
||||
* 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;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* 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 client
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <websocketpp/random/random_device.hpp>
|
||||
|
||||
#include <websocketpp/config/core.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <websocketpp/http/request.hpp>
|
||||
|
||||
struct stub_config : public websocketpp::config::core {
|
||||
typedef core::concurrency_type concurrency_type;
|
||||
|
||||
typedef core::request_type request_type;
|
||||
typedef core::response_type response_type;
|
||||
|
||||
typedef core::message_type message_type;
|
||||
typedef core::con_msg_manager_type con_msg_manager_type;
|
||||
typedef core::endpoint_msg_manager_type endpoint_msg_manager_type;
|
||||
|
||||
typedef core::alog_type alog_type;
|
||||
typedef core::elog_type elog_type;
|
||||
|
||||
//typedef core::rng_type rng_type;
|
||||
typedef websocketpp::random::random_device::int_generator<uint32_t,concurrency_type> rng_type;
|
||||
|
||||
typedef core::transport_type transport_type;
|
||||
|
||||
typedef core::endpoint_base endpoint_base;
|
||||
|
||||
static const websocketpp::log::level elog_level = websocketpp::log::elevel::none;
|
||||
static const websocketpp::log::level alog_level = websocketpp::log::alevel::none;
|
||||
};
|
||||
|
||||
typedef websocketpp::client<stub_config> client;
|
||||
typedef client::connection_ptr connection_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( invalid_uri ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
connection_ptr con = c.get_connection("foo", ec);
|
||||
|
||||
BOOST_CHECK_EQUAL( ec , websocketpp::error::make_error_code(websocketpp::error::invalid_uri) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( unsecure_endpoint ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
connection_ptr con = c.get_connection("wss://localhost/", ec);
|
||||
|
||||
BOOST_CHECK_EQUAL( ec , websocketpp::error::make_error_code(websocketpp::error::endpoint_not_secure) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( get_connection ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
|
||||
BOOST_CHECK( con );
|
||||
BOOST_CHECK_EQUAL( con->get_host() , "localhost" );
|
||||
BOOST_CHECK_EQUAL( con->get_port() , 80 );
|
||||
BOOST_CHECK_EQUAL( con->get_secure() , false );
|
||||
BOOST_CHECK_EQUAL( con->get_resource() , "/" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( connect_con ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
std::stringstream out;
|
||||
std::string o;
|
||||
|
||||
c.register_ostream(&out);
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
c.connect(con);
|
||||
|
||||
o = out.str();
|
||||
websocketpp::http::parser::request r;
|
||||
r.consume(o.data(),o.size());
|
||||
|
||||
BOOST_CHECK( r.ready() );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET");
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1");
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/");
|
||||
|
||||
BOOST_CHECK_EQUAL( r.get_header("Host"), "localhost");
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Version"), "13");
|
||||
BOOST_CHECK_EQUAL( r.get_header("Connection"), "Upgrade");
|
||||
BOOST_CHECK_EQUAL( r.get_header("Upgrade"), "websocket");
|
||||
|
||||
// Key is randomly generated & User-Agent will change so just check that
|
||||
// they are not empty.
|
||||
BOOST_CHECK_NE( r.get_header("Sec-WebSocket-Key"), "");
|
||||
BOOST_CHECK_NE( r.get_header("User-Agent"), "" );
|
||||
|
||||
// connection should have written out an opening handshake request and be in
|
||||
// the read response internal state
|
||||
|
||||
// TODO: more tests related to reading the HTTP response
|
||||
std::stringstream channel2;
|
||||
channel2 << "e\r\n\r\n";
|
||||
channel2 >> *con;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( select_subprotocol ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
using websocketpp::error::make_error_code;
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
|
||||
BOOST_CHECK( con );
|
||||
|
||||
con->select_subprotocol("foo",ec);
|
||||
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::server_only) );
|
||||
BOOST_CHECK_THROW( con->select_subprotocol("foo") , websocketpp::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( add_subprotocols_invalid ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
using websocketpp::error::make_error_code;
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
BOOST_CHECK( con );
|
||||
|
||||
con->add_subprotocol("",ec);
|
||||
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
|
||||
BOOST_CHECK_THROW( con->add_subprotocol("") , websocketpp::exception );
|
||||
|
||||
con->add_subprotocol("foo,bar",ec);
|
||||
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
|
||||
BOOST_CHECK_THROW( con->add_subprotocol("foo,bar") , websocketpp::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( add_subprotocols ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
std::stringstream out;
|
||||
std::string o;
|
||||
|
||||
c.register_ostream(&out);
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
BOOST_CHECK( con );
|
||||
|
||||
con->add_subprotocol("foo",ec);
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
BOOST_CHECK_NO_THROW( con->add_subprotocol("bar") );
|
||||
|
||||
c.connect(con);
|
||||
|
||||
o = out.str();
|
||||
websocketpp::http::parser::request r;
|
||||
r.consume(o.data(),o.size());
|
||||
|
||||
BOOST_CHECK( r.ready() );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Protocol"), "foo, bar");
|
||||
}
|
||||
|
||||
|
||||
247
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/server.cpp
vendored
Normal file
247
third_party/socket.io-client-cpp/lib/websocketpp/test/roles/server.cpp
vendored
Normal file
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * 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
|
||||
* 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;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* 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 server
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// Test Environment:
|
||||
// server, no TLS, no locks, iostream based transport
|
||||
#include <websocketpp/config/core.hpp>
|
||||
#include <websocketpp/server.hpp>
|
||||
|
||||
typedef websocketpp::server<websocketpp::config::core> server;
|
||||
typedef websocketpp::config::core::message_type::ptr message_ptr;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
|
||||
/*struct stub_config : public websocketpp::config::core {
|
||||
typedef core::concurrency_type concurrency_type;
|
||||
|
||||
typedef core::request_type request_type;
|
||||
typedef core::response_type response_type;
|
||||
|
||||
typedef core::message_type message_type;
|
||||
typedef core::con_msg_manager_type con_msg_manager_type;
|
||||
typedef core::endpoint_msg_manager_type endpoint_msg_manager_type;
|
||||
|
||||
typedef core::alog_type alog_type;
|
||||
typedef core::elog_type elog_type;
|
||||
|
||||
typedef core::rng_type rng_type;
|
||||
|
||||
typedef core::transport_type transport_type;
|
||||
|
||||
typedef core::endpoint_base endpoint_base;
|
||||
};*/
|
||||
|
||||
/* Run server and return output test rig */
|
||||
std::string run_server_test(server& s, std::string input) {
|
||||
server::connection_ptr con;
|
||||
std::stringstream output;
|
||||
|
||||
s.register_ostream(&output);
|
||||
s.clear_access_channels(websocketpp::log::alevel::all);
|
||||
s.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
con = s.get_connection();
|
||||
con->start();
|
||||
|
||||
std::stringstream channel;
|
||||
|
||||
channel << input;
|
||||
channel >> *con;
|
||||
|
||||
return output.str();
|
||||
}
|
||||
|
||||
/* handler library*/
|
||||
void echo_func(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
s->send(hdl, msg->get_payload(), msg->get_opcode());
|
||||
}
|
||||
|
||||
bool validate_func_subprotocol(server* s, std::string* out, std::string accept,
|
||||
websocketpp::connection_hdl hdl)
|
||||
{
|
||||
server::connection_ptr con = s->get_con_from_hdl(hdl);
|
||||
|
||||
std::stringstream o;
|
||||
|
||||
const std::vector<std::string> & protocols = con->get_requested_subprotocols();
|
||||
std::vector<std::string>::const_iterator it;
|
||||
|
||||
for (it = protocols.begin(); it != protocols.end(); ++it) {
|
||||
o << *it << ",";
|
||||
}
|
||||
|
||||
*out = o.str();
|
||||
|
||||
if (!accept.empty()) {
|
||||
con->select_subprotocol(accept);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void open_func_subprotocol(server* s, std::string* out, websocketpp::connection_hdl hdl) {
|
||||
server::connection_ptr con = s->get_con_from_hdl(hdl);
|
||||
|
||||
*out = con->get_subprotocol();
|
||||
}
|
||||
|
||||
/* Tests */
|
||||
BOOST_AUTO_TEST_CASE( basic_websocket_request ) {
|
||||
std::string input = "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\nOrigin: http://www.example.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( invalid_websocket_version ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: a\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 400 Bad Request\r\nServer: test\r\n\r\n";
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
//s.set_message_handler(bind(&echo_func,&s,::_1,::_2));
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( unimplemented_websocket_version ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 14\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 400 Bad Request\r\nSec-WebSocket-Version: 0,7,8,13\r\nServer: test\r\n\r\n";
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( list_subprotocol_empty ) {
|
||||
std::string input = "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\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
std::string subprotocol;
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&subprotocol,::_1));
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(subprotocol, "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( list_subprotocol_one ) {
|
||||
std::string input = "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\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(validate, "foo,");
|
||||
BOOST_CHECK_EQUAL(open, "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( accept_subprotocol_one ) {
|
||||
std::string input = "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\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: foo\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(validate, "foo,");
|
||||
BOOST_CHECK_EQUAL(open, "foo");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( accept_subprotocol_invalid ) {
|
||||
std::string input = "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\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: foo\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo2",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
std::string o;
|
||||
|
||||
BOOST_CHECK_THROW(o = run_server_test(s,input), websocketpp::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( accept_subprotocol_two ) {
|
||||
std::string input = "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\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo, bar\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: bar\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"bar",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(validate, "foo,bar,");
|
||||
BOOST_CHECK_EQUAL(open, "bar");
|
||||
}
|
||||
|
||||
/*BOOST_AUTO_TEST_CASE( user_reject_origin ) {
|
||||
std::string input = "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\nOrigin: http://www.example2.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 403 Forbidden\r\nServer: test\r\n\r\n";
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
|
||||
BOOST_CHECK(run_server_test(s,input) == output);
|
||||
}*/
|
||||
Reference in New Issue
Block a user