diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 08:52:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 08:52:01 +0000 |
commit | 42f47327da6a208ac3cd1f9bca07fc506ed51a63 (patch) | |
tree | e06c5e993e0d0b618f616280b372506b1f0f8419 /src/shrpx_config_test.cc | |
parent | Adding debian version 1.59.0-1. (diff) | |
download | nghttp2-42f47327da6a208ac3cd1f9bca07fc506ed51a63.tar.xz nghttp2-42f47327da6a208ac3cd1f9bca07fc506ed51a63.zip |
Merging upstream version 1.60.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/shrpx_config_test.cc')
-rw-r--r-- | src/shrpx_config_test.cc | 238 |
1 files changed, 129 insertions, 109 deletions
diff --git a/src/shrpx_config_test.cc b/src/shrpx_config_test.cc index a8f0962..068f185 100644 --- a/src/shrpx_config_test.cc +++ b/src/shrpx_config_test.cc @@ -30,43 +30,57 @@ #include <cstdlib> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "shrpx_config.h" #include "shrpx_log.h" namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_config_parse_header), + munit_void_test(test_shrpx_config_parse_log_format), + munit_void_test(test_shrpx_config_read_tls_ticket_key_file), + munit_void_test(test_shrpx_config_read_tls_ticket_key_file_aes_256), + munit_test_end(), +}; +} // namespace + +const MunitSuite config_suite{ + "/config_suite", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_config_parse_header(void) { BlockAllocator balloc(4096, 4096); auto p = parse_header(balloc, StringRef::from_lit("a: b")); - CU_ASSERT("a" == p.name); - CU_ASSERT("b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal("b", p.value.str()); p = parse_header(balloc, StringRef::from_lit("a: b")); - CU_ASSERT("a" == p.name); - CU_ASSERT("b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal("b", p.value.str()); p = parse_header(balloc, StringRef::from_lit(":a: b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("a: :b")); - CU_ASSERT("a" == p.name); - CU_ASSERT(":b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal(":b", p.value.str()); p = parse_header(balloc, StringRef::from_lit(": b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("alpha: bravo charlie")); - CU_ASSERT("alpha" == p.name); - CU_ASSERT("bravo charlie" == p.value); + assert_stdstring_equal("alpha", p.name.str()); + assert_stdstring_equal("bravo charlie", p.value.str()); p = parse_header(balloc, StringRef::from_lit("a,: b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("a: b\x0a")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); } void test_shrpx_config_parse_log_format(void) { @@ -77,100 +91,102 @@ void test_shrpx_config_parse_log_format(void) { R"($remote_addr - $remote_user [$time_local] )" R"("$request" $status $body_bytes_sent )" R"("${http_referer}" $http_host "$http_user_agent")")); - CU_ASSERT(16 == res.size()); + assert_size(16, ==, res.size()); - CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[0].type); + assert_enum_class(LogFragmentType::REMOTE_ADDR, ==, res[0].type); - CU_ASSERT(LogFragmentType::LITERAL == res[1].type); - CU_ASSERT(" - $remote_user [" == res[1].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[1].type); + assert_stdstring_equal(" - $remote_user [", res[1].value.str()); - CU_ASSERT(LogFragmentType::TIME_LOCAL == res[2].type); + assert_enum_class(LogFragmentType::TIME_LOCAL, ==, res[2].type); - CU_ASSERT(LogFragmentType::LITERAL == res[3].type); - CU_ASSERT("] \"" == res[3].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[3].type); + assert_stdstring_equal("] \"", res[3].value.str()); - CU_ASSERT(LogFragmentType::REQUEST == res[4].type); + assert_enum_class(LogFragmentType::REQUEST, ==, res[4].type); - CU_ASSERT(LogFragmentType::LITERAL == res[5].type); - CU_ASSERT("\" " == res[5].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[5].type); + assert_stdstring_equal("\" ", res[5].value.str()); - CU_ASSERT(LogFragmentType::STATUS == res[6].type); + assert_enum_class(LogFragmentType::STATUS, ==, res[6].type); - CU_ASSERT(LogFragmentType::LITERAL == res[7].type); - CU_ASSERT(" " == res[7].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[7].type); + assert_stdstring_equal(" ", res[7].value.str()); - CU_ASSERT(LogFragmentType::BODY_BYTES_SENT == res[8].type); + assert_enum_class(LogFragmentType::BODY_BYTES_SENT, ==, res[8].type); - CU_ASSERT(LogFragmentType::LITERAL == res[9].type); - CU_ASSERT(" \"" == res[9].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[9].type); + assert_stdstring_equal(" \"", res[9].value.str()); - CU_ASSERT(LogFragmentType::HTTP == res[10].type); - CU_ASSERT("referer" == res[10].value); + assert_enum_class(LogFragmentType::HTTP, ==, res[10].type); + assert_stdstring_equal("referer", res[10].value.str()); - CU_ASSERT(LogFragmentType::LITERAL == res[11].type); - CU_ASSERT("\" " == res[11].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[11].type); + assert_stdstring_equal("\" ", res[11].value.str()); - CU_ASSERT(LogFragmentType::AUTHORITY == res[12].type); + assert_enum_class(LogFragmentType::AUTHORITY, ==, res[12].type); - CU_ASSERT(LogFragmentType::LITERAL == res[13].type); - CU_ASSERT(" \"" == res[13].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[13].type); + assert_stdstring_equal(" \"", res[13].value.str()); - CU_ASSERT(LogFragmentType::HTTP == res[14].type); - CU_ASSERT("user-agent" == res[14].value); + assert_enum_class(LogFragmentType::HTTP, ==, res[14].type); + assert_stdstring_equal("user-agent", res[14].value.str()); - CU_ASSERT(LogFragmentType::LITERAL == res[15].type); - CU_ASSERT("\"" == res[15].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[15].type); + assert_stdstring_equal("\"", res[15].value.str()); res = parse_log_format(balloc, StringRef::from_lit("$")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("$" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("$", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${a")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${a" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${a", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${a ")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${a " == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${a ", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("$$remote_addr")); - CU_ASSERT(2 == res.size()); + assert_size(2, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("$" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("$", res[0].value.str()); - CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[1].type); - CU_ASSERT("" == res[1].value); + assert_enum_class(LogFragmentType::REMOTE_ADDR, ==, res[1].type); + assert_stdstring_equal("", res[1].value.str()); } void test_shrpx_config_read_tls_ticket_key_file(void) { char file1[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd1 = mkstemp(file1); - CU_ASSERT(fd1 != -1); - CU_ASSERT(48 == - write(fd1, "0..............12..............34..............5", 48)); + assert_int(-1, !=, fd1); + assert_ssize( + 48, ==, + write(fd1, "0..............12..............34..............5", 48)); char file2[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd2 = mkstemp(file2); - CU_ASSERT(fd2 != -1); - CU_ASSERT(48 == - write(fd2, "6..............78..............9a..............b", 48)); + assert_int(-1, !=, fd2); + assert_ssize( + 48, ==, + write(fd2, "6..............78..............9a..............b", 48)); close(fd1); close(fd2); @@ -178,44 +194,48 @@ void test_shrpx_config_read_tls_ticket_key_file(void) { {StringRef{file1}, StringRef{file2}}, EVP_aes_128_cbc(), EVP_sha256()); unlink(file1); unlink(file2); - CU_ASSERT(ticket_keys.get() != nullptr); - CU_ASSERT(2 == ticket_keys->keys.size()); + assert_not_null(ticket_keys.get()); + assert_size(2, ==, ticket_keys->keys.size()); auto key = &ticket_keys->keys[0]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "0..............1")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::begin(key->data.enc_key) + 16, "2..............3")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::begin(key->data.hmac_key) + 16, - "4..............5")); - CU_ASSERT(16 == key->hmac_keylen); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "0..............1")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::begin(key->data.enc_key) + 16, + "2..............3")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::begin(key->data.hmac_key) + 16, + "4..............5")); + assert_size(16, ==, key->hmac_keylen); key = &ticket_keys->keys[1]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "6..............7")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::begin(key->data.enc_key) + 16, "8..............9")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::begin(key->data.hmac_key) + 16, - "a..............b")); - CU_ASSERT(16 == key->hmac_keylen); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "6..............7")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::begin(key->data.enc_key) + 16, + "8..............9")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::begin(key->data.hmac_key) + 16, + "a..............b")); + assert_size(16, ==, key->hmac_keylen); } void test_shrpx_config_read_tls_ticket_key_file_aes_256(void) { char file1[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd1 = mkstemp(file1); - CU_ASSERT(fd1 != -1); - CU_ASSERT(80 == write(fd1, - "0..............12..............................34..." - "...........................5", - 80)); + assert_int(-1, !=, fd1); + assert_ssize(80, ==, + write(fd1, + "0..............12..............................34..." + "...........................5", + 80)); char file2[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd2 = mkstemp(file2); - CU_ASSERT(fd2 != -1); - CU_ASSERT(80 == write(fd2, - "6..............78..............................9a..." - "...........................b", - 80)); + assert_int(-1, !=, fd2); + assert_ssize(80, ==, + write(fd2, + "6..............78..............................9a..." + "...........................b", + 80)); close(fd1); close(fd2); @@ -223,27 +243,27 @@ void test_shrpx_config_read_tls_ticket_key_file_aes_256(void) { {StringRef{file1}, StringRef{file2}}, EVP_aes_256_cbc(), EVP_sha256()); unlink(file1); unlink(file2); - CU_ASSERT(ticket_keys.get() != nullptr); - CU_ASSERT(2 == ticket_keys->keys.size()); + assert_not_null(ticket_keys.get()); + assert_size(2, ==, ticket_keys->keys.size()); auto key = &ticket_keys->keys[0]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "0..............1")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::end(key->data.enc_key), - "2..............................3")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::end(key->data.hmac_key), - "4..............................5")); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "0..............1")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::end(key->data.enc_key), + "2..............................3")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::end(key->data.hmac_key), + "4..............................5")); key = &ticket_keys->keys[1]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "6..............7")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::end(key->data.enc_key), - "8..............................9")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::end(key->data.hmac_key), - "a..............................b")); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "6..............7")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::end(key->data.enc_key), + "8..............................9")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::end(key->data.hmac_key), + "a..............................b")); } } // namespace shrpx |