Copilot commented on code in PR #3741:
URL: https://github.com/apache/brpc/pull/3741#discussion_r4680898338


##########
test/brpc_ssl_unittest.cpp:
##########
@@ -354,6 +359,100 @@ TEST_F(SSLTest, verify_peer_name) {
     ASSERT_EQ(0, server.Join());
 }
 
+#ifndef USE_MESALINK
+static void CreateIPv6Certificate(butil::TempFile* cert_file) {
+    std::unique_ptr<BIO, decltype(&BIO_free)> cert_bio(
+        BIO_new_file("cert1.crt", "r"), BIO_free);
+    std::unique_ptr<BIO, decltype(&BIO_free)> key_bio(
+        BIO_new_file("cert1.key", "r"), BIO_free);
+    ASSERT_TRUE(cert_bio);
+    ASSERT_TRUE(key_bio);
+    std::unique_ptr<X509, decltype(&X509_free)> cert(
+        PEM_read_bio_X509(cert_bio.get(), nullptr, nullptr, nullptr), 
X509_free);
+    std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)> key(
+        PEM_read_bio_PrivateKey(key_bio.get(), nullptr, nullptr, nullptr), 
EVP_PKEY_free);
+    ASSERT_TRUE(cert);
+    ASSERT_TRUE(key);
+    const int san_index = X509_get_ext_by_NID(cert.get(), 
NID_subject_alt_name, -1);
+    ASSERT_GE(san_index, 0);
+    X509_EXTENSION_free(X509_delete_ext(cert.get(), san_index));
+    char ip_san[] = "IP:::1";
+    std::unique_ptr<X509_EXTENSION, decltype(&X509_EXTENSION_free)> san(
+        X509V3_EXT_conf_nid(nullptr, nullptr, NID_subject_alt_name, ip_san),
+        X509_EXTENSION_free);
+    ASSERT_TRUE(san);
+    ASSERT_EQ(1, X509_add_ext(cert.get(), san.get(), -1));
+    ASSERT_GT(X509_sign(cert.get(), key.get(), EVP_sha256()), 0);
+
+    std::unique_ptr<BIO, decltype(&BIO_free)> pem(BIO_new(BIO_s_mem()), 
BIO_free);
+    ASSERT_TRUE(pem);
+    ASSERT_EQ(1, PEM_write_bio_X509(pem.get(), cert.get()));
+    char* data = nullptr;
+    const long size = BIO_get_mem_data(pem.get(), &data);
+    ASSERT_GT(size, 0);
+    ASSERT_EQ(0, cert_file->save_bin(data, static_cast<size_t>(size)));
+}
+
+TEST_F(SSLTest, verify_ipv6_peer_name_with_load_balancer) {
+    if (!brpc::SupportsPeerNameVerification()) {
+        return;
+    }
+    butil::TempFile cert_file;
+    ASSERT_NO_FATAL_FAILURE(CreateIPv6Certificate(&cert_file));
+
+    EchoServiceImpl echo_svc;
+    brpc::Server server;
+    brpc::ServerOptions server_options;
+    server_options.mutable_ssl_options()->default_cert.certificate = 
cert_file.fname();
+    server_options.mutable_ssl_options()->default_cert.private_key = 
"cert1.key";
+    ASSERT_EQ(0, server.AddService(&echo_svc, 
brpc::SERVER_DOESNT_OWN_SERVICE));
+    ASSERT_EQ(0, server.Start("[::1]:8613", &server_options));

Review Comment:
   This test unconditionally binds `[::1]`, but IPv6 loopback is not guaranteed 
in the test environment; the existing `EndPointTest.ipv6` explicitly avoids its 
live listen case for that reason (`test/endpoint_unittest.cpp:243-245`). On 
hosts or CI containers without IPv6, this assertion fails before exercising the 
naming-service behavior. Treat an IPv6 bind failure as a skipped test (or 
otherwise gate the test on IPv6 availability).



##########
test/brpc_ssl_unittest.cpp:
##########
@@ -354,6 +359,100 @@ TEST_F(SSLTest, verify_peer_name) {
     ASSERT_EQ(0, server.Join());
 }
 
+#ifndef USE_MESALINK
+static void CreateIPv6Certificate(butil::TempFile* cert_file) {
+    std::unique_ptr<BIO, decltype(&BIO_free)> cert_bio(
+        BIO_new_file("cert1.crt", "r"), BIO_free);
+    std::unique_ptr<BIO, decltype(&BIO_free)> key_bio(
+        BIO_new_file("cert1.key", "r"), BIO_free);
+    ASSERT_TRUE(cert_bio);
+    ASSERT_TRUE(key_bio);
+    std::unique_ptr<X509, decltype(&X509_free)> cert(
+        PEM_read_bio_X509(cert_bio.get(), nullptr, nullptr, nullptr), 
X509_free);
+    std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)> key(
+        PEM_read_bio_PrivateKey(key_bio.get(), nullptr, nullptr, nullptr), 
EVP_PKEY_free);
+    ASSERT_TRUE(cert);
+    ASSERT_TRUE(key);
+    const int san_index = X509_get_ext_by_NID(cert.get(), 
NID_subject_alt_name, -1);
+    ASSERT_GE(san_index, 0);
+    X509_EXTENSION_free(X509_delete_ext(cert.get(), san_index));
+    char ip_san[] = "IP:::1";
+    std::unique_ptr<X509_EXTENSION, decltype(&X509_EXTENSION_free)> san(
+        X509V3_EXT_conf_nid(nullptr, nullptr, NID_subject_alt_name, ip_san),
+        X509_EXTENSION_free);

Review Comment:
   This introduces a BoringSSL-only link failure: `X509V3_EXT_conf_nid` is 
implemented in BoringSSL's separate `decrepit` library, but this test target 
links the brpc test library with only BoringSSL `ssl` and `crypto` (see 
`src/butil/CMakeLists.txt:278-280` and `test/CMakeLists.txt:346-354`). The 
repository's BoringSSL CI configuration will therefore fail to link 
`brpc_ssl_unittest` unless the test avoids this legacy API or the build targets 
are updated to link `decrepit`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to