Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
httpserver_tests.cpp File Reference
#include <httpserver.h>
#include <rpc/protocol.h>
#include <test/util/common.h>
#include <test/util/logging.h>
#include <test/util/setup_common.h>
#include <util/string.h>
#include <util/threadpool.h>
#include <boost/test/unit_test.hpp>
Include dependency graph for httpserver_tests.cpp:

Go to the source code of this file.

Functions

 BOOST_FIXTURE_TEST_SUITE (httpserver_tests, SocketTestingSetup) BOOST_AUTO_TEST_CASE(test_query_parameters)
 BOOST_AUTO_TEST_CASE (http_headers_tests)
 BOOST_AUTO_TEST_CASE (http_response_tests)
 BOOST_AUTO_TEST_CASE (http_request_tests)
 BOOST_CHECK (req.LoadControlData(reader))
 BOOST_CHECK (!req.LoadHeaders(reader))
LineReader reader ("GET / HTTP/1.0\r\n\r\n" R"({"method":"getblockcount"})", MAX_HEADERS_SIZE)
 BOOST_CHECK_EQUAL (req.ReadBody(), "")
LineReader reader ("GET / HTTP/1.0\r\nContent-Length: eleven\r\n\r\n" R"({"method":"getblockcount"})", MAX_HEADERS_SIZE)
 BOOST_CHECK_EXCEPTION (req.LoadBody(reader), std::runtime_error, HasReason{"Cannot parse Content-Length value"})
LineReader reader ("GET / HTTP/1.0\r\nContent-Length: -8\r\n\r\n" R"({"method":"getblockcount"})", MAX_HEADERS_SIZE)
std::string huge_body (excessive_size, 'x')
LineReader reader (request, MAX_HEADERS_SIZE)
 BOOST_CHECK_EXCEPTION (req.LoadBody(reader), ContentTooLargeError, HasReason{"Max body size exceeded"})
LineReader reader ("GET / HTTP/1.0\r\nContent-Length: 1024\r\n\r\n" R"({"method":"getblockcount"})", MAX_HEADERS_SIZE)
LineReader reader (ok_chunked, MAX_HEADERS_SIZE)
 BOOST_CHECK_EQUAL (req.ReadBody(), R"({"method":"getblockcount"})")
LineReader reader (excessive_chunk_size, MAX_HEADERS_SIZE)
 BOOST_CHECK_EXCEPTION (req.LoadBody(reader), ContentTooLargeError, HasReason{"Chunk will exceed max body size"})
 BOOST_CHECK_EQUAL (reader.Remaining(), 0)
 BOOST_CHECK (!req.GetHeader("Expires"))
LineReader reader (invalid_chunked, MAX_HEADERS_SIZE)
 BOOST_CHECK_EXCEPTION (req.LoadBody(reader), std::runtime_error, HasReason{"Cannot parse chunk length value"})
 BOOST_CHECK_EXCEPTION (req.LoadBody(reader), std::runtime_error, HasReason{"Improperly terminated chunk"})
 BOOST_AUTO_TEST_CASE (http_request_state_tests)
 BOOST_AUTO_TEST_CASE (http_server_socket_tests)

Variables

constexpr std::string_view full_request
LineReader reader ("GET / HTTP/1.0\r\nHost: ", MAX_HEADERS_SIZE)
const std::string request {"GET / HTTP/1.0\r\nContent-Length: " + util::ToString(excessive_size) + "\r\n\r\n" + std::move(huge_body)}
HTTPRequest req
std::string_view ok_chunked
std::string_view excessive_chunk_size
std::string_view invalid_chunked

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( http_headers_tests )

Definition at line 76 of file httpserver_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( http_request_state_tests )

Definition at line 371 of file httpserver_tests.cpp.

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( http_request_tests )

Definition at line 194 of file httpserver_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( http_response_tests )

Definition at line 175 of file httpserver_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( http_server_socket_tests )

Definition at line 661 of file httpserver_tests.cpp.

Here is the call graph for this function:

◆ BOOST_CHECK() [1/3]

BOOST_CHECK ( !req. GetHeader"Expires")

◆ BOOST_CHECK() [2/3]

BOOST_CHECK ( !req. LoadHeadersreader)

◆ BOOST_CHECK() [3/3]

BOOST_CHECK ( req. LoadControlDatareader)

◆ BOOST_CHECK_EQUAL() [1/3]

BOOST_CHECK_EQUAL ( reader. Remaining(),
0  )

◆ BOOST_CHECK_EQUAL() [2/3]

BOOST_CHECK_EQUAL ( req. ReadBody(),
""  )

◆ BOOST_CHECK_EQUAL() [3/3]

BOOST_CHECK_EQUAL ( req. ReadBody(),
R"({"method":"getblockcount"})"  )

