xref: /third_party/nghttp2/src/shrpx-unittest.cc (revision 2c593315)
12c593315Sopenharmony_ci/*
22c593315Sopenharmony_ci * nghttp2 - HTTP/2 C Library
32c593315Sopenharmony_ci *
42c593315Sopenharmony_ci * Copyright (c) 2013 Tatsuhiro Tsujikawa
52c593315Sopenharmony_ci *
62c593315Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
72c593315Sopenharmony_ci * a copy of this software and associated documentation files (the
82c593315Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
92c593315Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
102c593315Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
112c593315Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
122c593315Sopenharmony_ci * the following conditions:
132c593315Sopenharmony_ci *
142c593315Sopenharmony_ci * The above copyright notice and this permission notice shall be
152c593315Sopenharmony_ci * included in all copies or substantial portions of the Software.
162c593315Sopenharmony_ci *
172c593315Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
182c593315Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
192c593315Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
202c593315Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
212c593315Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
222c593315Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
232c593315Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
242c593315Sopenharmony_ci */
252c593315Sopenharmony_ci#ifdef HAVE_CONFIG_H
262c593315Sopenharmony_ci#  include <config.h>
272c593315Sopenharmony_ci#endif // HAVE_CONFIG_H
282c593315Sopenharmony_ci
292c593315Sopenharmony_ci#include <stdio.h>
302c593315Sopenharmony_ci#include <string.h>
312c593315Sopenharmony_ci#include <CUnit/Basic.h>
322c593315Sopenharmony_ci// include test cases' include files here
332c593315Sopenharmony_ci#include "shrpx_tls_test.h"
342c593315Sopenharmony_ci#include "shrpx_downstream_test.h"
352c593315Sopenharmony_ci#include "shrpx_config_test.h"
362c593315Sopenharmony_ci#include "shrpx_worker_test.h"
372c593315Sopenharmony_ci#include "http2_test.h"
382c593315Sopenharmony_ci#include "util_test.h"
392c593315Sopenharmony_ci#include "nghttp2_gzip_test.h"
402c593315Sopenharmony_ci#include "buffer_test.h"
412c593315Sopenharmony_ci#include "memchunk_test.h"
422c593315Sopenharmony_ci#include "template_test.h"
432c593315Sopenharmony_ci#include "shrpx_http_test.h"
442c593315Sopenharmony_ci#include "base64_test.h"
452c593315Sopenharmony_ci#include "shrpx_config.h"
462c593315Sopenharmony_ci#include "tls.h"
472c593315Sopenharmony_ci#include "shrpx_router_test.h"
482c593315Sopenharmony_ci#include "shrpx_log.h"
492c593315Sopenharmony_ci
502c593315Sopenharmony_cistatic int init_suite1(void) { return 0; }
512c593315Sopenharmony_ci
522c593315Sopenharmony_cistatic int clean_suite1(void) { return 0; }
532c593315Sopenharmony_ci
542c593315Sopenharmony_ciint main(int argc, char *argv[]) {
552c593315Sopenharmony_ci  CU_pSuite pSuite = nullptr;
562c593315Sopenharmony_ci  unsigned int num_tests_failed;
572c593315Sopenharmony_ci
582c593315Sopenharmony_ci  nghttp2::tls::libssl_init();
592c593315Sopenharmony_ci
602c593315Sopenharmony_ci  shrpx::create_config();
612c593315Sopenharmony_ci
622c593315Sopenharmony_ci  // initialize the CUnit test registry
632c593315Sopenharmony_ci  if (CUE_SUCCESS != CU_initialize_registry())
642c593315Sopenharmony_ci    return CU_get_error();
652c593315Sopenharmony_ci
662c593315Sopenharmony_ci  // add a suite to the registry
672c593315Sopenharmony_ci  pSuite = CU_add_suite("shrpx_TestSuite", init_suite1, clean_suite1);
682c593315Sopenharmony_ci  if (nullptr == pSuite) {
692c593315Sopenharmony_ci    CU_cleanup_registry();
702c593315Sopenharmony_ci    return CU_get_error();
712c593315Sopenharmony_ci  }
722c593315Sopenharmony_ci
732c593315Sopenharmony_ci  // add the tests to the suite
742c593315Sopenharmony_ci  if (!CU_add_test(pSuite, "tls_create_lookup_tree",
752c593315Sopenharmony_ci                   shrpx::test_shrpx_tls_create_lookup_tree) ||
762c593315Sopenharmony_ci      !CU_add_test(pSuite, "tls_cert_lookup_tree_add_ssl_ctx",
772c593315Sopenharmony_ci                   shrpx::test_shrpx_tls_cert_lookup_tree_add_ssl_ctx) ||
782c593315Sopenharmony_ci      !CU_add_test(pSuite, "tls_tls_hostname_match",
792c593315Sopenharmony_ci                   shrpx::test_shrpx_tls_tls_hostname_match) ||
802c593315Sopenharmony_ci      !CU_add_test(pSuite, "tls_tls_verify_numeric_hostname",
812c593315Sopenharmony_ci                   shrpx::test_shrpx_tls_verify_numeric_hostname) ||
822c593315Sopenharmony_ci      !CU_add_test(pSuite, "tls_tls_verify_dns_hostname",
832c593315Sopenharmony_ci                   shrpx::test_shrpx_tls_verify_dns_hostname) ||
842c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_add_header", shrpx::test_http2_add_header) ||
852c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_get_header", shrpx::test_http2_get_header) ||
862c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_copy_headers_to_nva",
872c593315Sopenharmony_ci                   shrpx::test_http2_copy_headers_to_nva) ||
882c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_build_http1_headers_from_headers",
892c593315Sopenharmony_ci                   shrpx::test_http2_build_http1_headers_from_headers) ||
902c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_lws", shrpx::test_http2_lws) ||
912c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_rewrite_location_uri",
922c593315Sopenharmony_ci                   shrpx::test_http2_rewrite_location_uri) ||
932c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_parse_http_status_code",
942c593315Sopenharmony_ci                   shrpx::test_http2_parse_http_status_code) ||
952c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_index_header",
962c593315Sopenharmony_ci                   shrpx::test_http2_index_header) ||
972c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_lookup_token",
982c593315Sopenharmony_ci                   shrpx::test_http2_lookup_token) ||
992c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_parse_link_header",
1002c593315Sopenharmony_ci                   shrpx::test_http2_parse_link_header) ||
1012c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_path_join", shrpx::test_http2_path_join) ||
1022c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_normalize_path",
1032c593315Sopenharmony_ci                   shrpx::test_http2_normalize_path) ||
1042c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_rewrite_clean_path",
1052c593315Sopenharmony_ci                   shrpx::test_http2_rewrite_clean_path) ||
1062c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_get_pure_path_component",
1072c593315Sopenharmony_ci                   shrpx::test_http2_get_pure_path_component) ||
1082c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_construct_push_component",
1092c593315Sopenharmony_ci                   shrpx::test_http2_construct_push_component) ||
1102c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_contains_trailers",
1112c593315Sopenharmony_ci                   shrpx::test_http2_contains_trailers) ||
1122c593315Sopenharmony_ci      !CU_add_test(pSuite, "http2_check_transfer_encoding",
1132c593315Sopenharmony_ci                   shrpx::test_http2_check_transfer_encoding) ||
1142c593315Sopenharmony_ci      !CU_add_test(pSuite, "downstream_field_store_append_last_header",
1152c593315Sopenharmony_ci                   shrpx::test_downstream_field_store_append_last_header) ||
1162c593315Sopenharmony_ci      !CU_add_test(pSuite, "downstream_field_store_header",
1172c593315Sopenharmony_ci                   shrpx::test_downstream_field_store_header) ||
1182c593315Sopenharmony_ci      !CU_add_test(pSuite, "downstream_crumble_request_cookie",
1192c593315Sopenharmony_ci                   shrpx::test_downstream_crumble_request_cookie) ||
1202c593315Sopenharmony_ci      !CU_add_test(pSuite, "downstream_assemble_request_cookie",
1212c593315Sopenharmony_ci                   shrpx::test_downstream_assemble_request_cookie) ||
1222c593315Sopenharmony_ci      !CU_add_test(pSuite, "downstream_rewrite_location_response_header",
1232c593315Sopenharmony_ci                   shrpx::test_downstream_rewrite_location_response_header) ||
1242c593315Sopenharmony_ci      !CU_add_test(pSuite, "downstream_supports_non_final_response",
1252c593315Sopenharmony_ci                   shrpx::test_downstream_supports_non_final_response) ||
1262c593315Sopenharmony_ci      !CU_add_test(pSuite, "downstream_find_affinity_cookie",
1272c593315Sopenharmony_ci                   shrpx::test_downstream_find_affinity_cookie) ||
1282c593315Sopenharmony_ci      !CU_add_test(pSuite, "config_parse_header",
1292c593315Sopenharmony_ci                   shrpx::test_shrpx_config_parse_header) ||
1302c593315Sopenharmony_ci      !CU_add_test(pSuite, "config_parse_log_format",
1312c593315Sopenharmony_ci                   shrpx::test_shrpx_config_parse_log_format) ||
1322c593315Sopenharmony_ci      !CU_add_test(pSuite, "config_read_tls_ticket_key_file",
1332c593315Sopenharmony_ci                   shrpx::test_shrpx_config_read_tls_ticket_key_file) ||
1342c593315Sopenharmony_ci      !CU_add_test(pSuite, "config_read_tls_ticket_key_file_aes_256",
1352c593315Sopenharmony_ci                   shrpx::test_shrpx_config_read_tls_ticket_key_file_aes_256) ||
1362c593315Sopenharmony_ci      !CU_add_test(pSuite, "worker_match_downstream_addr_group",
1372c593315Sopenharmony_ci                   shrpx::test_shrpx_worker_match_downstream_addr_group) ||
1382c593315Sopenharmony_ci      !CU_add_test(pSuite, "http_create_forwarded",
1392c593315Sopenharmony_ci                   shrpx::test_shrpx_http_create_forwarded) ||
1402c593315Sopenharmony_ci      !CU_add_test(pSuite, "http_create_via_header_value",
1412c593315Sopenharmony_ci                   shrpx::test_shrpx_http_create_via_header_value) ||
1422c593315Sopenharmony_ci      !CU_add_test(pSuite, "http_create_affinity_cookie",
1432c593315Sopenharmony_ci                   shrpx::test_shrpx_http_create_affinity_cookie) ||
1442c593315Sopenharmony_ci      !CU_add_test(pSuite, "http_create_atlsvc_header_field_value",
1452c593315Sopenharmony_ci                   shrpx::test_shrpx_http_create_altsvc_header_value) ||
1462c593315Sopenharmony_ci      !CU_add_test(pSuite, "http_check_http_scheme",
1472c593315Sopenharmony_ci                   shrpx::test_shrpx_http_check_http_scheme) ||
1482c593315Sopenharmony_ci      !CU_add_test(pSuite, "router_match", shrpx::test_shrpx_router_match) ||
1492c593315Sopenharmony_ci      !CU_add_test(pSuite, "router_match_wildcard",
1502c593315Sopenharmony_ci                   shrpx::test_shrpx_router_match_wildcard) ||
1512c593315Sopenharmony_ci      !CU_add_test(pSuite, "router_match_prefix",
1522c593315Sopenharmony_ci                   shrpx::test_shrpx_router_match_prefix) ||
1532c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_streq", shrpx::test_util_streq) ||
1542c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_strieq", shrpx::test_util_strieq) ||
1552c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_inp_strlower",
1562c593315Sopenharmony_ci                   shrpx::test_util_inp_strlower) ||
1572c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_to_base64", shrpx::test_util_to_base64) ||
1582c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_to_token68", shrpx::test_util_to_token68) ||
1592c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_percent_encode_token",
1602c593315Sopenharmony_ci                   shrpx::test_util_percent_encode_token) ||
1612c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_percent_decode",
1622c593315Sopenharmony_ci                   shrpx::test_util_percent_decode) ||
1632c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_quote_string",
1642c593315Sopenharmony_ci                   shrpx::test_util_quote_string) ||
1652c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) ||
1662c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_http_date", shrpx::test_util_http_date) ||
1672c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_select_h2", shrpx::test_util_select_h2) ||
1682c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_ipv6_numeric_addr",
1692c593315Sopenharmony_ci                   shrpx::test_util_ipv6_numeric_addr) ||
1702c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_utos", shrpx::test_util_utos) ||
1712c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_make_string_ref_uint",
1722c593315Sopenharmony_ci                   shrpx::test_util_make_string_ref_uint) ||
1732c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_utos_unit", shrpx::test_util_utos_unit) ||
1742c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_utos_funit", shrpx::test_util_utos_funit) ||
1752c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_parse_uint_with_unit",
1762c593315Sopenharmony_ci                   shrpx::test_util_parse_uint_with_unit) ||
1772c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_parse_uint", shrpx::test_util_parse_uint) ||
1782c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_parse_duration_with_unit",
1792c593315Sopenharmony_ci                   shrpx::test_util_parse_duration_with_unit) ||
1802c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_duration_str",
1812c593315Sopenharmony_ci                   shrpx::test_util_duration_str) ||
1822c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_format_duration",
1832c593315Sopenharmony_ci                   shrpx::test_util_format_duration) ||
1842c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_starts_with", shrpx::test_util_starts_with) ||
1852c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_ends_with", shrpx::test_util_ends_with) ||
1862c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_parse_http_date",
1872c593315Sopenharmony_ci                   shrpx::test_util_parse_http_date) ||
1882c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_localtime_date",
1892c593315Sopenharmony_ci                   shrpx::test_util_localtime_date) ||
1902c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_get_uint64", shrpx::test_util_get_uint64) ||
1912c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_parse_config_str_list",
1922c593315Sopenharmony_ci                   shrpx::test_util_parse_config_str_list) ||
1932c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_make_http_hostport",
1942c593315Sopenharmony_ci                   shrpx::test_util_make_http_hostport) ||
1952c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_make_hostport",
1962c593315Sopenharmony_ci                   shrpx::test_util_make_hostport) ||
1972c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_strifind", shrpx::test_util_strifind) ||
1982c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_random_alpha_digit",
1992c593315Sopenharmony_ci                   shrpx::test_util_random_alpha_digit) ||
2002c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_format_hex", shrpx::test_util_format_hex) ||
2012c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_is_hex_string",
2022c593315Sopenharmony_ci                   shrpx::test_util_is_hex_string) ||
2032c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_decode_hex", shrpx::test_util_decode_hex) ||
2042c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_extract_host",
2052c593315Sopenharmony_ci                   shrpx::test_util_extract_host) ||
2062c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_split_hostport",
2072c593315Sopenharmony_ci                   shrpx::test_util_split_hostport) ||
2082c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_split_str", shrpx::test_util_split_str) ||
2092c593315Sopenharmony_ci      !CU_add_test(pSuite, "util_rstrip", shrpx::test_util_rstrip) ||
2102c593315Sopenharmony_ci      !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) ||
2112c593315Sopenharmony_ci      !CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) ||
2122c593315Sopenharmony_ci      !CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) ||
2132c593315Sopenharmony_ci      !CU_add_test(pSuite, "memchunk_append", nghttp2::test_memchunks_append) ||
2142c593315Sopenharmony_ci      !CU_add_test(pSuite, "memchunk_drain", nghttp2::test_memchunks_drain) ||
2152c593315Sopenharmony_ci      !CU_add_test(pSuite, "memchunk_riovec", nghttp2::test_memchunks_riovec) ||
2162c593315Sopenharmony_ci      !CU_add_test(pSuite, "memchunk_recycle",
2172c593315Sopenharmony_ci                   nghttp2::test_memchunks_recycle) ||
2182c593315Sopenharmony_ci      !CU_add_test(pSuite, "memchunk_reset", nghttp2::test_memchunks_reset) ||
2192c593315Sopenharmony_ci      !CU_add_test(pSuite, "peek_memchunk_append",
2202c593315Sopenharmony_ci                   nghttp2::test_peek_memchunks_append) ||
2212c593315Sopenharmony_ci      !CU_add_test(pSuite, "peek_memchunk_disable_peek_drain",
2222c593315Sopenharmony_ci                   nghttp2::test_peek_memchunks_disable_peek_drain) ||
2232c593315Sopenharmony_ci      !CU_add_test(pSuite, "peek_memchunk_disable_peek_no_drain",
2242c593315Sopenharmony_ci                   nghttp2::test_peek_memchunks_disable_peek_no_drain) ||
2252c593315Sopenharmony_ci      !CU_add_test(pSuite, "peek_memchunk_reset",
2262c593315Sopenharmony_ci                   nghttp2::test_peek_memchunks_reset) ||
2272c593315Sopenharmony_ci      !CU_add_test(pSuite, "template_immutable_string",
2282c593315Sopenharmony_ci                   nghttp2::test_template_immutable_string) ||
2292c593315Sopenharmony_ci      !CU_add_test(pSuite, "template_string_ref",
2302c593315Sopenharmony_ci                   nghttp2::test_template_string_ref) ||
2312c593315Sopenharmony_ci      !CU_add_test(pSuite, "base64_encode", nghttp2::test_base64_encode) ||
2322c593315Sopenharmony_ci      !CU_add_test(pSuite, "base64_decode", nghttp2::test_base64_decode)) {
2332c593315Sopenharmony_ci    CU_cleanup_registry();
2342c593315Sopenharmony_ci    return CU_get_error();
2352c593315Sopenharmony_ci  }
2362c593315Sopenharmony_ci
2372c593315Sopenharmony_ci  // Run all tests using the CUnit Basic interface
2382c593315Sopenharmony_ci  CU_basic_set_mode(CU_BRM_VERBOSE);
2392c593315Sopenharmony_ci  CU_basic_run_tests();
2402c593315Sopenharmony_ci  num_tests_failed = CU_get_number_of_tests_failed();
2412c593315Sopenharmony_ci  CU_cleanup_registry();
2422c593315Sopenharmony_ci  if (CU_get_error() == CUE_SUCCESS) {
2432c593315Sopenharmony_ci    return num_tests_failed;
2442c593315Sopenharmony_ci  } else {
2452c593315Sopenharmony_ci    printf("CUnit Error: %s\n", CU_get_error_msg());
2462c593315Sopenharmony_ci    return CU_get_error();
2472c593315Sopenharmony_ci  }
2482c593315Sopenharmony_ci}
249