MCPcopy Create free account
hub / github.com/OISF/libhtp / TEST_F

Function TEST_F

test/test_hybrid.cpp:243–390  ·  view source on GitHub ↗

* Test hybrid mode with one complete GET transaction; request then response * with a body. Most features are tested, including query string parameters and callbacks. */

Source from the content-addressed store, hash-verified

241 * with a body. Most features are tested, including query string parameters and callbacks.
242 */
243TEST_F(HybridParsing, GetTest) {
244 // Create a new LibHTP transaction
245 htp_tx_t *tx = htp_connp_tx_create(connp);
246 ASSERT_TRUE(tx != NULL);
247
248 // Configure user data and callbacks
249 htp_tx_set_user_data(tx, &user_data);
250
251 // Register callbacks
252 RegisterUserCallbacks();
253
254 // Request begins
255 htp_tx_state_request_start(tx);
256 ASSERT_EQ(1, user_data.callback_REQUEST_START_invoked);
257
258 // Request line data
259 htp_tx_req_set_method(tx, "GET", 3, HTP_ALLOC_COPY);
260 htp_tx_req_set_method_number(tx, HTP_M_GET);
261 htp_tx_req_set_uri(tx, "/?p=1&q=2", 9, HTP_ALLOC_COPY);
262 htp_tx_req_set_protocol(tx, "HTTP/1.1", 8, HTP_ALLOC_COPY);
263 htp_tx_req_set_protocol_number(tx, HTP_PROTOCOL_1_1);
264 htp_tx_req_set_protocol_0_9(tx, 0);
265
266 // Request line complete
267 htp_tx_state_request_line(tx);
268 ASSERT_EQ(1, user_data.callback_REQUEST_LINE_invoked);
269
270 // Check request line data
271 ASSERT_TRUE(tx->request_method != NULL);
272 ASSERT_EQ(0, bstr_cmp_c(tx->request_method, "GET"));
273 ASSERT_TRUE(tx->request_uri != NULL);
274 ASSERT_EQ(0, bstr_cmp_c(tx->request_uri, "/?p=1&q=2"));
275 ASSERT_TRUE(tx->request_protocol != NULL);
276 ASSERT_EQ(0, bstr_cmp_c(tx->request_protocol, "HTTP/1.1"));
277
278 ASSERT_TRUE(tx->parsed_uri != NULL);
279
280 ASSERT_TRUE(tx->parsed_uri->path != NULL);
281 ASSERT_EQ(0, bstr_cmp_c(tx->parsed_uri->path, "/"));
282
283 ASSERT_TRUE(tx->parsed_uri->query != NULL);
284 ASSERT_EQ(0, bstr_cmp_c(tx->parsed_uri->query, "p=1&q=2"));
285
286 // Check parameters
287 htp_param_t *param_p = htp_tx_req_get_param(tx, "p", 1);
288 ASSERT_TRUE(param_p != NULL);
289 ASSERT_EQ(0, bstr_cmp_c(param_p->value, "1"));
290
291 htp_param_t *param_q = htp_tx_req_get_param(tx, "q", 1);
292 ASSERT_TRUE(param_q != NULL);
293 ASSERT_EQ(0, bstr_cmp_c(param_q->value, "2"));
294
295 // Request headers
296 htp_tx_req_set_header(tx, "Host", 4, "www.example.com", 15, HTP_ALLOC_COPY);
297 htp_tx_req_set_header(tx, "Connection", 10, "keep-alive", 10, HTP_ALLOC_COPY);
298 htp_tx_req_set_header(tx, "User-Agent", 10, "Mozilla/5.0", 11, HTP_ALLOC_COPY);
299
300 // Request headers complete

Callers

nothing calls this directly

Calls 15

htp_connp_tx_createFunction · 0.85
htp_tx_set_user_dataFunction · 0.85
htp_tx_req_set_methodFunction · 0.85
htp_tx_req_set_uriFunction · 0.85
htp_tx_req_set_protocolFunction · 0.85
bstr_cmp_cFunction · 0.85
htp_tx_req_get_paramFunction · 0.85

Tested by

no test coverage detected