| 35 | BOOST_FIXTURE_TEST_SUITE(httpserver_tests, SocketTestingSetup) |
| 36 | |
| 37 | BOOST_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 | |
| 83 | BOOST_AUTO_TEST_CASE(http_headers_tests) |
| 84 | { |
nothing calls this directly
no test coverage detected