Commit f3553a12 authored by old-bear's avatar old-bear

Fix UT of server which rely on the format of curl's output

parent bea6f4c1
...@@ -1277,11 +1277,10 @@ TEST_F(ServerTest, too_big_message) { ...@@ -1277,11 +1277,10 @@ TEST_F(ServerTest, too_big_message) {
server.Join(); server.Join();
} }
void CheckCert(const char* fname, const char* cert) { void CheckCert(const char* address, const char* cert) {
butil::ScopedFILE fp(fname, "r"); std::string cmd = butil::string_printf(
char buf[1024]; "/usr/bin/curl -Ikv https://%s 2>&1 | grep %s", address, cert);
fgets(buf, sizeof(buf), fp); ASSERT_EQ(0, system(cmd.c_str()));
ASSERT_EQ(0, strncmp(cert, buf + 1, strlen(cert))) << cert; // Skip the first blank
} }
std::string GetRawPemString(const char* fname) { std::string GetRawPemString(const char* fname) {
...@@ -1311,20 +1310,12 @@ TEST_F(ServerTest, ssl_sni) { ...@@ -1311,20 +1310,12 @@ TEST_F(ServerTest, ssl_sni) {
options.ssl_options.certs.push_back(cert); options.ssl_options.certs.push_back(cert);
} }
ASSERT_EQ(0, server.Start(8613, &options)); ASSERT_EQ(0, server.Start(8613, &options));
{ CheckCert("localhost:8613", "cert1");
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");
}
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{ CheckCert("localhost.localdomain:8613", "cert2");
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");
}
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME #endif // SSL_CTRL_SET_TLSEXT_HOSTNAME
server.Stop(0); server.Stop(0);
server.Join(); server.Join();
} }
...@@ -1340,12 +1331,8 @@ TEST_F(ServerTest, ssl_reload) { ...@@ -1340,12 +1331,8 @@ TEST_F(ServerTest, ssl_reload) {
options.ssl_options.default_cert = cert; options.ssl_options.default_cert = cert;
} }
ASSERT_EQ(0, server.Start(8613, &options)); ASSERT_EQ(0, server.Start(8613, &options));
{ CheckCert("localhost:8613", "cert1");
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");
}
{ {
brpc::CertInfo cert; brpc::CertInfo cert;
cert.certificate = GetRawPemString("cert2.crt"); cert.certificate = GetRawPemString("cert2.crt");
...@@ -1354,12 +1341,7 @@ TEST_F(ServerTest, ssl_reload) { ...@@ -1354,12 +1341,7 @@ TEST_F(ServerTest, ssl_reload) {
ASSERT_EQ(0, server.AddCertificate(cert)); ASSERT_EQ(0, server.AddCertificate(cert));
} }
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{ CheckCert("localhost.localdomain:8613", "cert2");
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");
}
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME #endif // SSL_CTRL_SET_TLSEXT_HOSTNAME
{ {
...@@ -1369,12 +1351,7 @@ TEST_F(ServerTest, ssl_reload) { ...@@ -1369,12 +1351,7 @@ TEST_F(ServerTest, ssl_reload) {
ASSERT_EQ(0, server.RemoveCertificate(cert)); ASSERT_EQ(0, server.RemoveCertificate(cert));
} }
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{ CheckCert("localhost.localdomain:8613", "cert1");
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");
}
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME #endif // SSL_CTRL_SET_TLSEXT_HOSTNAME
{ {
...@@ -1387,12 +1364,7 @@ TEST_F(ServerTest, ssl_reload) { ...@@ -1387,12 +1364,7 @@ TEST_F(ServerTest, ssl_reload) {
ASSERT_EQ(0, server.ResetCertificates(certs)); ASSERT_EQ(0, server.ResetCertificates(certs));
} }
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
{ CheckCert("localhost.localdomain:8613", "cert2");
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");
}
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME #endif // SSL_CTRL_SET_TLSEXT_HOSTNAME
server.Stop(0); server.Stop(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment