MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/httpserver_tests.cpp:37–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35BOOST_FIXTURE_TEST_SUITE(httpserver_tests, SocketTestingSetup)
36
37BOOST_AUTO_TEST_CASE(test_query_parameters)
38{
39 std::string uri {};
40
41 // Tolerate a URI with invalid characters (% not followed by hex digits)
42 uri = "/rest/endpoint/someresource.json?p1=v1&p2=v2%";
43 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p1"), "v1");
44 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p2"), "v2%");
45
46 // No parameters
47 uri = "localhost:8080/rest/headers/someresource.json";
48 BOOST_CHECK(!GetQueryParameterFromUri(uri, "p1"));
49
50 // Single parameter
51 uri = "localhost:8080/rest/endpoint/someresource.json?p1=v1";
52 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p1"), "v1");
53 BOOST_CHECK(!GetQueryParameterFromUri(uri, "p2"));
54
55 // Multiple parameters
56 uri = "/rest/endpoint/someresource.json?p1=v1&p2=v2";
57 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p1"), "v1");
58 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p2"), "v2");
59
60 // If the query string contains duplicate keys, the first value is returned
61 uri = "/rest/endpoint/someresource.json?p1=v1&p1=v2";
62 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p1"), "v1");
63
64 // Invalid query string syntax is the same as not having parameters
65 uri = "/rest/endpoint/someresource.json&p1=v1&p2=v2";
66 BOOST_CHECK(!GetQueryParameterFromUri(uri, "p1"));
67
68 // Multiple parameters, some characters encoded
69 uri = "/rest/endpoint/someresource.json?p1=v1%20&p2=100%25";
70 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p1"), "v1 ");
71 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p2"), "100%");
72
73 // Encoded query delimiters are part of the parameter value, not structure.
74 uri = "/rest/endpoint/someresource.json?p=a%26b%3Dc%23frag&other=x";
75 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "p"), "a&b=c#frag");
76 BOOST_CHECK_EQUAL(GetQueryParameterFromUri(uri, "other"), "x");
77
78 // An encoded question mark in the path does not introduce a query section.
79 uri = "/rest/endpoint/someresource.json%3Fp1%3Dv1%26p2%3D100%25";
80 BOOST_CHECK(!GetQueryParameterFromUri(uri, "p1"));
81}
82
83BOOST_AUTO_TEST_CASE(http_headers_tests)
84{

Callers

nothing calls this directly

Calls 15

GetQueryParameterFromUriFunction · 0.85
SetMockTimeFunction · 0.85
LookupFunction · 0.85
FindAllMethod · 0.80
RemoveAllMethod · 0.80
StringifyMethod · 0.80
StringifyHeadersMethod · 0.80
LoadControlDataMethod · 0.80
LoadHeadersMethod · 0.80
LoadBodyMethod · 0.80
GetRequestMethodMethod · 0.80
GetURIMethod · 0.80

Tested by

no test coverage detected