#include <boost/test/unit_test.hpp>
#include <iostream>
#include <websocketpp/config/core.hpp>
#include <websocketpp/server.hpp>
Go to the source code of this file.
◆ BOOST_TEST_MODULE
#define BOOST_TEST_MODULE server |
◆ server
◆ BOOST_AUTO_TEST_CASE() [1/8]
BOOST_AUTO_TEST_CASE |
( |
accept_subprotocol_invalid | | ) |
|
Definition at line 203 of file server.cpp.
203 {
204 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";
205
206 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";
207
210
215
216 std::string o;
217
219}
void set_user_agent(std::string const &ua)
Sets the user agent string that this endpoint will use.
bool validate(server *, websocketpp::connection_hdl)
bool validate_func_subprotocol(server *s, std::string *out, std::string accept, websocketpp::connection_hdl hdl)
std::string run_server_test(server &s, std::string input)
void open_func_subprotocol(server *s, std::string *out, websocketpp::connection_hdl hdl)
◆ BOOST_AUTO_TEST_CASE() [2/8]
BOOST_AUTO_TEST_CASE |
( |
accept_subprotocol_one | | ) |
|
Definition at line 185 of file server.cpp.
185 {
186 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";
187
188 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";
189
192
197
199 BOOST_CHECK_EQUAL(
validate,
"foo,");
200 BOOST_CHECK_EQUAL(open, "foo");
201}
◆ BOOST_AUTO_TEST_CASE() [3/8]
BOOST_AUTO_TEST_CASE |
( |
accept_subprotocol_two | | ) |
|
Definition at line 221 of file server.cpp.
221 {
222 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";
223
224 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";
225
228
233
235 BOOST_CHECK_EQUAL(
validate,
"foo,bar,");
236 BOOST_CHECK_EQUAL(open, "bar");
237}
◆ BOOST_AUTO_TEST_CASE() [4/8]
BOOST_AUTO_TEST_CASE |
( |
basic_websocket_request | | ) |
|
Definition at line 120 of file server.cpp.
120 {
121 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";
122 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";
123
126
128}
◆ BOOST_AUTO_TEST_CASE() [5/8]
BOOST_AUTO_TEST_CASE |
( |
invalid_websocket_version | | ) |
|
Definition at line 130 of file server.cpp.
130 {
131 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";
132 std::string output = "HTTP/1.1 400 Bad Request\r\nServer: test\r\n\r\n";
133
136
137
139}
◆ BOOST_AUTO_TEST_CASE() [6/8]
BOOST_AUTO_TEST_CASE |
( |
list_subprotocol_empty | | ) |
|
Definition at line 152 of file server.cpp.
152 {
153 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";
154
155 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";
156
157 std::string subprotocol;
158
162
164 BOOST_CHECK_EQUAL(subprotocol, "");
165}
◆ BOOST_AUTO_TEST_CASE() [7/8]
BOOST_AUTO_TEST_CASE |
( |
list_subprotocol_one | | ) |
|
Definition at line 167 of file server.cpp.
167 {
168 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";
169
170 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";
171
174
179
181 BOOST_CHECK_EQUAL(
validate,
"foo,");
182 BOOST_CHECK_EQUAL(open, "");
183}
◆ BOOST_AUTO_TEST_CASE() [8/8]
BOOST_AUTO_TEST_CASE |
( |
unimplemented_websocket_version | | ) |
|
Definition at line 141 of file server.cpp.
141 {
142 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";
143
144 std::string output = "HTTP/1.1 400 Bad Request\r\nSec-WebSocket-Version: 0,7,8,13\r\nServer: test\r\n\r\n";
145
148
150}
◆ echo_func()
Definition at line 86 of file server.cpp.
86 {
87 s->send(hdl, msg->get_payload(), msg->get_opcode());
88}
◆ open_func_subprotocol()
Definition at line 113 of file server.cpp.
113 {
115
116 *out = con->get_subprotocol();
117}
connection_type::ptr connection_ptr
◆ run_server_test()
std::string run_server_test |
( |
server & | s, |
|
|
std::string | input ) |
Definition at line 66 of file server.cpp.
66 {
68 std::stringstream output;
69
70 s.register_ostream(&output);
73
74 con =
s.get_connection();
75 con->start();
76
77 std::stringstream channel;
78
79 channel << input;
80 channel >> *con;
81
82 return output.str();
83}
static level const all
Special aggregate value representing "all levels".
static level const all
Special aggregate value representing "all levels".
◆ validate_func_subprotocol()
Definition at line 90 of file server.cpp.
92{
94
95 std::stringstream o;
96
97 const std::vector<std::string> & protocols = con->get_requested_subprotocols();
98 std::vector<std::string>::const_iterator it;
99
100 for (it = protocols.begin(); it != protocols.end(); ++it) {
101 o << *it << ",";
102 }
103
104 *out = o.str();
105
107 con->select_subprotocol(accept);
108 }
109
110 return true;
111}
@ accept
Accept any value the remote endpoint offers.