Commit 5711cfce authored by Ge Jun's avatar Ge Jun Committed by GitHub

Merge pull request #23 from brpc/jiangrujie-dev

Fix UT of server which rely on the format of curl's output
parents 8ae7b0c8 f3553a12
......@@ -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) {
......@@ -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();
}
......@@ -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");
......@@ -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
{
......@@ -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
{
......@@ -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);
......
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