WrongVersion - throwing if client and server protocol versions don't match
This commit is contained in:
Родитель
146bd8219c
Коммит
ff8922cd5d
|
@ -5,6 +5,7 @@
|
|||
#include <thread>
|
||||
#include <algorithm>
|
||||
#include "cpprest\asyncrt_utils.h"
|
||||
#include "constants.h"
|
||||
#include "connection_impl.h"
|
||||
#include "request_sender.h"
|
||||
#include "url_builder.h"
|
||||
|
@ -100,6 +101,15 @@ namespace signalr
|
|||
}, m_disconnect_cts.get_token())
|
||||
.then([connection](negotiation_response negotiation_response)
|
||||
{
|
||||
if (negotiation_response.protocol_version != PROTOCOL)
|
||||
{
|
||||
return pplx::task_from_exception<void>(
|
||||
std::runtime_error(std::string{ "incompatible protocol version. client protocol version: " }
|
||||
.append(utility::conversions::to_utf8string(PROTOCOL)
|
||||
.append(", server protocol version: ")
|
||||
.append(utility::conversions::to_utf8string(negotiation_response.protocol_version)))));
|
||||
}
|
||||
|
||||
return connection->start_transport(negotiation_response)
|
||||
.then([connection, negotiation_response](std::shared_ptr<transport> transport)
|
||||
{
|
||||
|
|
|
@ -302,7 +302,7 @@ TEST(connection_impl_start, start_fails_if_connect_request_times_out)
|
|||
auto websocket_client = std::make_shared<test_websocket_client>();
|
||||
websocket_client->set_receive_function([]()->pplx::task<std::string>
|
||||
{
|
||||
return pplx::task_from_result(std::string(""));
|
||||
return pplx::task_from_result(std::string("{}"));
|
||||
});
|
||||
|
||||
auto connection =
|
||||
|
@ -320,6 +320,36 @@ TEST(connection_impl_start, start_fails_if_connect_request_times_out)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(connection_impl_start, start_fails_if_protocol_versions_not_compatible)
|
||||
{
|
||||
auto web_request_factory = std::make_unique<test_web_request_factory>([](const web::uri& url)
|
||||
{
|
||||
auto response_body =
|
||||
url.path() == _XPLATSTR("/negotiate")
|
||||
? _XPLATSTR("{\"Url\":\"/signalr\", \"ConnectionToken\" : \"A==\", \"ConnectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ")
|
||||
_XPLATSTR("\"KeepAliveTimeout\" : 20.0, \"DisconnectTimeout\" : 30.0, \"ConnectionTimeout\" : 110.0, \"TryWebSockets\" : true, ")
|
||||
_XPLATSTR("\"ProtocolVersion\" : \"1.2\", \"TransportConnectTimeout\" : 0.1, \"LongPollDelay\" : 0.0}")
|
||||
: _XPLATSTR("{ }");
|
||||
|
||||
return std::unique_ptr<web_request>(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body));
|
||||
});
|
||||
|
||||
auto websocket_client = std::make_shared<test_websocket_client>();
|
||||
auto connection =
|
||||
connection_impl::create(create_uri(), _XPLATSTR(""), trace_level::all, std::make_shared<trace_log_writer>(),
|
||||
std::move(web_request_factory), std::make_unique<test_transport_factory>(websocket_client));
|
||||
|
||||
try
|
||||
{
|
||||
connection->start().get();
|
||||
ASSERT_TRUE(false); // exception not thrown
|
||||
}
|
||||
catch (const std::runtime_error &e)
|
||||
{
|
||||
ASSERT_STREQ("incompatible protocol version. client protocol version: 1.4, server protocol version: 1.2", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(connection_impl_process_response, process_response_logs_messages)
|
||||
{
|
||||
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
|
||||
|
|
Загрузка…
Ссылка в новой задаче