forked from boostorg/beast
detect_ssl, async_detect_ssl are public interfaces
This commit is contained in:
@@ -44,6 +44,7 @@ add_executable (tests-beast-core
|
||||
buffers_range.cpp
|
||||
buffers_suffix.cpp
|
||||
buffers_to_string.cpp
|
||||
detect_ssl.cpp
|
||||
dynamic_buffer_ref.cpp
|
||||
error.cpp
|
||||
file.cpp
|
||||
|
||||
@@ -32,6 +32,7 @@ local SOURCES =
|
||||
buffers_range.cpp
|
||||
buffers_suffix.cpp
|
||||
buffers_to_string.cpp
|
||||
detect_ssl.cpp
|
||||
dynamic_buffer_ref.cpp
|
||||
error.cpp
|
||||
file.cpp
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
//
|
||||
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/core/detect_ssl.hpp>
|
||||
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/beast/_experimental/test/stream.hpp>
|
||||
#include <boost/beast/_experimental/test/handler.hpp>
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
#include <boost/core/exchange.hpp>
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
class detect_ssl_test : public unit_test::suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
testDetect()
|
||||
{
|
||||
auto const yes =
|
||||
[](int n, string_view s)
|
||||
{
|
||||
BEAST_EXPECT(detail::is_tls_client_hello(
|
||||
net::const_buffer(s.data(), n)));
|
||||
};
|
||||
|
||||
auto const no =
|
||||
[](int n, string_view s)
|
||||
{
|
||||
BEAST_EXPECT(! detail::is_tls_client_hello(
|
||||
net::const_buffer(s.data(), n)));
|
||||
};
|
||||
|
||||
auto const maybe =
|
||||
[](int n, string_view s)
|
||||
{
|
||||
BEAST_EXPECT(boost::indeterminate(
|
||||
detail::is_tls_client_hello(
|
||||
net::const_buffer(s.data(), n))));
|
||||
};
|
||||
|
||||
maybe( 0, "\x00\x00\x00\x00\x00\x00\x00\x00\x00");
|
||||
no ( 1, "\x01\x00\x00\x00\x00\x00\x00\x00\x00");
|
||||
maybe( 1, "\x16\x00\x00\x00\x00\x00\x00\x00\x00");
|
||||
maybe( 4, "\x16\x00\x00\x00\x00\x00\x00\x00\x00");
|
||||
no ( 5, "\x16\x00\x00\x00\x00\x00\x00\x00\x00");
|
||||
maybe( 5, "\x16\x00\x00\x01\x00\x00\x00\x00\x00");
|
||||
no ( 8, "\x16\x00\x00\x01\x00\x00\x00\x00\x00");
|
||||
maybe( 8, "\x16\x00\x00\x01\x00\x01\x00\x00\x00");
|
||||
no ( 9, "\x16\x00\x00\x01\x00\x01\x01\x00\x00");
|
||||
yes ( 9, "\x16\x00\x00\x01\x00\x01\x00\x00\x00");
|
||||
}
|
||||
|
||||
void
|
||||
testRead()
|
||||
{
|
||||
net::io_context ioc;
|
||||
|
||||
// true
|
||||
|
||||
{
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
s1.append({"\x16\x00\x00\x01\x00\x01\x00\x00\x00", 9});
|
||||
auto result = detect_ssl(s1, b, ec);
|
||||
BEAST_EXPECT(result == true);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
}
|
||||
|
||||
// true
|
||||
|
||||
{
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
auto s2 = test::connect(s1);
|
||||
s1.append({"\x16\x00\x00\x01\x00\x01\x00\x00\x00", 9});
|
||||
s2.close();
|
||||
auto result = detect_ssl(s1, b, ec);
|
||||
BEAST_EXPECT(result == true);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
}
|
||||
|
||||
// false
|
||||
|
||||
{
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
s1.append({"\x16\x00\x00\x01\x00\x01\x01\x00\x00", 9});
|
||||
auto result = detect_ssl(s1, b, ec);
|
||||
BEAST_EXPECT(result == false);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
}
|
||||
|
||||
// eof
|
||||
{
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
auto s2 = test::connect(s1);
|
||||
s1.append({"\x16\x00\x00\x01\x00", 5});
|
||||
s2.close();
|
||||
auto result = detect_ssl(s1, b, ec);
|
||||
BEAST_EXPECT(result == false);
|
||||
BEAST_EXPECT(ec);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testAsyncRead()
|
||||
{
|
||||
net::io_context ioc;
|
||||
|
||||
// true
|
||||
|
||||
{
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
s1.append({"\x16\x00\x00\x01\x00\x01\x00\x00\x00", 9});
|
||||
async_detect_ssl(s1, b, test::success_handler());
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
// true
|
||||
|
||||
{
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
auto s2 = test::connect(s1);
|
||||
s1.append({"\x16\x00\x00\x01\x00\x01\x00\x00\x00", 9});
|
||||
s2.close();
|
||||
async_detect_ssl(s1, b, test::success_handler());
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
// false
|
||||
|
||||
{
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
s1.append({"\x16\x00\x00\x01\x00\x01\x01\x00\x00", 9});
|
||||
async_detect_ssl(s1, b, test::success_handler());
|
||||
test::run(ioc);
|
||||
}
|
||||
|
||||
// eof
|
||||
{
|
||||
flat_buffer b;
|
||||
test::stream s1(ioc);
|
||||
auto s2 = test::connect(s1);
|
||||
s1.append({"\x16\x00\x00\x01\x00", 5});
|
||||
s2.close();
|
||||
async_detect_ssl(s1, b,
|
||||
test::fail_handler(net::error::eof));
|
||||
test::run(ioc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testDetect();
|
||||
testRead();
|
||||
testAsyncRead();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,core,detect_ssl);
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
@@ -19,7 +19,6 @@ add_executable (tests-doc
|
||||
Jamfile
|
||||
snippets.hpp
|
||||
snippets.ipp
|
||||
core_examples.cpp
|
||||
core_snippets.cpp
|
||||
core_1_refresher.cpp
|
||||
core_3_layers.cpp
|
||||
|
||||
@@ -19,7 +19,6 @@ alias run-tests :
|
||||
[ compile core_snippets.cpp ]
|
||||
[ compile http_snippets.cpp ]
|
||||
[ compile websocket_snippets.cpp ]
|
||||
[ run core_examples.cpp $(TEST_MAIN) ]
|
||||
[ run core_1_refresher.cpp $(TEST_MAIN) ]
|
||||
[ run core_3_layers.cpp $(TEST_MAIN) ]
|
||||
[ run http_examples.cpp $(TEST_MAIN) ]
|
||||
@@ -28,7 +27,6 @@ alias run-tests :
|
||||
|
||||
exe fat-tests :
|
||||
$(TEST_MAIN)
|
||||
core_examples.cpp
|
||||
core_1_refresher.cpp
|
||||
core_3_layers.cpp
|
||||
http_examples.cpp
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#include "example/common/detect_ssl.hpp"
|
||||
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/_experimental/test/stream.hpp>
|
||||
#include <boost/beast/test/yield_to.hpp>
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
class examples_test
|
||||
: public beast::unit_test::suite
|
||||
, public beast::test::enable_yield_to
|
||||
{
|
||||
public:
|
||||
void
|
||||
testDetect()
|
||||
{
|
||||
char buf[4];
|
||||
buf[0] = 0x16;
|
||||
buf[1] = 0;
|
||||
buf[2] = 0;
|
||||
buf[3] = 0;
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
net::buffer(buf, 0))));
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
net::buffer(buf, 1))));
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
net::buffer(buf, 2))));
|
||||
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
|
||||
net::buffer(buf, 3))));
|
||||
BEAST_EXPECT(is_ssl_handshake(
|
||||
net::buffer(buf, 4)));
|
||||
buf[0] = 0;
|
||||
BEAST_EXPECT(! is_ssl_handshake(
|
||||
net::buffer(buf, 1)));
|
||||
}
|
||||
|
||||
void
|
||||
testRead()
|
||||
{
|
||||
{
|
||||
test::stream ts{ioc_, "\x16***"};
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
auto const result = detect_ssl(ts, b, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(result);
|
||||
}
|
||||
yield_to(
|
||||
[&](yield_context yield)
|
||||
{
|
||||
test::stream ts{ioc_, "\x16***"};
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
auto const result =
|
||||
async_detect_ssl(ts, b, yield[ec]);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(result);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
run()
|
||||
{
|
||||
testDetect();
|
||||
testRead();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,core,examples);
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
@@ -18,7 +18,6 @@ add_executable (tests-example-common
|
||||
${EXTRAS_FILES}
|
||||
${TEST_MAIN}
|
||||
Jamfile
|
||||
detect_ssl.cpp
|
||||
root_certificates.cpp
|
||||
server_certificate.cpp
|
||||
session_alloc.cpp
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#
|
||||
|
||||
local SOURCES =
|
||||
detect_ssl.cpp
|
||||
root_certificates.cpp
|
||||
server_certificate.cpp
|
||||
session_alloc.cpp
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "example/common/detect_ssl.hpp"
|
||||
|
||||
Reference in New Issue
Block a user