diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-11 16:46:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-11 16:46:30 +0000 |
commit | 854010bc34484a22f5e97ed21ea76e76cde6a9ca (patch) | |
tree | e2fe43eaaa3546c62c0fce539d775f9928c805f4 /src/shrpx_tls_test.cc | |
parent | Adding debian version 1.61.0-1. (diff) | |
download | nghttp2-854010bc34484a22f5e97ed21ea76e76cde6a9ca.tar.xz nghttp2-854010bc34484a22f5e97ed21ea76e76cde6a9ca.zip |
Merging upstream version 1.62.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/shrpx_tls_test.cc')
-rw-r--r-- | src/shrpx_tls_test.cc | 96 |
1 files changed, 44 insertions, 52 deletions
diff --git a/src/shrpx_tls_test.cc b/src/shrpx_tls_test.cc index 04d16da..013c347 100644 --- a/src/shrpx_tls_test.cc +++ b/src/shrpx_tls_test.cc @@ -54,16 +54,16 @@ void test_shrpx_tls_create_lookup_tree(void) { auto tree = std::make_unique<tls::CertLookupTree>(); constexpr StringRef hostnames[] = { - StringRef::from_lit("example.com"), // 0 - StringRef::from_lit("www.example.org"), // 1 - StringRef::from_lit("*www.example.org"), // 2 - StringRef::from_lit("xy*.host.domain"), // 3 - StringRef::from_lit("*yy.host.domain"), // 4 - StringRef::from_lit("nghttp2.sourceforge.net"), // 5 - StringRef::from_lit("sourceforge.net"), // 6 - StringRef::from_lit("sourceforge.net"), // 7, duplicate - StringRef::from_lit("*.foo.bar"), // 8, oo.bar is suffix of *.foo.bar - StringRef::from_lit("oo.bar") // 9 + "example.com"_sr, // 0 + "www.example.org"_sr, // 1 + "*www.example.org"_sr, // 2 + "xy*.host.domain"_sr, // 3 + "*yy.host.domain"_sr, // 4 + "nghttp2.sourceforge.net"_sr, // 5 + "sourceforge.net"_sr, // 6 + "sourceforge.net"_sr, // 7, duplicate + "*.foo.bar"_sr, // 8, oo.bar is suffix of *.foo.bar + "oo.bar"_sr // 9 }; auto num = array_size(hostnames); @@ -75,13 +75,13 @@ void test_shrpx_tls_create_lookup_tree(void) { assert_ssize(0, ==, tree->lookup(hostnames[0])); assert_ssize(1, ==, tree->lookup(hostnames[1])); - assert_ssize(2, ==, tree->lookup(StringRef::from_lit("2www.example.org"))); - assert_ssize(-1, ==, tree->lookup(StringRef::from_lit("www2.example.org"))); - assert_ssize(3, ==, tree->lookup(StringRef::from_lit("xy1.host.domain"))); + assert_ssize(2, ==, tree->lookup("2www.example.org"_sr)); + assert_ssize(-1, ==, tree->lookup("www2.example.org"_sr)); + assert_ssize(3, ==, tree->lookup("xy1.host.domain"_sr)); // Does not match *yy.host.domain, because * must match at least 1 // character. - assert_ssize(-1, ==, tree->lookup(StringRef::from_lit("yy.host.domain"))); - assert_ssize(4, ==, tree->lookup(StringRef::from_lit("xyy.host.domain"))); + assert_ssize(-1, ==, tree->lookup("yy.host.domain"_sr)); + assert_ssize(4, ==, tree->lookup("xyy.host.domain"_sr)); assert_ssize(-1, ==, tree->lookup(StringRef{})); assert_ssize(5, ==, tree->lookup(hostnames[5])); assert_ssize(6, ==, tree->lookup(hostnames[6])); @@ -89,14 +89,14 @@ void test_shrpx_tls_create_lookup_tree(void) { for (int i = 0; i < 7; ++i) { assert_ssize(-1, ==, tree->lookup(StringRef{h6 + i, str_size(h6) - i})); } - assert_ssize(8, ==, tree->lookup(StringRef::from_lit("x.foo.bar"))); + assert_ssize(8, ==, tree->lookup("x.foo.bar"_sr)); assert_ssize(9, ==, tree->lookup(hostnames[9])); constexpr StringRef names[] = { - StringRef::from_lit("rab"), // 1 - StringRef::from_lit("zab"), // 2 - StringRef::from_lit("zzub"), // 3 - StringRef::from_lit("ab") // 4 + "rab"_sr, // 1 + "zab"_sr, // 2 + "zzub"_sr, // 3 + "ab"_sr // 4 }; num = array_size(names); @@ -169,12 +169,11 @@ void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void) { assert_int(0, ==, rv); - assert_ssize(-1, ==, - tree.lookup(StringRef::from_lit("not-used.nghttp2.org"))); - assert_ssize(0, ==, tree.lookup(StringRef::from_lit("test.nghttp2.org"))); - assert_ssize(1, ==, tree.lookup(StringRef::from_lit("w.test.nghttp2.org"))); - assert_ssize(2, ==, tree.lookup(StringRef::from_lit("www.test.nghttp2.org"))); - assert_ssize(3, ==, tree.lookup(StringRef::from_lit("test.example.com"))); + assert_ssize(-1, ==, tree.lookup("not-used.nghttp2.org"_sr)); + assert_ssize(0, ==, tree.lookup("test.nghttp2.org"_sr)); + assert_ssize(1, ==, tree.lookup("w.test.nghttp2.org"_sr)); + assert_ssize(2, ==, tree.lookup("www.test.nghttp2.org"_sr)); + assert_ssize(3, ==, tree.lookup("test.example.com"_sr)); } template <size_t N, size_t M> @@ -249,11 +248,10 @@ static Address parse_addr(const char *ipaddr) { void test_shrpx_tls_verify_numeric_hostname(void) { { // Successful IPv4 address match in SAN - static constexpr char ipaddr[] = "127.0.0.1"; + static constexpr auto ipaddr = "127.0.0.1"_sr; auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); - auto addr = parse_addr(ipaddr); - auto rv = - tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); + auto addr = parse_addr(ipaddr.data()); + auto rv = tls::verify_numeric_hostname(cert, ipaddr, &addr); assert_int(0, ==, rv); @@ -262,11 +260,10 @@ void test_shrpx_tls_verify_numeric_hostname(void) { { // Successful IPv6 address match in SAN - static constexpr char ipaddr[] = "::1"; + static constexpr auto ipaddr = "::1"_sr; auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); - auto addr = parse_addr(ipaddr); - auto rv = - tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); + auto addr = parse_addr(ipaddr.data()); + auto rv = tls::verify_numeric_hostname(cert, ipaddr, &addr); assert_int(0, ==, rv); @@ -275,11 +272,10 @@ void test_shrpx_tls_verify_numeric_hostname(void) { { // Unsuccessful IPv4 address match in SAN - static constexpr char ipaddr[] = "192.168.0.127"; + static constexpr auto ipaddr = "192.168.0.127"_sr; auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); - auto addr = parse_addr(ipaddr); - auto rv = - tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); + auto addr = parse_addr(ipaddr.data()); + auto rv = tls::verify_numeric_hostname(cert, ipaddr, &addr); assert_int(-1, ==, rv); @@ -288,11 +284,10 @@ void test_shrpx_tls_verify_numeric_hostname(void) { { // CommonName is not used if SAN is available - static constexpr char ipaddr[] = "192.168.0.1"; + static constexpr auto ipaddr = "192.168.0.1"_sr; auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/ipaddr.crt"); - auto addr = parse_addr(ipaddr); - auto rv = - tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); + auto addr = parse_addr(ipaddr.data()); + auto rv = tls::verify_numeric_hostname(cert, ipaddr, &addr); assert_int(-1, ==, rv); @@ -301,11 +296,10 @@ void test_shrpx_tls_verify_numeric_hostname(void) { { // Successful IPv4 address match in CommonName - static constexpr char ipaddr[] = "127.0.0.1"; + static constexpr auto ipaddr = "127.0.0.1"_sr; auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/nosan_ip.crt"); - auto addr = parse_addr(ipaddr); - auto rv = - tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); + auto addr = parse_addr(ipaddr.data()); + auto rv = tls::verify_numeric_hostname(cert, ipaddr, &addr); assert_int(0, ==, rv); @@ -317,8 +311,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { { // Successful exact DNS name match in SAN auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); - auto rv = tls::verify_dns_hostname( - cert, StringRef::from_lit("nghttp2.example.com")); + auto rv = tls::verify_dns_hostname(cert, "nghttp2.example.com"_sr); assert_int(0, ==, rv); @@ -328,8 +321,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { { // Successful wildcard DNS name match in SAN auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); - auto rv = tls::verify_dns_hostname( - cert, StringRef::from_lit("www.nghttp2.example.com")); + auto rv = tls::verify_dns_hostname(cert, "www.nghttp2.example.com"_sr); assert_int(0, ==, rv); @@ -339,7 +331,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { { // CommonName is not used if SAN is available. auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); - auto rv = tls::verify_dns_hostname(cert, StringRef::from_lit("localhost")); + auto rv = tls::verify_dns_hostname(cert, "localhost"_sr); assert_int(-1, ==, rv); @@ -349,7 +341,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { { // Successful DNS name match in CommonName auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/nosan.crt"); - auto rv = tls::verify_dns_hostname(cert, StringRef::from_lit("localhost")); + auto rv = tls::verify_dns_hostname(cert, "localhost"_sr); assert_int(0, ==, rv); |