#include #include static const char * __identify_http_request = "POST /gen_204 HTTP/1.1\r\n" "Host: www.google.com\r\n" "Connection: close\r\n" "Content-Length: 0\r\n" "Origin: https://www.google.com\r\n" "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n" "Content-Type: text/plain;charset=UTF-8\r\n" "Accept: */*\r\n" "X-Client-Data: CJG2yQEIorbJAQjEtskBCKmdygEI2J3KAQjZncoBCKijygEY+aXKAQ==\r\n" "Referer: https://www.google.com/\r\n" "Accept-Encoding: gzip, deflate\r\n" "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\r\n"; static const char * __identify_not_http_request = "MZMZ"; TEST(HttpHalfConstruct, ProtoIdentifyIsHTTP) { auto * hf_request = hf_private_create(TFE_HTTP_REQUEST, 1, 1); ASSERT_TRUE(hf_request != NULL); int ret = hf_private_parse(hf_request, (const unsigned char *) __identify_http_request, strlen(__identify_http_request)); EXPECT_EQ(ret, 0); } TEST(HttpHalfConstruct, ProtoIdentifyNotHTTP) { auto * hf_request = hf_private_create(TFE_HTTP_REQUEST, 1, 1); ASSERT_TRUE(hf_request != NULL); int ret = hf_private_parse(hf_request, (const unsigned char *) __identify_not_http_request, strlen(__identify_not_http_request)); EXPECT_EQ(ret, -1); } static const char * __get_http_request_no_body = "GET /gfwlist/gfwlist/master/gfwlist.txt HTTP/1.1\r\n" "Host: raw.githubusercontent.com\r\n" "Connection: close\r\n" "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n" "Accept: */*\r\n" "Accept-Encoding: gzip, deflate\r\n" "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\r\n" "If-None-Match: \"023aeae5eafc12082067c36031888adb3bafa797\"\r\n" "\r\n"; void __get_http_request_header_verify_helper(struct http_half_private * hf_private) { auto * hf_public = &hf_private->hf_public; EXPECT_EQ(hf_public->major_version, 1); EXPECT_EQ(hf_public->minor_version, 1); auto * hf_public_request = &hf_public->req_spec; /* PUBLIC FIELD */ EXPECT_EQ(hf_public_request->method, TFE_HTTP_GET); EXPECT_STREQ(hf_public_request->uri, "/gfwlist/gfwlist/master/gfwlist.txt"); EXPECT_STREQ(hf_public_request->url, "raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"); EXPECT_STREQ(hf_public_request->host, "raw.githubusercontent.com"); /* Header Field */ struct http_field_name field_name; void * __iterator = NULL; const char * hdr_value = NULL; /* HOST */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_HOST); EXPECT_STREQ(hdr_value, "raw.githubusercontent.com"); /* Connection */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_CONNECTION); EXPECT_STREQ(hdr_value, "close"); /* User-Agent */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_USER_AGENT); EXPECT_STREQ(hdr_value, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"); /* Accept */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_UNKNOWN_FIELD); EXPECT_STREQ(field_name.field_name, "Accept"); EXPECT_STREQ(hdr_value, "*/*"); /* Accept-Encoding */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_ACCEPT_ENCODING); EXPECT_STREQ(hdr_value, "gzip, deflate"); /* Accept-Language */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_UNKNOWN_FIELD); EXPECT_STREQ(field_name.field_name, "Accept-Language"); EXPECT_STREQ(hdr_value, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"); /* If-None-Match */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_UNKNOWN_FIELD); EXPECT_STREQ(field_name.field_name, "If-None-Match"); EXPECT_STREQ(hdr_value, "\"023aeae5eafc12082067c36031888adb3bafa797\""); } int __get_http_request_01_callback(struct http_half_private * hf_private, tfe_http_event ev, const unsigned char * data, size_t len, void * user) { const static tfe_http_event event_call_order[] = { EV_HTTP_REQ_HDR, EV_HTTP_REQ_END, }; auto * calling_seq = (unsigned int *) user; EXPECT_LE(*calling_seq, TFE_DIM(event_call_order)); EXPECT_EQ(event_call_order[*calling_seq], ev); (*calling_seq)++; return 0; } TEST(HttpHalfConstruct, GetWithNoBody) { auto * hf_request = hf_private_create(TFE_HTTP_REQUEST, 0, 0); ASSERT_TRUE(hf_request != NULL); int ret = hf_private_parse(hf_request, (const unsigned char *) __get_http_request_no_body, strlen(__get_http_request_no_body)); ASSERT_EQ(ret, 0); __get_http_request_header_verify_helper(hf_request); } TEST(HttpHalfConstructCallback, GetWithNoBody) { auto * hf_request = hf_private_create(TFE_HTTP_REQUEST, 0, 0); ASSERT_TRUE(hf_request != NULL); auto * __data = (const unsigned char *) __get_http_request_no_body; size_t __datalen = strlen(__get_http_request_no_body); unsigned int __expect_id = 0; hf_private_set_callback(hf_request, __get_http_request_01_callback, &__expect_id, NULL); hf_private_parse(hf_request, __data, __datalen); __get_http_request_header_verify_helper(hf_request); } /* POST / HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) QQBrowser/6.0 Host: qbwup.imtt.qq.com Content-Length: 726 Cache-Control: no-cache ......,..... ......,..............h......V.c..O..-o.{..'._J"9Y...yM...XR....$......L..*r..3..Q..&.......B......' .....K.(.2..1...}..nep..lI..Ds.5d....E. .Y...9..zr.........H$.....n...GaX.....k.. .I8...4|..5~..j0u5..>.'...........F16M./...........W..... 7.]xu..2.J.|..A.p`@a.Nq....!v.$...Z.....W..,....<.&:...@..........Y.x.A .<..r.d8.(.te.....%....=.....xnx..0....*.../.. lJz.>9.....>>..,....9. ....$./......k........;T.6#{...t...............c....xv.M.mw.......w... rg..........-d.Z.../f..st....v...8}..p..a.5N...:.......s/U.......o.." .}U...S:~.......TC.....X...}2..+&>.+............T?>........T.. -..]r n.....]co..!.......}.0.'...lgR...L.`f .^..2;M.F]..........A.>...`sJ,.>J.....*/ static const unsigned char __post_http_request[] = { /* Packet 4060 */ 0x50, 0x4f, 0x53, 0x54, 0x20, 0x2f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0x2f, 0x34, 0x2e, 0x30, 0x20, 0x28, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x3b, 0x20, 0x4d, 0x53, 0x49, 0x45, 0x20, 0x37, 0x2e, 0x30, 0x3b, 0x20, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x20, 0x4e, 0x54, 0x20, 0x35, 0x2e, 0x31, 0x29, 0x20, 0x51, 0x51, 0x42, 0x72, 0x6f, 0x77, 0x73, 0x65, 0x72, 0x2f, 0x36, 0x2e, 0x30, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x71, 0x62, 0x77, 0x75, 0x70, 0x2e, 0x69, 0x6d, 0x74, 0x74, 0x2e, 0x71, 0x71, 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3a, 0x20, 0x37, 0x32, 0x36, 0x0d, 0x0a, 0x43, 0x61, 0x63, 0x68, 0x65, 0x2d, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3a, 0x20, 0x6e, 0x6f, 0x2d, 0x63, 0x61, 0x63, 0x68, 0x65, 0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x00, 0x02, 0xd6, 0x10, 0x02, 0x2c, 0x3c, 0x4c, 0x56, 0x08, 0x71, 0x62, 0x70, 0x63, 0x73, 0x74, 0x61, 0x74, 0x66, 0x04, 0x73, 0x74, 0x61, 0x74, 0x7d, 0x00, 0x01, 0x02, 0xb3, 0x08, 0x00, 0x01, 0x06, 0x05, 0x63, 0x72, 0x79, 0x70, 0x74, 0x18, 0x00, 0x01, 0x06, 0x0a, 0x6c, 0x69, 0x73, 0x74, 0x3c, 0x63, 0x68, 0x61, 0x72, 0x3e, 0x1d, 0x00, 0x01, 0x02, 0x95, 0x0d, 0x00, 0x01, 0x02, 0x90, 0xc9, 0xf0, 0x2c, 0x12, 0xa4, 0x8d, 0x1d, 0xdd, 0xa4, 0xb6, 0xd6, 0xde, 0xb0, 0x9b, 0xe8, 0xf6, 0x13, 0x68, 0x9e, 0x95, 0xf8, 0xf9, 0xcb, 0xe8, 0x56, 0xa3, 0x63, 0x0e, 0x8b, 0x4f, 0xb8, 0x1c, 0x2d, 0x6f, 0xb9, 0x7b, 0x0c, 0x13, 0x27, 0x82, 0x5f, 0x4a, 0x22, 0x39, 0x59, 0x12, 0xb8, 0xfa, 0x79, 0x4d, 0x80, 0x1b, 0xce, 0x58, 0x52, 0x81, 0xf6, 0xb4, 0x83, 0x24, 0x99, 0x18, 0x1a, 0x85, 0x01, 0x91, 0x4c, 0xa3, 0xa5, 0x2a, 0x72, 0xe1, 0xea, 0x33, 0xb9, 0xae, 0x51, 0xfa, 0xca, 0x26, 0x91, 0x1c, 0xed, 0xba, 0x9d, 0x14, 0xe1, 0x42, 0x9f, 0x15, 0xd3, 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, 0xf8, 0x41, 0xcf, 0x3e, 0x99, 0x9e, 0xbd, 0x60, 0x73, 0x4a, 0x2c, 0xab, 0x3e, 0x4a, 0x8c, 0x98, 0x0c, 0xa8, 0x0c}; /* POST / HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) QQBrowser/6.0 Host: qbwup.imtt.qq.com Content-Length: 726 Cache-Control: no-cache ......,..... ......,..............h......V.c..O..-o.{..'._J"9Y...yM...XR....$......L..*r..3..Q..&.......B......' .....K.(.2..1...}..nep..lI..Ds.5d....E. .Y...9..zr.........H$.....n...GaX.....k.. .I8...4|..5~..j0u5..>.'...........F16M./...........W..... 7.]xu..2.J.|..A.p`@a.Nq....!v.$...Z.....W..,....<.&:...@..........Y.x.A .<..r.d8.(.te.....%....=.....xnx..0....*.../.. lJz.>9.....>>..,....9. ....$./......k........;T.6#{...t...............c....xv.M.mw.......w... rg..........-d.Z.../f..st....v...8}..p..a.5N...:.......s/U.......o.." .}U...S:~.......TC.....X...}2..+&>.+............T?>........T.. -..]r n.....]co..!.......}.0.'...lgR...L.`f .^..2;M.F]..........A.>...`sJ,.>J.....*/ void __http_post_header_verify_helper(struct http_half_private * hf_private) { auto * hf_public = &hf_private->hf_public; EXPECT_EQ(hf_public->major_version, 1); EXPECT_EQ(hf_public->minor_version, 1); auto * hf_public_request = &hf_public->req_spec; /* PUBLIC FIELD */ EXPECT_EQ(hf_public_request->method, TFE_HTTP_POST); EXPECT_STREQ(hf_public_request->uri, "/"); EXPECT_STREQ(hf_public_request->url, "qbwup.imtt.qq.com/"); EXPECT_STREQ(hf_public_request->host, "qbwup.imtt.qq.com"); /* Header Field */ struct http_field_name field_name; void * __iterator = NULL; const char * hdr_value = NULL; /* User-Agent */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_USER_AGENT); EXPECT_STREQ(hdr_value, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) QQBrowser/6.0"); /* HOST */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_HOST); EXPECT_STREQ(hdr_value, "qbwup.imtt.qq.com"); /* Content-Length */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_CONT_LENGTH); EXPECT_STREQ(hdr_value, "726"); /* Accept */ hdr_value = tfe_http_field_iterate(hf_public, &__iterator, &field_name); EXPECT_EQ(field_name.field_id, TFE_HTTP_UNKNOWN_FIELD); EXPECT_STREQ(field_name.field_name, "Cache-Control"); EXPECT_STREQ(hdr_value, "no-cache"); } struct __post_http_req_ctx { unsigned int calling_seq{0}; size_t total_length{0}; bool req_hdr_called{false}; bool req_body_begin_called{false}; bool req_body_cont_called{false}; bool req_body_end_called{false}; bool req_end_called{false}; }; int __post_http_request_callback(struct http_half_private * hf_private, tfe_http_event ev, const unsigned char * data, size_t len, void * user) { const static tfe_http_event event_call_order[] = { EV_HTTP_REQ_HDR, EV_HTTP_REQ_BODY_BEGIN, EV_HTTP_REQ_BODY_CONT, EV_HTTP_REQ_BODY_END, EV_HTTP_REQ_END }; auto * ctx = (struct __post_http_req_ctx *) user; EXPECT_LE(ctx->calling_seq, TFE_DIM(event_call_order)); EXPECT_EQ(event_call_order[ctx->calling_seq], ev); ctx->calling_seq++; if (ev & EV_HTTP_REQ_HDR) { __http_post_header_verify_helper(hf_private); ctx->req_hdr_called = true; } if (ev & EV_HTTP_REQ_BODY_BEGIN) { ctx->req_body_begin_called = true; } if (ev & EV_HTTP_REQ_BODY_CONT) { ctx->total_length += len; ctx->req_body_cont_called = true; } if (ev & EV_HTTP_REQ_BODY_END) { EXPECT_EQ(ctx->total_length, 726); ctx->req_body_end_called = true; } if (ev & EV_HTTP_REQ_END) { ctx->req_end_called = true; } return 0; } TEST(HttpHalfConstruct, PostWithBody) { auto * hf_request = hf_private_create(TFE_HTTP_REQUEST, 0, 0); ASSERT_TRUE(hf_request != NULL); auto * __data = (const unsigned char *) __post_http_request; size_t __datalen = sizeof(__post_http_request); int ret = hf_private_parse(hf_request, __data, __datalen); ASSERT_EQ(ret, 0); __http_post_header_verify_helper(hf_request); } TEST(HttpHalfConstructCallback, PostWithBody) { auto * hf_request = hf_private_create(TFE_HTTP_REQUEST, 0, 0); ASSERT_TRUE(hf_request != NULL); auto * __data = (const unsigned char *) __post_http_request; size_t __datalen = sizeof(__post_http_request); auto * ctx = new struct __post_http_req_ctx; hf_private_set_callback(hf_request, __post_http_request_callback, ctx, NULL); hf_private_parse(hf_request, __data, __datalen); __http_post_header_verify_helper(hf_request); EXPECT_TRUE(ctx->req_hdr_called); EXPECT_TRUE(ctx->req_body_begin_called); EXPECT_TRUE(ctx->req_body_cont_called); EXPECT_TRUE(ctx->req_body_end_called); EXPECT_TRUE(ctx->req_end_called); } void tfe_stream_write_access_log(const struct tfe_stream * stream, int level, const char * fmt, ...) { return; } int main(int argc, char ** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }