Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 13 additions & 41 deletions test/brpc_server_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,11 +1277,10 @@ TEST_F(ServerTest, too_big_message) {
server.Join();
}

void CheckCert(const char* fname, const char* cert) {
butil::ScopedFILE fp(fname, "r");
char buf[1024];
fgets(buf, sizeof(buf), fp);
ASSERT_EQ(0, strncmp(cert, buf + 1, strlen(cert))) << cert; // Skip the first blank
void CheckCert(const char* address, const char* cert) {
std::string cmd = butil::string_printf(
"/usr/bin/curl -Ikv https://%s 2>&1 | grep %s", address, cert);
ASSERT_EQ(0, system(cmd.c_str()));
}

std::string GetRawPemString(const char* fname) {
Expand Down Expand Up @@ -1311,20 +1310,12 @@ TEST_F(ServerTest, ssl_sni) {
options.ssl_options.certs.push_back(cert);
}
ASSERT_EQ(0, server.Start(8613, &options));
{
std::string cmd = "/usr/bin/curl -Ikv https://localhost:8613 2>&1 "
"| grep common | cut -d':' -f2 > cname.out";
ASSERT_EQ(0, system(cmd.c_str()));
CheckCert("cname.out", "cert1");
}
CheckCert("localhost:8613", "cert1");

#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{
std::string cmd = "/usr/bin/curl -Ikv https://localhost.localdomain:8613 "
"2>&1 | grep common | cut -d':' -f2 > cname.out";
ASSERT_EQ(0, system(cmd.c_str()));
CheckCert("cname.out", "cert2");
}
CheckCert("localhost.localdomain:8613", "cert2");
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME

server.Stop(0);
server.Join();
}
Expand All @@ -1340,12 +1331,8 @@ TEST_F(ServerTest, ssl_reload) {
options.ssl_options.default_cert = cert;
}
ASSERT_EQ(0, server.Start(8613, &options));
{
std::string cmd = "/usr/bin/curl -Ikv https://localhost:8613 2>&1 "
"| grep common | cut -d':' -f2 > cname.out";
ASSERT_EQ(0, system(cmd.c_str()));
CheckCert("cname.out", "cert1");
}
CheckCert("localhost:8613", "cert1");

{
brpc::CertInfo cert;
cert.certificate = GetRawPemString("cert2.crt");
Expand All @@ -1354,12 +1341,7 @@ TEST_F(ServerTest, ssl_reload) {
ASSERT_EQ(0, server.AddCertificate(cert));
}
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{
std::string cmd = "/usr/bin/curl -Ikv https://localhost.localdomain:8613 "
"2>&1 | grep common | cut -d':' -f2 > cname.out";
ASSERT_EQ(0, system(cmd.c_str()));
CheckCert("cname.out", "cert2");
}
CheckCert("localhost.localdomain:8613", "cert2");
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME

{
Expand All @@ -1369,12 +1351,7 @@ TEST_F(ServerTest, ssl_reload) {
ASSERT_EQ(0, server.RemoveCertificate(cert));
}
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{
std::string cmd = "/usr/bin/curl -Ikv https://localhost.localdomain:8613 "
"2>&1 | grep common | cut -d':' -f2 > cname.out";
ASSERT_EQ(0, system(cmd.c_str()));
CheckCert("cname.out", "cert1");
}
CheckCert("localhost.localdomain:8613", "cert1");
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME

{
Expand All @@ -1387,12 +1364,7 @@ TEST_F(ServerTest, ssl_reload) {
ASSERT_EQ(0, server.ResetCertificates(certs));
}
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{
std::string cmd = "/usr/bin/curl -Ikv https://localhost.localdomain:8613 "
"2>&1 | grep common | cut -d':' -f2 > cname.out";
ASSERT_EQ(0, system(cmd.c_str()));
CheckCert("cname.out", "cert2");
}
CheckCert("localhost.localdomain:8613", "cert2");
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME

server.Stop(0);
Expand Down