◆ BOOST_CHECK_EXCEPTION() [1/5]

BOOST_CHECK_EXCEPTION ( req. LoadBodyreader,
ContentTooLargeError ,
HasReason{"Chunk will exceed max body size"}  )

◆ BOOST_CHECK_EXCEPTION() [2/5]

BOOST_CHECK_EXCEPTION ( req. LoadBodyreader,
ContentTooLargeError ,
HasReason{"Max body size exceeded"}  )

◆ BOOST_CHECK_EXCEPTION() [3/5]

BOOST_CHECK_EXCEPTION ( req. LoadBodyreader,
std::runtime_error ,
HasReason{"Cannot parse chunk length value"}  )
Here is the call graph for this function:

◆ BOOST_CHECK_EXCEPTION() [4/5]

BOOST_CHECK_EXCEPTION ( req. LoadBodyreader,
std::runtime_error ,
HasReason{"Cannot parse Content-Length value"}  )
Here is the caller graph for this function:

◆ BOOST_CHECK_EXCEPTION() [5/5]

BOOST_CHECK_EXCEPTION ( req. LoadBodyreader,
std::runtime_error ,
HasReason{"Improperly terminated chunk"}  )
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_SUITE()

BOOST_FIXTURE_TEST_SUITE ( httpserver_tests ,
SocketTestingSetup  )

Definition at line 28 of file httpserver_tests.cpp.

◆ huge_body()

std::string huge_body ( excessive_size ,
'x'  )

◆ reader() [1/8]

LineReader reader ( "GET / HTTP/1.0\r\n\r\n" R"({"method":"getblockcount"})" ,
MAX_HEADERS_SIZE  )

◆ reader() [2/8]

LineReader reader ( "GET / HTTP/1.0\r\nContent-Length: -8\r\n\r\n" R"({"method":"getblockcount"})" ,
MAX_HEADERS_SIZE  )

◆ reader() [3/8]

LineReader reader ( "GET / HTTP/1.0\r\nContent-Length: 1024\r\n\r\n" R"({"method":"getblockcount"})" ,
MAX_HEADERS_SIZE  )

◆ reader() [4/8]

LineReader reader ( "GET / HTTP/1.0\r\nContent-Length: eleven\r\n\r\n" R"({"method":"getblockcount"})" ,
MAX_HEADERS_SIZE  )

◆ reader() [5/8]

◆ reader() [6/8]

◆ reader() [7/8]

◆ reader() [8/8]

Variable Documentation

◆ excessive_chunk_size

std::string_view excessive_chunk_size
Initial value:
= "GET / HTTP/1.0\n"
"Transfer-Encoding: chunked\n"
"\n"
"10\n"
R"({"method":"getbl)""\n"
"20000000\n"
R"(ockcount"})""\n"
"0\n"
"\n"

Definition at line 299 of file httpserver_tests.cpp.

◆ full_request

std::string_view full_request
constexpr
Initial value:
= "POST / HTTP/1.1\r\n"
"Host: 127.0.0.1\r\n"
"Connection: close\r\n"
"Content-Type: application/json\r\n"
"Authorization: Basic X19jb29raWVfXzo5OGQ5ODQ3MWNmNjg0NzAzYTkzN2EzNzk0ZDFlODQ1NjZmYTRkZjJiMzFkYjhhODI4ZGY4MjVjOTg5ZGI4OTVl\r\n"
"Content-Length: 46\r\n"
"\r\n"
R"({"method":"getblockcount","params":[],"id":1})""\n"

Definition at line 19 of file httpserver_tests.cpp.

◆ invalid_chunked

std::string_view invalid_chunked
Initial value:
= "GET / HTTP/1.0\n"
"Transfer-Encoding: chunked\n"
"\n"
"XVI\n"
R"({"method":"getbl)""\n"
"X\n"
R"(ockcount"})""\n"
"0\n"
"\n"

Definition at line 338 of file httpserver_tests.cpp.

◆ ok_chunked

std::string_view ok_chunked
Initial value:
= "GET / HTTP/1.0\n"
"Transfer-Encoding: chunked\n"
"\n"
"10\n"
R"({"method":"getbl)""\n"
" a \n"
R"(ockcount"})""\n"
"0\n"
"\n"

Definition at line 281 of file httpserver_tests.cpp.

◆ reader

LineReader reader ( "GET / HTTP/1.0\r\nHost: " ,
MAX_HEADERS_SIZE  )
Initial value:

◆ req

Definition at line 253 of file httpserver_tests.cpp.

◆ request

const std::string request {"GET / HTTP/1.0\r\nContent-Length: " + util::ToString(excessive_size) + "\r\n\r\n" + std::move(huge_body)}

Definition at line 252 of file httpserver_tests.cpp.